diff --git a/account_financial_report_webkit/report/open_invoices.py b/account_financial_report_webkit/report/open_invoices.py index 90b9b676..118d321c 100644 --- a/account_financial_report_webkit/report/open_invoices.py +++ b/account_financial_report_webkit/report/open_invoices.py @@ -22,14 +22,26 @@ import pooler from collections import defaultdict from report import report_sxw -from osv import osv -from tools.translate import _ 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 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): def __init__(self, cursor, uid, name, context): @@ -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): """Populate a ledger_lines attribute on each browse record that will be used by mako template""" @@ -84,6 +108,7 @@ class PartnersOpenInvoicesWebkit(report_sxw.rml_parse, CommonPartnersReportHeade result_selection = self._get_form_param('result_selection', data) date_until = self._get_form_param('until_date', 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: 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.ledger_lines = ledger_lines_memoizer.get(account.id, {}) + if group_by_currency: + self._group_lines_by_currency(account) objects.append(account) self.localcontext.update({ diff --git a/account_financial_report_webkit/report/templates/account_report_open_invoices.mako b/account_financial_report_webkit/report/templates/account_report_open_invoices.mako index ebc4ecd4..ffe102dc 100644 --- a/account_financial_report_webkit/report/templates/account_report_open_invoices.mako +++ b/account_financial_report_webkit/report/templates/account_report_open_invoices.mako @@ -1,4 +1,5 @@ - + - <%! - def amount(text): - return text.replace('-', '‑') # 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)%>
@@ -70,181 +72,13 @@
${ display_target_move(data) }
- - %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 - %> - -
${account.code} - ${account.name}
- - %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 - %> -
-
- ${partner_name or _('No Partner')} -
-
-
- ## date -
${_('Date')}
- ## period -
${_('Period')}
- ## move -
${_('Entry')}
- ## journal -
${_('Journal')}
- ## partner -
${_('Partner')}
- ## label -
${_('Label')}
- ## reconcile -
${_('Rec.')}
- ## maturity -
${_('Due Date')}
- ## debit -
${_('Debit')}
- ## credit -
${_('Credit')}
- ## balance cumulated -
${_('Cumul. Bal.')}
- %if amount_currency(data): - ## currency balance -
${_('Curr. Balance')}
- ## curency code -
${_('Curr.')}
- %endif -
-
-
- <% - 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) - %> -
- ## date -
${formatLang(line.get('ldate') or '', date=True)}
- ## period -
${line.get('period_code') or ''}
- ## move -
${line.get('move_name') or ''}
- ## journal -
${line.get('jcode') or ''}
- ## partner -
${line.get('partner_name') or ''}
- ## label -
${label}
- ## reconcile -
${line.get('rec_name') or ''}
- ## maturity date -
${formatLang(line.get('date_maturity') or '', date=True)}
- ## debit -
${formatLang(line.get('debit') or 0.0) | amount }
- ## credit -
${formatLang(line.get('credit') or 0.0) | amount }
- ## balance cumulated - <% cumul_balance += line.get('balance') or 0.0 %> -
${formatLang(cumul_balance) | amount }
- %if amount_currency(data): - ## currency balance -
${formatLang(line.get('amount_currency') or 0.0) | amount }
- ## curency code -
${line.get('currency_code') or ''}
- %endif -
- %endfor -
- ## date -
- ## period -
- ## move -
- ## journal -
- ## partner -
- ## label -
${_('Cumulated Balance on Partner')}
- ## reconcile -
- ## maturity date -
- ## debit -
${formatLang(total_debit) | amount }
- ## credit -
${formatLang(total_credit) | amount }
- ## balance cumulated -
${formatLang(cumul_balance) | amount }
- %if amount_currency(data): - %if account.currency_id: - ## currency balance -
${formatLang(cumul_balance_curr) | amount }
- %else: -
${ u'-' }
- %endif - ## curency code -
${ account.currency_id.name if account.currency_id else u'' }
- %endif -
-
-
- <% - account_total_debit += total_debit - account_total_credit += total_credit - account_balance_cumul += cumul_balance - account_balance_cumul_curr += cumul_balance_curr - %> - %endfor -
-
-
${account.code} - ${account.name}
- ## label -
${_("Cumulated Balance on Account")}
- ## debit -
${ formatLang(account_total_debit) | amount }
- ## credit -
${ formatLang(account_total_credit) | amount }
- ## balance cumulated -
${ formatLang(account_balance_cumul) | amount }
- %if amount_currency(data): - ## currency balance cumulated - %if account.currency_id: -
${ formatLang(account_balance_cumul_curr) | amount }
- %else: -
${ u'-' }
- %endif - ## curency code -
${ account.currency_id.name if account.currency_id else u'' }
- %endif -
-
- + %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: + <% fl = formatLang %> + <%include file="open_invoices_inclusion.mako.html" args="account=acc,formatLang=fl"/> %endif %endfor diff --git a/account_financial_report_webkit/wizard/open_invoices_wizard.py b/account_financial_report_webkit/wizard/open_invoices_wizard.py index 115541bb..30284a19 100644 --- a/account_financial_report_webkit/wizard/open_invoices_wizard.py +++ b/account_financial_report_webkit/wizard/open_invoices_wizard.py @@ -29,6 +29,7 @@ class AccountReportOpenInvoicesWizard(osv.osv_memory): _description = "Open Invoices Report" _columns = { + 'group_by_currency':fields.boolean('Group Partner by currency'), 'until_date': fields.date("Clearance date", required=True, 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 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 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: context = {} vals = self.read(cr, uid, ids, - ['until_date',], + ['until_date', 'group_by_currency'], context=context)[0] data['form'].update(vals) return data diff --git a/account_financial_report_webkit/wizard/open_invoices_wizard_view.xml b/account_financial_report_webkit/wizard/open_invoices_wizard_view.xml index 1b1c1fa2..aa1dfad2 100644 --- a/account_financial_report_webkit/wizard/open_invoices_wizard_view.xml +++ b/account_financial_report_webkit/wizard/open_invoices_wizard_view.xml @@ -31,6 +31,7 @@ +