From 8b69b2f7323d9193eb971854b0c7134c592d1206 Mon Sep 17 00:00:00 2001 From: Nicolas Martinelli Date: Wed, 13 Dec 2017 13:34:21 +0100 Subject: [PATCH] [REF] account: hook for currency rate Commit 74e4130f5f370 makes sure to make the accounting date prevail on the invoice date when it comes to currency conversion. However, the choice of date is not universally recognized. Softwares (and accountants) might use either the accounting date or the invoice date. Therefore, we provide a hook se the behavior of the software can easily be changed if necessary. opw-783372 --- addons/account/models/account_invoice.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/addons/account/models/account_invoice.py b/addons/account/models/account_invoice.py index 83a4c015179..8ea2fc69e24 100644 --- a/addons/account/models/account_invoice.py +++ b/addons/account/models/account_invoice.py @@ -700,7 +700,7 @@ class AccountInvoice(models.Model): total_currency = 0 for line in invoice_move_lines: if self.currency_id != company_currency: - currency = self.currency_id.with_context(date=self.date or self.date_invoice or fields.Date.context_today(self)) + currency = self.currency_id.with_context(date=self._get_currency_rate_date() or fields.Date.context_today(self)) if not (line.get('currency_id') and line.get('amount_currency')): line['currency_id'] = currency.id line['amount_currency'] = currency.round(line['price']) @@ -848,7 +848,7 @@ class AccountInvoice(models.Model): if inv.payment_term_id: totlines = inv.with_context(ctx).payment_term_id.with_context(currency_id=company_currency.id).compute(total, inv.date_invoice)[0] res_amount_currency = total_currency - ctx['date'] = inv.date or inv.date_invoice + ctx['date'] = inv._get_currency_rate_date() for i, t in enumerate(totlines): if inv.currency_id != company_currency: amount_currency = company_currency.with_context(ctx).compute(t[1], inv.currency_id) @@ -1029,6 +1029,9 @@ class AccountInvoice(models.Model): copy_fields = ['company_id', 'user_id', 'fiscal_position_id'] return self._get_refund_common_fields() + self._get_refund_prepare_fields() + copy_fields + def _get_currency_rate_date(self): + return self.date or self.date_invoice + @api.model def _prepare_refund(self, invoice, date_invoice=None, date=None, description=None, journal_id=None): """ Prepare the dict of values to create the new refund from the invoice.