Browse Source

[ADD] grouped by partner and currencies on open invoices

(lp:c2c-addons/6.1  rev 50)
6.1
unknown 13 years ago
parent
commit
e0e0d3f031
  1. 31
      account_financial_report_webkit/report/open_invoices.py
  2. 192
      account_financial_report_webkit/report/templates/account_report_open_invoices.mako
  3. 7
      account_financial_report_webkit/wizard/open_invoices_wizard.py
  4. 1
      account_financial_report_webkit/wizard/open_invoices_wizard_view.xml

31
account_financial_report_webkit/report/open_invoices.py

@ -22,13 +22,25 @@ import pooler
from collections import defaultdict from collections import defaultdict
from report import report_sxw from report import report_sxw
from osv import osv
from tools.translate import _
from datetime import datetime from datetime import datetime
from itertools import groupby
from operator import itemgetter
from mako.template import Template
from tools.translate import _
from openerp.osv import osv
from common_partner_reports import CommonPartnersReportHeaderWebkit from common_partner_reports import CommonPartnersReportHeaderWebkit
from webkit_parser_header_fix import HeaderFooterTextWebKitParser from webkit_parser_header_fix import HeaderFooterTextWebKitParser
from openerp.addons.report_webkit import report_helper
import addons
def get_mako_template(obj, *args):
template_path = addons.get_module_resource(*args)
return Template(filename=template_path, input_encoding='utf-8')
report_helper.WebKitHelper.get_mako_template = get_mako_template
class PartnersOpenInvoicesWebkit(report_sxw.rml_parse, CommonPartnersReportHeaderWebkit): class PartnersOpenInvoicesWebkit(report_sxw.rml_parse, CommonPartnersReportHeaderWebkit):
@ -65,6 +77,18 @@ class PartnersOpenInvoicesWebkit(report_sxw.rml_parse, CommonPartnersReportHeade
], ],
}) })
def _group_lines_by_currency(self, account_br):
account_br.grouped_ledger_lines = {}
if not account_br.ledger_lines:
return
for part_id, plane_lines in account_br.ledger_lines.items():
account_br.grouped_ledger_lines[part_id] = []
plane_lines.sort(key=itemgetter('currency_code'))
for curr, lines in groupby(plane_lines, key=itemgetter('currency_code')):
tmp = [x for x in lines]
account_br.grouped_ledger_lines[part_id].append((curr, tmp)) #I want to reiter many times
def set_context(self, objects, data, ids, report_type=None): def set_context(self, objects, data, ids, report_type=None):
"""Populate a ledger_lines attribute on each browse record that will be used """Populate a ledger_lines attribute on each browse record that will be used
by mako template""" by mako template"""
@ -84,6 +108,7 @@ class PartnersOpenInvoicesWebkit(report_sxw.rml_parse, CommonPartnersReportHeade
result_selection = self._get_form_param('result_selection', data) result_selection = self._get_form_param('result_selection', data)
date_until = self._get_form_param('until_date', data) date_until = self._get_form_param('until_date', data)
chart_account = self._get_chart_account_id_br(data) chart_account = self._get_chart_account_id_br(data)
group_by_currency = self._get_form_param('group_by_currency', data)
if main_filter == 'filter_no' and fiscalyear: if main_filter == 'filter_no' and fiscalyear:
start_period = self.get_first_fiscalyear_period(fiscalyear) start_period = self.get_first_fiscalyear_period(fiscalyear)
@ -129,6 +154,8 @@ class PartnersOpenInvoicesWebkit(report_sxw.rml_parse, CommonPartnersReportHeade
account.partners_order = self._order_partners(ledg_lines_pids, init_bal_lines_pids) account.partners_order = self._order_partners(ledg_lines_pids, init_bal_lines_pids)
account.ledger_lines = ledger_lines_memoizer.get(account.id, {}) account.ledger_lines = ledger_lines_memoizer.get(account.id, {})
if group_by_currency:
self._group_lines_by_currency(account)
objects.append(account) objects.append(account)
self.localcontext.update({ self.localcontext.update({

192
account_financial_report_webkit/report/templates/account_report_open_invoices.mako

@ -1,4 +1,5 @@
<!DOCTYPE html SYSTEM "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<!DOCTYPE html SYSTEM
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"> <html xmlns="http://www.w3.org/1999/xhtml">
<head> <head>
<style type="text/css"> <style type="text/css">
@ -19,11 +20,12 @@
</style> </style>
</head> </head>
<body> <body>
<%!
def amount(text):
return text.replace('-', '&#8209;') # replace by a non-breaking hyphen (it will not word-wrap between hyphen and numbers)
%>
<% import addons %>
<% template1 = helper.get_mako_template('account_financial_report_webkit','report', 'templates', 'open_invoices_inclusion.mako.html') %>
<% context.lookup.put_template('open_invoices_inclusion.mako.html', template1) %>
<% template2 = helper.get_mako_template('account_financial_report_webkit','report', 'templates', 'grouped_by_curr_open_invoices_inclusion.mako.html') %>
<% context.lookup.put_template('grouped_by_curr_open_invoices_inclusion.mako.html', template2) %>
<%setLang(user.context_lang)%> <%setLang(user.context_lang)%>
<div class="act_as_table data_table"> <div class="act_as_table data_table">
@ -70,181 +72,13 @@
<div class="act_as_cell">${ display_target_move(data) }</div> <div class="act_as_cell">${ display_target_move(data) }</div>
</div> </div>
</div> </div>
%for account in objects:
%if account.ledger_lines:
<%
if not account.partners_order:
continue
account_total_debit = 0.0
account_total_credit = 0.0
account_balance_cumul = 0.0
account_balance_cumul_curr = 0.0
%>
<div class="account_title bg" style="width: 1080px; margin-top: 20px; font-size: 12px;">${account.code} - ${account.name}</div>
%for partner_name, p_id, p_ref, p_name in account.partners_order:
<%
total_debit = 0.0
total_credit = 0.0
cumul_balance = 0.0
cumul_balance_curr = 0.0
part_cumul_balance = 0.0
part_cumul_balance_curr = 0.0
%>
<div class="act_as_table list_table" style="margin-top: 5px;">
<div class="act_as_caption account_title">
${partner_name or _('No Partner')}
</div>
<div class="act_as_thead">
<div class="act_as_row labels">
## date
<div class="act_as_cell first_column" style="width: 60px;">${_('Date')}</div>
## period
<div class="act_as_cell" style="width: 70px;">${_('Period')}</div>
## move
<div class="act_as_cell" style="width: 70px;">${_('Entry')}</div>
## journal
<div class="act_as_cell" style="width: 70px;">${_('Journal')}</div>
## partner
<div class="act_as_cell" style="width: 60px;">${_('Partner')}</div>
## label
<div class="act_as_cell" style="width: 255px;">${_('Label')}</div>
## reconcile
<div class="act_as_cell" style="width: 80px;">${_('Rec.')}</div>
## maturity
<div class="act_as_cell" style="width: 60px;">${_('Due Date')}</div>
## debit
<div class="act_as_cell amount" style="width: 80px;">${_('Debit')}</div>
## credit
<div class="act_as_cell amount" style="width: 80px;">${_('Credit')}</div>
## balance cumulated
<div class="act_as_cell amount" style="width: 80px;">${_('Cumul. Bal.')}</div>
%if amount_currency(data):
## currency balance
<div class="act_as_cell amount sep_left" style="width: 80px;">${_('Curr. Balance')}</div>
## curency code
<div class="act_as_cell amount" style="width: 30px; text-align: right;">${_('Curr.')}</div>
%endif
</div>
</div>
<div class="act_as_tbody">
<%
total_debit = 0.0
total_credit = 0.0
%>
%for line in account.ledger_lines.get(p_id, []):
<%
total_debit += line.get('debit') or 0.0
total_credit += line.get('credit') or 0.0
label_elements = [line.get('lname') or '']
if line.get('invoice_number'):
label_elements.append("(%s)" % (line['invoice_number'],))
label = ' '.join(label_elements)
%>
<div class="act_as_row lines ${line.get('is_from_previous_periods') and 'open_invoice_previous_line' or ''} ${line.get('is_clearance_line') and 'clearance_line' or ''}">
## date
<div class="act_as_cell first_column">${formatLang(line.get('ldate') or '', date=True)}</div>
## period
<div class="act_as_cell">${line.get('period_code') or ''}</div>
## move
<div class="act_as_cell">${line.get('move_name') or ''}</div>
## journal
<div class="act_as_cell">${line.get('jcode') or ''}</div>
## partner
<div class="act_as_cell overflow_ellipsis">${line.get('partner_name') or ''}</div>
## label
<div class="act_as_cell">${label}</div>
## reconcile
<div class="act_as_cell">${line.get('rec_name') or ''}</div>
## maturity date
<div class="act_as_cell">${formatLang(line.get('date_maturity') or '', date=True)}</div>
## debit
<div class="act_as_cell amount">${formatLang(line.get('debit') or 0.0) | amount }</div>
## credit
<div class="act_as_cell amount">${formatLang(line.get('credit') or 0.0) | amount }</div>
## balance cumulated
<% cumul_balance += line.get('balance') or 0.0 %>
<div class="act_as_cell amount" style="padding-right: 1px;">${formatLang(cumul_balance) | amount }</div>
%if amount_currency(data):
## currency balance
<div class="act_as_cell sep_left amount">${formatLang(line.get('amount_currency') or 0.0) | amount }</div>
## curency code
<div class="act_as_cell" style="text-align: right; ">${line.get('currency_code') or ''}</div>
%endif
</div>
%endfor
<div class="act_as_row lines labels">
## date
<div class="act_as_cell first_column"></div>
## period
<div class="act_as_cell"></div>
## move
<div class="act_as_cell"></div>
## journal
<div class="act_as_cell"></div>
## partner
<div class="act_as_cell"></div>
## label
<div class="act_as_cell">${_('Cumulated Balance on Partner')}</div>
## reconcile
<div class="act_as_cell"></div>
## maturity date
<div class="act_as_cell"></div>
## debit
<div class="act_as_cell amount">${formatLang(total_debit) | amount }</div>
## credit
<div class="act_as_cell amount">${formatLang(total_credit) | amount }</div>
## balance cumulated
<div class="act_as_cell amount" style="padding-right: 1px;">${formatLang(cumul_balance) | amount }</div>
%if amount_currency(data):
%if account.currency_id:
## currency balance
<div class="act_as_cell sep_left amount" style="padding-right: 1px;">${formatLang(cumul_balance_curr) | amount }</div>
%for acc in objects:
%if hasattr(acc, 'grouped_ledger_lines'):
<% fl = formatLang %>
<%include file="grouped_by_curr_open_invoices_inclusion.mako.html" args="account=acc,formatLang=fl"/>
%else: %else:
<div class="act_as_cell sep_left amount" style="padding-right: 1px;">${ u'-' }</div>
%endif
## curency code
<div class="act_as_cell" style="text-align: right; ">${ account.currency_id.name if account.currency_id else u'' }</div>
%endif
</div>
</div>
</div>
<%
account_total_debit += total_debit
account_total_credit += total_credit
account_balance_cumul += cumul_balance
account_balance_cumul_curr += cumul_balance_curr
%>
%endfor
<div class="act_as_table list_table" style="margin-top:5px;">
<div class="act_as_row labels" style="font-weight: bold; font-size: 12px;">
<div class="act_as_cell first_column" style="width: 330px;">${account.code} - ${account.name}</div>
## label
<div class="act_as_cell" style="width: 395px;">${_("Cumulated Balance on Account")}</div>
## debit
<div class="act_as_cell amount" style="width: 80px;">${ formatLang(account_total_debit) | amount }</div>
## credit
<div class="act_as_cell amount" style="width: 80px;">${ formatLang(account_total_credit) | amount }</div>
## balance cumulated
<div class="act_as_cell amount" style="width: 80px; ">${ formatLang(account_balance_cumul) | amount }</div>
%if amount_currency(data):
## currency balance cumulated
%if account.currency_id:
<div class="act_as_cell amount sep_left" style="width: 80px;">${ formatLang(account_balance_cumul_curr) | amount }</div>
%else:
<div class="act_as_cell amount sep_left" style="width: 80px; padding-right: 1px;">${ u'-' }</div>
%endif
## curency code
<div class="act_as_cell amount" style="width: 30px; text-align: right;">${ account.currency_id.name if account.currency_id else u'' }</div>
%endif
</div>
</div>
</div>
<% fl = formatLang %>
<%include file="open_invoices_inclusion.mako.html" args="account=acc,formatLang=fl"/>
%endif %endif
%endfor %endfor
</body> </body>

7
account_financial_report_webkit/wizard/open_invoices_wizard.py

@ -29,6 +29,7 @@ class AccountReportOpenInvoicesWizard(osv.osv_memory):
_description = "Open Invoices Report" _description = "Open Invoices Report"
_columns = { _columns = {
'group_by_currency':fields.boolean('Group Partner by currency'),
'until_date': fields.date("Clearance date", 'until_date': fields.date("Clearance date",
required=True, required=True,
help="""The clearance date is essentially a tool used for debtors provisionning calculation. help="""The clearance date is essentially a tool used for debtors provisionning calculation.
@ -36,9 +37,7 @@ class AccountReportOpenInvoicesWizard(osv.osv_memory):
By default, this date is equal to the the end date (ie: 31/12/2011 if you select fy 2011). By default, this date is equal to the the end date (ie: 31/12/2011 if you select fy 2011).
By amending the clearance date, you will be, for instance, able to answer the question : 'based on my last year end debtors open invoices, which invoices are still unpaid today (today is my clearance date)?' By amending the clearance date, you will be, for instance, able to answer the question : 'based on my last year end debtors open invoices, which invoices are still unpaid today (today is my clearance date)?'
"""),
}
""")}
def _check_until_date(self, cr, uid, ids, context=None): def _check_until_date(self, cr, uid, ids, context=None):
def get_key_id(obj, field): def get_key_id(obj, field):
@ -111,7 +110,7 @@ By amending the clearance date, you will be, for instance, able to answer the qu
if context is None: if context is None:
context = {} context = {}
vals = self.read(cr, uid, ids, vals = self.read(cr, uid, ids,
['until_date',],
['until_date', 'group_by_currency'],
context=context)[0] context=context)[0]
data['form'].update(vals) data['form'].update(vals)
return data return data

1
account_financial_report_webkit/wizard/open_invoices_wizard_view.xml

@ -31,6 +31,7 @@
</page> </page>
<page string="Layout Options" name="layout_options"> <page string="Layout Options" name="layout_options">
<field name="amount_currency"/> <field name="amount_currency"/>
<field name="group_by_currency"/>
</page> </page>
</page> </page>
<page name="filters" position="attributes"> <page name="filters" position="attributes">

Loading…
Cancel
Save