From 97c1fbc18b969278266260cf74affc54feb24241 Mon Sep 17 00:00:00 2001 From: aliya Date: Tue, 22 Nov 2022 08:45:53 +0000 Subject: [PATCH] [FIX] account: bill date rather than accounting MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit We should always use `invoice_date` instead of the `date` of the move for currency exchange. Re-adding some of the changes from odoo/odoo#87984 task-2807136 closes odoo/odoo#106367 X-original-commit: 76a640d05a350840bdde1c88bd052251aabd6b12 Signed-off-by: William André (wan) --- addons/account/models/account_move.py | 4 ++-- addons/account/models/account_move_line.py | 2 +- .../account/tests/test_account_move_out_invoice.py | 12 ++++++------ 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/addons/account/models/account_move.py b/addons/account/models/account_move.py index 6ef79e8fc38..8d753ff75bc 100644 --- a/addons/account/models/account_move.py +++ b/addons/account/models/account_move.py @@ -1462,7 +1462,7 @@ class AccountMove(models.Model): to_write = [] amount_currency = abs(move.amount_total) - balance = move.currency_id._convert(amount_currency, move.company_currency_id, move.company_id, move.date) + balance = move.currency_id._convert(amount_currency, move.company_currency_id, move.company_id, move.invoice_date or move.date) for line in move.line_ids: if not line.currency_id.is_zero(balance - abs(line.balance)): @@ -1788,7 +1788,7 @@ class AccountMove(models.Model): diff_amount_currency = diff_balance = difference else: diff_amount_currency = difference - diff_balance = self.currency_id._convert(diff_amount_currency, self.company_id.currency_id, self.company_id, self.date) + diff_balance = self.currency_id._convert(diff_amount_currency, self.company_id.currency_id, self.company_id, self.invoice_date or self.date) return diff_balance, diff_amount_currency def _apply_cash_rounding(self, diff_balance, diff_amount_currency, cash_rounding_line): diff --git a/addons/account/models/account_move_line.py b/addons/account/models/account_move_line.py index 706c21d5627..af7f209c0d5 100644 --- a/addons/account/models/account_move_line.py +++ b/addons/account/models/account_move_line.py @@ -631,7 +631,7 @@ class AccountMoveLine(models.Model): from_currency=line.company_currency_id, to_currency=line.currency_id, company=line.company_id, - date=line.move_id.date or fields.Date.context_today(line), + date=line.move_id.invoice_date or line.move_id.date or fields.Date.context_today(line), ) @api.depends('currency_id', 'company_currency_id') diff --git a/addons/account/tests/test_account_move_out_invoice.py b/addons/account/tests/test_account_move_out_invoice.py index d5c742ed818..1ca34354b2c 100644 --- a/addons/account/tests/test_account_move_out_invoice.py +++ b/addons/account/tests/test_account_move_out_invoice.py @@ -2327,9 +2327,9 @@ class TestAccountMoveOutInvoiceOnchanges(AccountTestInvoicingCommon): { **self.tax_line_vals_1, 'currency_id': self.currency_data['currency'].id, - 'amount_currency': -180.0, + 'amount_currency': -200.0, 'debit': 0.0, - 'credit': 90.0, + 'credit': 100.0, }, { **self.tax_line_vals_2, @@ -2342,8 +2342,8 @@ class TestAccountMoveOutInvoiceOnchanges(AccountTestInvoicingCommon): **self.term_line_vals_1, 'name': move.name, 'currency_id': self.currency_data['currency'].id, - 'amount_currency': 1410.0, - 'debit': 705.0, + 'amount_currency': 1430.0, + 'debit': 715.0, 'credit': 0.0, 'date_maturity': fields.Date.from_string('2017-01-15'), }, @@ -2353,8 +2353,8 @@ class TestAccountMoveOutInvoiceOnchanges(AccountTestInvoicingCommon): 'currency_id': self.currency_data['currency'].id, 'date': fields.Date.from_string('2017-01-15'), 'amount_untaxed': 1200.0, - 'amount_tax': 210.0, - 'amount_total': 1410.0, + 'amount_tax': 230.0, + 'amount_total': 1430.0, }) def test_out_invoice_switch_out_refund_1(self):