From 25e39cdf1b460277f306104c5d1beaaee70c0d5b Mon Sep 17 00:00:00 2001 From: Thibault Francois Date: Wed, 19 Feb 2020 12:35:13 +0000 Subject: [PATCH] [FIX] account: set proper account_id one line When you create a invoice from a sale_order the account was taken from the journal and it should comes from the product or the product_categories and in last resort the journal and finally fiscal position should have been apply. It was not the case anymore, because setting the partner_id prior the account_id trigger the default_get on the account_id which in that case take the wrong value closes odoo/odoo#47267 Solution: set first the account_id then the partner_id X-original-commit: 857564367691f3f11572f718499c9d22c823c421 Signed-off-by: Quentin De Paoli (qdp) --- addons/account/models/account_move.py | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/addons/account/models/account_move.py b/addons/account/models/account_move.py index ffa5010d415..96064fbb046 100644 --- a/addons/account/models/account_move.py +++ b/addons/account/models/account_move.py @@ -1507,12 +1507,6 @@ class AccountMove(models.Model): if line.exclude_from_invoice_tab: continue - # Ensure related fields are well copied. - line.partner_id = self.partner_id - line.date = self.date - line.recompute_tax_line = True - line.currency_id = line_currency - # Shortcut to load the demo data. # Doing line.account_id triggers a default_get(['account_id']) that could returns a result. # A section / note must not have an account_id set. @@ -1526,6 +1520,19 @@ class AccountMove(models.Model): if line.product_id and not line._cache.get('name'): line.name = line._get_computed_name() + # Compute the account before the partner_id + # In case account_followup is installed + # Setting the partner will get the account_id in cache + # If the account_id is not in cache, it will trigger the default value + # Which is wrong in some case + # It's better to set the account_id before the partner_id + # Ensure related fields are well copied. + line.partner_id = self.partner_id + line.date = self.date + line.recompute_tax_line = True + line.currency_id = line_currency + + self.line_ids._onchange_price_subtotal() self._recompute_dynamic_lines(recompute_all_taxes=True)