From 80cc00c873a179b916ff70ca7644310e745482de Mon Sep 17 00:00:00 2001 From: luis Date: Thu, 10 Jul 2025 11:18:54 +0200 Subject: [PATCH] LaOsaCoop/Odoo16#52 fix product_sale_price_from_pricelist to include taxes in final price --- .../models/product_template.py | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/product_sale_price_from_pricelist/models/product_template.py b/product_sale_price_from_pricelist/models/product_template.py index 5ccf188..4e831df 100644 --- a/product_sale_price_from_pricelist/models/product_template.py +++ b/product_sale_price_from_pricelist/models/product_template.py @@ -5,6 +5,7 @@ from odoo import exceptions, models, fields, api, _ from odoo.exceptions import UserError +import math class ProductTemplate(models.Model): @@ -65,11 +66,22 @@ class ProductTemplate(models.Model): partial_price = template.product_variant_id._get_price( qty=1, pricelist=pricelist ) + # Compute taxes to add + tax_price = self.taxes_id.compute_all( + partial_price[template.product_variant_id.id]["value"] or 0.0, + handle_price_include=False, + ) + price_with_taxes = ( + tax_price["taxes"][0]["amount"] + + partial_price[template.product_variant_id.id]["value"] + ) + # Round to 0.05 + if round(price_with_taxes % 0.05, 2) != 0: + price_with_taxes = math.ceil(price_with_taxes / 0.05) * 0.05 + template.write( { - "list_price_theoritical": partial_price[ - template.product_variant_id.id - ]["value"], + "list_price_theoritical": price_with_taxes, "last_purchase_price_updated": True, } )