From 4ba265a3287e34f56651e32fab40db8565752c69 Mon Sep 17 00:00:00 2001 From: Laurent Smet Date: Tue, 31 Mar 2020 15:01:34 +0000 Subject: [PATCH] [FIX] account: Recompute the account set on payment terms when changing the partner. - Create an invoice without partner. - Set a custom receivable account. - Set a partner => the account used as payment terms is not recomputed that is wrong. closes odoo/odoo#48898 X-original-commit: 33de1c8f5e459eb26194736c17c053dce3a1c206 Signed-off-by: oco-odoo Signed-off-by: Laurent Smet --- addons/account/models/account_move.py | 13 +++++++++++-- .../account/tests/test_account_move_in_invoice.py | 2 ++ addons/account/tests/test_account_move_in_refund.py | 2 ++ .../account/tests/test_account_move_out_invoice.py | 2 ++ .../account/tests/test_account_move_out_refund.py | 2 ++ 5 files changed, 19 insertions(+), 2 deletions(-) diff --git a/addons/account/models/account_move.py b/addons/account/models/account_move.py index 31dbac1e80b..eb6f8dd2d9f 100644 --- a/addons/account/models/account_move.py +++ b/addons/account/models/account_move.py @@ -332,12 +332,21 @@ class AccountMove(models.Model): if p.invoice_warn == 'block': self.partner_id = False return {'warning': warning} - for line in self.line_ids: - line.partner_id = self.partner_id.commercial_partner_id + if self.is_sale_document(include_receipts=True) and self.partner_id.property_payment_term_id: self.invoice_payment_term_id = self.partner_id.property_payment_term_id + new_term_account = self.partner_id.commercial_partner_id.property_account_receivable_id elif self.is_purchase_document(include_receipts=True) and self.partner_id.property_supplier_payment_term_id: self.invoice_payment_term_id = self.partner_id.property_supplier_payment_term_id + new_term_account = self.partner_id.commercial_partner_id.property_account_payable_id + else: + new_term_account = None + + for line in self.line_ids: + line.partner_id = self.partner_id.commercial_partner_id + + if new_term_account and line.account_id.user_type_id.type in ('receivable', 'payable'): + line.account_id = new_term_account self._compute_bank_partner_id() self.invoice_partner_bank_id = self.bank_partner_id.bank_ids and self.bank_partner_id.bank_ids[0] diff --git a/addons/account/tests/test_account_move_in_invoice.py b/addons/account/tests/test_account_move_in_invoice.py index 42aed3dac6e..c25ae9c52d5 100644 --- a/addons/account/tests/test_account_move_in_invoice.py +++ b/addons/account/tests/test_account_move_in_invoice.py @@ -625,6 +625,7 @@ class TestAccountMoveInInvoiceOnchanges(AccountTestInvoicingCommon): **self.term_line_vals_1, 'name': 'turlututu', 'partner_id': self.partner_b.id, + 'account_id': self.partner_b.property_account_payable_id.id, 'price_unit': -789.6, 'price_subtotal': -789.6, 'price_total': -789.6, @@ -635,6 +636,7 @@ class TestAccountMoveInInvoiceOnchanges(AccountTestInvoicingCommon): **self.term_line_vals_1, 'name': 'turlututu', 'partner_id': self.partner_b.id, + 'account_id': self.partner_b.property_account_payable_id.id, 'price_unit': -338.4, 'price_subtotal': -338.4, 'price_total': -338.4, diff --git a/addons/account/tests/test_account_move_in_refund.py b/addons/account/tests/test_account_move_in_refund.py index 83740d9667b..2e0aaf520f9 100644 --- a/addons/account/tests/test_account_move_in_refund.py +++ b/addons/account/tests/test_account_move_in_refund.py @@ -337,6 +337,7 @@ class TestAccountMoveInRefundOnchanges(AccountTestInvoicingCommon): **self.term_line_vals_1, 'name': 'turlututu', 'partner_id': self.partner_b.id, + 'account_id': self.partner_b.property_account_payable_id.id, 'price_unit': -338.4, 'price_subtotal': -338.4, 'price_total': -338.4, @@ -346,6 +347,7 @@ class TestAccountMoveInRefundOnchanges(AccountTestInvoicingCommon): **self.term_line_vals_1, 'name': 'turlututu', 'partner_id': self.partner_b.id, + 'account_id': self.partner_b.property_account_payable_id.id, 'price_unit': -789.6, 'price_subtotal': -789.6, 'price_total': -789.6, diff --git a/addons/account/tests/test_account_move_out_invoice.py b/addons/account/tests/test_account_move_out_invoice.py index 2b860d6f12f..7edca0f9d8e 100644 --- a/addons/account/tests/test_account_move_out_invoice.py +++ b/addons/account/tests/test_account_move_out_invoice.py @@ -626,6 +626,7 @@ class TestAccountMoveOutInvoiceOnchanges(AccountTestInvoicingCommon): { **self.term_line_vals_1, 'name': 'turlututu', + 'account_id': self.partner_b.property_account_receivable_id.id, 'partner_id': self.partner_b.id, 'price_unit': -423.0, 'price_subtotal': -423.0, @@ -635,6 +636,7 @@ class TestAccountMoveOutInvoiceOnchanges(AccountTestInvoicingCommon): { **self.term_line_vals_1, 'name': 'turlututu', + 'account_id': self.partner_b.property_account_receivable_id.id, 'partner_id': self.partner_b.id, 'price_unit': -987.0, 'price_subtotal': -987.0, diff --git a/addons/account/tests/test_account_move_out_refund.py b/addons/account/tests/test_account_move_out_refund.py index 36474559266..369e85eb2dc 100644 --- a/addons/account/tests/test_account_move_out_refund.py +++ b/addons/account/tests/test_account_move_out_refund.py @@ -337,6 +337,7 @@ class TestAccountMoveOutRefundOnchanges(AccountTestInvoicingCommon): **self.term_line_vals_1, 'name': 'turlututu', 'partner_id': self.partner_b.id, + 'account_id': self.partner_b.property_account_receivable_id.id, 'price_unit': -987.0, 'price_subtotal': -987.0, 'price_total': -987.0, @@ -347,6 +348,7 @@ class TestAccountMoveOutRefundOnchanges(AccountTestInvoicingCommon): **self.term_line_vals_1, 'name': 'turlututu', 'partner_id': self.partner_b.id, + 'account_id': self.partner_b.property_account_receivable_id.id, 'price_unit': -423.0, 'price_subtotal': -423.0, 'price_total': -423.0,