From ebcf344c2ff93092e77820d49bb09d241744426b Mon Sep 17 00:00:00 2001 From: dufresnedavid Date: Thu, 22 Jan 2015 12:48:14 -0500 Subject: [PATCH] Fix supplier and partner reports so that supplier report has only payable amounts and partner has only receivable amounts. Both reports have now all amounts in the correct column with the correct sign --- .../i18n/fr.po | 2 +- .../report/partner_aged_statement.mako | 32 +++++------ .../report/partner_aged_statement_report.py | 53 +++++++++++++++++-- .../report/supplier_aged_statement_report.py | 11 ++++ 4 files changed, 78 insertions(+), 20 deletions(-) diff --git a/account_partner_aged_statement_webkit/i18n/fr.po b/account_partner_aged_statement_webkit/i18n/fr.po index 09c67bc8..03074f3b 100644 --- a/account_partner_aged_statement_webkit/i18n/fr.po +++ b/account_partner_aged_statement_webkit/i18n/fr.po @@ -229,4 +229,4 @@ msgstr "Courriel:" #. module: account_partner_aged_statement_webkit #: model:ir.actions.report.xml,name:account_partner_aged_statement_webkit.supplier_aged_statement_report msgid "Supplier Aged Statement" -msgstr "Relevé de balance âgée" +msgstr "Relevé de balance âgée FRS" diff --git a/account_partner_aged_statement_webkit/report/partner_aged_statement.mako b/account_partner_aged_statement_webkit/report/partner_aged_statement.mako index c0b486dd..321d4812 100644 --- a/account_partner_aged_statement_webkit/report/partner_aged_statement.mako +++ b/account_partner_aged_statement_webkit/report/partner_aged_statement.mako @@ -68,13 +68,13 @@ ${_('Total')} - ${ formatLang(l['direction'], currency_obj=company.currency_id) } - ${ formatLang(l['4'], currency_obj=company.currency_id) } - ${ formatLang(l['3'], currency_obj=company.currency_id) } - ${ formatLang(l['2'], currency_obj=company.currency_id) } - ${ formatLang(l['1'], currency_obj=company.currency_id) } - ${ formatLang(l['0'], currency_obj=company.currency_id) } - ${ formatLang(l['total'], currency_obj=company.currency_id) } + ${ formatLang(balance_amount(l['direction']), currency_obj=company.currency_id) } + ${ formatLang(balance_amount(l['4']), currency_obj=company.currency_id) } + ${ formatLang(balance_amount(l['3']), currency_obj=company.currency_id) } + ${ formatLang(balance_amount(l['2']), currency_obj=company.currency_id) } + ${ formatLang(balance_amount(l['1']), currency_obj=company.currency_id) } + ${ formatLang(balance_amount(l['0']), currency_obj=company.currency_id) } + ${ formatLang(balance_amount(l['total']), currency_obj=company.currency_id) } %endif ## if l @@ -102,9 +102,9 @@ ${ line.move_id.name } ${ line.ref } ${ line.date_maturity and formatLang(line.date_maturity,date=True) or '' } - ${ formatLang(line.debit) or 0.0 } - ${ formatLang(line.credit) or 0.0 } - ${ formatLang(line.debit - line.credit, currency_obj = company.currency_id) } + ${ formatLang(line_amount(line))} + ${ formatLang(line_paid(line))} + ${ formatLang(line_amount(line) - line_paid(line), currency_obj = company.currency_id) } ${ line.amount_currency and formatLang(line.amount_currency, currency_obj = line.currency_id) or '' } %endfor ## for line in getLines30(partner) @@ -130,9 +130,9 @@ ${ line.move_id.name } ${ line.ref } ${ line.date_maturity and formatLang(line.date_maturity,date=True) or '' } - ${ formatLang(line.debit) or 0 } - ${ formatLang(line.credit) or 0 } - ${ formatLang(line.debit - line.credit, currency_obj = company.currency_id) } + ${ formatLang(line_amount(line))} + ${ formatLang(line_paid(line))} + ${ formatLang(line_amount(line) - line_paid(line), currency_obj = company.currency_id) } ${ line.amount_currency and formatLang(line.amount_currency, currency_obj = line.currency_id) or '' } %endfor ## for line in getLines3060(partner) @@ -158,9 +158,9 @@ ${ line.move_id.name } ${ line.ref } ${ line.date_maturity and formatLang(line.date_maturity,date=True) or '' } - ${ formatLang(line.debit) or 0 } - ${ formatLang(line.credit) or 0 } - ${ formatLang(line.debit - line.credit, currency_obj = company.currency_id) } + ${ formatLang(line_amount(line))} + ${ formatLang(line_paid(line))} + ${ formatLang(line_amount(line) - line_paid(line), currency_obj = company.currency_id) } ${ line.amount_currency and formatLang(line.amount_currency, currency_obj = line.currency_id) or '' } %endfor ## for line in getLines60(partner) diff --git a/account_partner_aged_statement_webkit/report/partner_aged_statement_report.py b/account_partner_aged_statement_webkit/report/partner_aged_statement_report.py index 1605a429..7be1c721 100644 --- a/account_partner_aged_statement_webkit/report/partner_aged_statement_report.py +++ b/account_partner_aged_statement_webkit/report/partner_aged_statement_report.py @@ -48,6 +48,9 @@ class PartnerAgedTrialReport(aged_trial_report): 'getLines3060': self._lines_get_30_60, 'getLines60': self._lines_get60, 'show_message': True, + 'line_amount': self._line_amount, + 'line_paid': self._line_paid, + 'balance_amount': lambda amount: amount, }) def _lines_get30(self, obj): @@ -58,7 +61,7 @@ class PartnerAgedTrialReport(aged_trial_report): movelines = moveline_obj.search( self.cr, self.uid, [('partner_id', '=', obj.id), - ('account_id.type', 'in', ['receivable', 'payable']), + ('account_id.type', 'in', ['receivable']), ('state', '<>', 'draft'), ('reconcile_id', '=', False), '|', '&', ('date_maturity', '<=', today), ('date_maturity', '>', stop), @@ -76,7 +79,7 @@ class PartnerAgedTrialReport(aged_trial_report): movelines = moveline_obj.search( self.cr, self.uid, [('partner_id', '=', obj.id), - ('account_id.type', 'in', ['receivable', 'payable']), + ('account_id.type', 'in', ['receivable']), ('state', '<>', 'draft'), ('reconcile_id', '=', False), '|', '&', ('date_maturity', '<=', start), ('date_maturity', '>', stop), @@ -93,7 +96,7 @@ class PartnerAgedTrialReport(aged_trial_report): movelines = moveline_obj.search( self.cr, self.uid, [('partner_id', '=', obj.id), - ('account_id.type', 'in', ['receivable', 'payable']), + ('account_id.type', 'in', ['receivable']), ('state', '<>', 'draft'), ('reconcile_id', '=', False), '|', ('date_maturity', '<=', start), ('date_maturity', '=', False), ('date', '<=', start)], @@ -185,6 +188,7 @@ class PartnerAgedTrialReport(aged_trial_report): ", ".join(str(int(i)) for i in self._partners), ) + self.ACCOUNT_TYPE = ['receivable'] return res def _get_lines(self, form, partner): @@ -196,6 +200,49 @@ class PartnerAgedTrialReport(aged_trial_report): self.query = self.orig_query return res + def _line_amount(self, line): + invoice = line.invoice + invoice_type = invoice and invoice.type or False + print invoice_type, line.debit, line.account_id.type + + if invoice_type == 'in_invoice': + return line.credit or 0.0 + + if invoice_type == 'in_refund': + return -line.debit or 0.0 + + if invoice_type == 'out_invoice': + return line.debit or 0.0 + + if invoice_type == 'out_refund': + return -line.credit or 0.0 + + if line.account_id.type == 'payable': + return line.credit or 0.0 + + return line.debit or 0.0 + + def _line_paid(self, line): + invoice = line.invoice + invoice_type = invoice and invoice.type or False + + if invoice_type == 'in_invoice': + return line.debit or 0.0 + + if invoice_type == 'in_refund': + return -line.credit or 0.0 + + if invoice_type == 'out_invoice': + return line.credit or 0.0 + + if invoice_type == 'out_refund': + return -line.debit or 0.0 + + if line.account_id.type == 'payable': + return line.debit or 0.0 + + return line.credit or 0.0 + report_sxw.report_sxw( 'report.webkit.partner_aged_statement_report', diff --git a/account_partner_aged_statement_webkit/report/supplier_aged_statement_report.py b/account_partner_aged_statement_webkit/report/supplier_aged_statement_report.py index 0f36e281..b9e89db1 100644 --- a/account_partner_aged_statement_webkit/report/supplier_aged_statement_report.py +++ b/account_partner_aged_statement_webkit/report/supplier_aged_statement_report.py @@ -39,8 +39,18 @@ class SupplierAgedTrialReport(PartnerAgedTrialReport): 'getLines3060': self._lines_get_30_60, 'getLines60': self._lines_get60, 'show_message': False, + 'get_lines': self._get_lines, + 'balance_amount': lambda amount: -amount, }) + def set_context(self, objects, data, ids, report_type=None): + res = super(SupplierAgedTrialReport, self).set_context( + objects, data, ids, report_type=report_type) + + self.ACCOUNT_TYPE = ['payable'] + + return res + def _lines_get30(self, obj): today = datetime.now() stop = today - relativedelta(days=30) @@ -92,6 +102,7 @@ class SupplierAgedTrialReport(PartnerAgedTrialReport): movelines = moveline_obj.browse(self.cr, self.uid, movelines) return movelines + report_sxw.report_sxw( 'report.webkit.supplier_aged_statement_report', 'res.partner',