From c1f9c351e275f7cddf1237fa1dd4081a95d63b56 Mon Sep 17 00:00:00 2001 From: dufresnedavid Date: Thu, 2 Jul 2015 10:18:52 -0400 Subject: [PATCH] Add invoice refunds --- .../account_partner_aged_statement_webkit.pot | 20 +++++++ .../i18n/fr.po | 20 +++++++ .../report/partner_aged_statement.mako | 38 ++++++++++++ .../report/partner_aged_statement_report.py | 58 +++++++++++++++---- .../report/supplier_aged_statement_report.py | 3 +- .../tests/test_aged_statement.py | 37 ++++++++++-- 6 files changed, 158 insertions(+), 18 deletions(-) diff --git a/account_partner_aged_statement_webkit/i18n/account_partner_aged_statement_webkit.pot b/account_partner_aged_statement_webkit/i18n/account_partner_aged_statement_webkit.pot index 1f6dfd0e..32d6541b 100644 --- a/account_partner_aged_statement_webkit/i18n/account_partner_aged_statement_webkit.pot +++ b/account_partner_aged_statement_webkit/i18n/account_partner_aged_statement_webkit.pot @@ -245,3 +245,23 @@ msgstr "" #: report:addons/account_partner_aged_statement_webkit/report/partner_aged_statement.mako:0 msgid "List of overdue invoices" msgstr "" + +#. module: account_partner_aged_statement_webkit +#: report:addons/account_partner_aged_statement_webkit/report/partner_aged_statement.mako:0 +msgid "Sum of Customer Refunds" +msgstr "" + +#. module: account_partner_aged_statement_webkit +#: report:addons/account_partner_aged_statement_webkit/report/partner_aged_statement.mako:0 +msgid "List of Customer Refunds" +msgstr "" + +#. module: account_partner_aged_statement_webkit +#: report:addons/account_partner_aged_statement_webkit/report/partner_aged_statement.mako:0 +msgid "Sum of Supplier Refunds" +msgstr "" + +#. module: account_partner_aged_statement_webkit +#: report:addons/account_partner_aged_statement_webkit/report/partner_aged_statement.mako:0 +msgid "List of Supplier Refunds" +msgstr "" diff --git a/account_partner_aged_statement_webkit/i18n/fr.po b/account_partner_aged_statement_webkit/i18n/fr.po index 540ccb0a..6e404b35 100644 --- a/account_partner_aged_statement_webkit/i18n/fr.po +++ b/account_partner_aged_statement_webkit/i18n/fr.po @@ -297,3 +297,23 @@ msgstr "Courriel:" #: 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 FRS" + +#. module: account_partner_aged_statement_webkit +#: report:addons/account_partner_aged_statement_webkit/report/partner_aged_statement.mako:0 +msgid "Sum of Customer Refunds" +msgstr "Somme des notes de crédit" + +#. module: account_partner_aged_statement_webkit +#: report:addons/account_partner_aged_statement_webkit/report/partner_aged_statement.mako:0 +msgid "List of Customer Refunds" +msgstr "Liste des notes de crédit" + +#. module: account_partner_aged_statement_webkit +#: report:addons/account_partner_aged_statement_webkit/report/partner_aged_statement.mako:0 +msgid "Sum of Supplier Refunds" +msgstr "Somme des notes de crédit" + +#. module: account_partner_aged_statement_webkit +#: report:addons/account_partner_aged_statement_webkit/report/partner_aged_statement.mako:0 +msgid "List of Supplier Refunds" +msgstr "Liste des notes de crédit" 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 f50e5bed..34fea72e 100644 --- a/account_partner_aged_statement_webkit/report/partner_aged_statement.mako +++ b/account_partner_aged_statement_webkit/report/partner_aged_statement.mako @@ -82,6 +82,12 @@

+ %if get_refunds_total(partner, company): +
${_('Sum of Customer Refunds') if ttype == 'receipt' else _('Sum of Supplier Refunds')} : ${ get_refunds_total(partner, company) }
+
+
+ %endif + %if getLinesCurrent(partner, company):
${_('List of current invoices')}

@@ -170,6 +176,38 @@ %endfor ## for line in getLines60(partner, company) %endif ## if getLines60(partner) + + %if getLinesRefunds(partner, company): +
+
+
${_('List of Customer Refunds') if ttype == 'receipt' else _('List of Supplier Refunds')}
+
+ + + + + + + + + + + + %for line in getLinesRefunds(partner, company): + + + + + + + + + + + %endfor ## for line in getLinesCurrent(partner, company) +
${_('Date')}${_('Description')}${_('Reference')}${_('Due date')}${_('Amount')}${_('Paid')}${_('Total')}${_('Currency')}
${ formatLang(line['date_original'], date=True) }${ line['name'] }${ line['ref'] }${ line['date_due'] and formatLang(line['date_due'], date=True) or '' }${ formatLang(line['amount_original']) }${ formatLang(line['amount_original'] - line['amount_unreconciled']) }${ formatLang(line['amount_unreconciled']) }${ line['currency_name'] }
+ %endif ## if getLinesRefunds(partner, company) + %endif ## if (partner.credit + partner.debit == 0 %endfor ## for partner in objects 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 2f34eed7..ef272bc5 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 @@ -44,18 +44,21 @@ class PartnerAgedTrialReport(aged_trial_report): current_user = self.localcontext["user"] self._company = current_user.company_id if self.localcontext.get("active_model", "") == "res.partner": - self._partners = self.localcontext["active_ids"] + self._partner = self.localcontext["active_id"] + self.ttype = 'receipt' self.localcontext.update({ 'message': self._message, 'getLinesCurrent': self._lines_get_current, 'getLines3060': self._lines_get_30_60, 'getLines60': self._lines_get_60, + 'getLinesRefunds': self._lines_get_refunds, 'show_message': True, 'get_current_invoice_lines': self._get_current_invoice_lines, 'get_balance': self._get_balance, + 'get_refunds_total': self._refunds_total, + 'ttype': self.ttype, }) self.partner_invoices_dict = {} - self.ttype = 'receipt' tz = self.localcontext.get('tz', False) tz = tz and pytz.timezone(tz) or pytz.utc self.today = datetime.now(tz) @@ -76,7 +79,11 @@ class PartnerAgedTrialReport(aged_trial_report): date_90 = date_90.strftime(DEFAULT_SERVER_DATE_FORMAT) date_120 = date_120.strftime(DEFAULT_SERVER_DATE_FORMAT) - movelines = self._get_current_invoice_lines(partner, company, today) + movelines = [ + line for line in + self._get_current_invoice_lines(partner, company, today) + if line['type'] in ['in_invoice', 'out_invoice'] + ] movelines = sorted(movelines, key=lambda x: x['currency_name']) grouped_movelines = [ @@ -147,12 +154,15 @@ class PartnerAgedTrialReport(aged_trial_report): inv_obj = pool['account.invoice'] + invoice_types = ( + ['out_invoice', 'out_refund'] if self.ttype == 'receipt' + else ['in_invoice', 'in_refund']) + invoice_ids = inv_obj.search(cr, uid, [ ('state', '=', 'open'), ('company_id', '=', company.id), ('partner_id', '=', partner.id), - ('type', '=', 'out_invoice' - if self.ttype == 'receipt' else 'in_invoice'), + ('type', 'in', invoice_types), ], context=context) invoices = inv_obj.browse(cr, uid, invoice_ids, context=context) @@ -168,6 +178,7 @@ class PartnerAgedTrialReport(aged_trial_report): 'name': inv.number, 'ref': inv.reference or '', 'id': inv.id, + 'type': inv.type, } for inv in invoices ], key=lambda inv: inv['date_original']) @@ -183,9 +194,13 @@ class PartnerAgedTrialReport(aged_trial_report): movelines = self._get_current_invoice_lines(partner, company, today) movelines = [ line for line in movelines - if not line['date_original'] or - line['date_original'] >= stop + if (( + not line['date_original'] or + line['date_original'] >= stop + ) and line['type'] in ['in_invoice', 'out_invoice']) ] + + print movelines return movelines def _lines_get_30_60(self, partner, company): @@ -200,8 +215,10 @@ class PartnerAgedTrialReport(aged_trial_report): movelines = self._get_current_invoice_lines(partner, company, today) movelines = [ line for line in movelines - if line['date_original'] and - stop < line['date_original'] <= start + if (( + line['date_original'] and + stop < line['date_original'] <= start + ) and line['type'] in ['in_invoice', 'out_invoice']) ] return movelines @@ -215,8 +232,27 @@ class PartnerAgedTrialReport(aged_trial_report): movelines = self._get_current_invoice_lines(partner, company, today) movelines = [ line for line in movelines - if line['date_original'] and - line['date_original'] <= start + if (( + line['date_original'] and + line['date_original'] <= start + ) and line['type'] in ['in_invoice', 'out_invoice']) + ] + return movelines + + def _refunds_total(self, partner, company): + today = self.today + movelines = self._get_current_invoice_lines(partner, company, today) + return sum( + line['amount_unreconciled'] for line in movelines + if line['type'] in ['in_refund', 'out_refund'] + ) + + def _lines_get_refunds(self, partner, company): + today = self.today + movelines = self._get_current_invoice_lines(partner, company, today) + movelines = [ + line for line in movelines + if line['type'] in ['in_refund', 'out_refund'] ] return movelines 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 b946bbc8..3a6d73c7 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 @@ -31,10 +31,11 @@ class SupplierAgedTrialReport(PartnerAgedTrialReport): """ def __init__(self, cr, uid, name, context): super(SupplierAgedTrialReport, self).__init__(cr, uid, name, context) + self.ttype = 'payment' self.localcontext.update({ 'show_message': False, + 'ttype': self.ttype, }) - self.ttype = 'payment' WebKitParser( diff --git a/account_partner_aged_statement_webkit/tests/test_aged_statement.py b/account_partner_aged_statement_webkit/tests/test_aged_statement.py index b74459eb..a698f7d3 100644 --- a/account_partner_aged_statement_webkit/tests/test_aged_statement.py +++ b/account_partner_aged_statement_webkit/tests/test_aged_statement.py @@ -103,14 +103,17 @@ class test_aged_statement(common.TransactionCase): 'price_unit': invoice[1], 'quantity': 1, })], + 'type': invoice[2], }, context=context) for invoice in [ - (self.today, 300), - (self.date1, 100), - (self.date2, 150), - (self.date3, 200), - (self.date4, 250), - (self.date5, 500), + (self.today, 300, 'out_invoice'), + (self.date1, 100, 'out_invoice'), + (self.date2, 150, 'out_invoice'), + (self.date3, 200, 'out_invoice'), + (self.date4, 250, 'out_invoice'), + (self.date5, 500, 'out_invoice'), + (self.date2, 600, 'out_refund'), + (self.date4, 700, 'out_refund'), ] ] @@ -193,3 +196,25 @@ class test_aged_statement(common.TransactionCase): 'amount_original': 200, 'amount_unreconciled': 200, }) + + def test_line_get_refunds(self): + lines = sorted( + self.report._lines_get_refunds(self.partner, self.company), + key=lambda l: l['date_original']) + + self.compare_vals(lines[0], { + 'date_original': self.date4, + 'amount_original': 700, + 'amount_unreconciled': 700, + }) + + self.compare_vals(lines[1], { + 'date_original': self.date2, + 'amount_original': 600, + 'amount_unreconciled': 600, + }) + + def test_refunds_total(self): + res = self.report._refunds_total(self.partner, self.company) + + self.assertEqual(res, 1300)