From 74e4130f5f370c6ea8979df87a7c973f71e92f32 Mon Sep 17 00:00:00 2001 From: Nicolas Martinelli Date: Fri, 14 Jul 2017 11:09:27 +0200 Subject: [PATCH] [FIX] account: accounting date vs invoice date The accounting date is an hidden field, which is by default the invoice date. However, a user can make it available in the interface, and modify it. When the accounting date is different from the invoice date, we must make sure to make the accounting date prevail when it comes to currency conversion. Otherwise, the account move created will use a currency exchange rate which is not in line with its date. opw-751848 --- addons/account/models/account_invoice.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/addons/account/models/account_invoice.py b/addons/account/models/account_invoice.py index 1f58f5aa1e7..3755689cf5e 100644 --- a/addons/account/models/account_invoice.py +++ b/addons/account/models/account_invoice.py @@ -698,7 +698,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_invoice or fields.Date.context_today(self)) + currency = self.currency_id.with_context(date=self.date or self.date_invoice 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']) @@ -832,7 +832,6 @@ class AccountInvoice(models.Model): if not inv.date_invoice: inv.with_context(ctx).write({'date_invoice': fields.Date.context_today(self)}) - date_invoice = inv.date_invoice company_currency = inv.company_id.currency_id # create move lines (one per invoice line + eventual taxes and analytic lines) @@ -845,9 +844,9 @@ class AccountInvoice(models.Model): name = inv.name or '/' if inv.payment_term_id: - totlines = inv.with_context(ctx).payment_term_id.with_context(currency_id=company_currency.id).compute(total, date_invoice)[0] + 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'] = date_invoice + ctx['date'] = inv.date or inv.date_invoice 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) @@ -887,7 +886,7 @@ class AccountInvoice(models.Model): journal = inv.journal_id.with_context(ctx) line = inv.finalize_invoice_move_lines(line) - date = inv.date or date_invoice + date = inv.date or inv.date_invoice move_vals = { 'ref': inv.reference, 'line_ids': line,