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,