From 2a7f5e25f178e71af6511512b5b2585e6c40558b Mon Sep 17 00:00:00 2001 From: Wolfgang Taferner Date: Thu, 15 Oct 2020 08:50:56 +0000 Subject: [PATCH] [FIX] account: balance with line quantity > 1 and fiscal position Currently the onchange is setting the price_unit to the price_subtotal to work out the proper price unit related to the tax, but does not have a different line quantity in mind. The update of the price_unit was raising a balance difference UserError which is now resolved by the fact that we only update the price_unit if it is affected OPW-2362066 closes odoo/odoo#60256 X-original-commit: 8c8d803992c31ba68a12801fa6dd4dcf909d9ed9 Signed-off-by: Laurent Smet --- addons/account/models/account_move.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/addons/account/models/account_move.py b/addons/account/models/account_move.py index 1ebafd3ce3c..bf0d8196f6d 100644 --- a/addons/account/models/account_move.py +++ b/addons/account/models/account_move.py @@ -3332,11 +3332,17 @@ class AccountMoveLine(models.Model): # E.g. mapping a 10% price-included tax to a 20% price-included tax for a price_unit of 110 should preserve # 100 as balance but set 120 as price_unit. if line.tax_ids and line.move_id.fiscal_position_id: - line.price_unit = line._get_price_total_and_subtotal()['price_subtotal'] - line.tax_ids = line.move_id.fiscal_position_id.map_tax(line.tax_ids._origin, partner=line.move_id.partner_id) - accounting_vals = line._get_fields_onchange_subtotal(price_subtotal=line.price_unit, currency=line.move_id.company_currency_id) + price_subtotal = line._get_price_total_and_subtotal()['price_subtotal'] + line.tax_ids = line.move_id.fiscal_position_id.map_tax( + line.tax_ids._origin, + partner=line.move_id.partner_id) + accounting_vals = line._get_fields_onchange_subtotal( + price_subtotal=price_subtotal, + currency=line.move_id.company_currency_id) amount_currency = accounting_vals['amount_currency'] - line.price_unit = line._get_fields_onchange_balance(amount_currency=amount_currency).get('price_unit', line.price_unit) + business_vals = line._get_fields_onchange_balance(amount_currency=amount_currency) + if 'price_unit' in business_vals: + line.price_unit = business_vals['price_unit'] # Convert the unit price to the invoice's currency. company = line.move_id.company_id