From 928c03f5b6e1bce207c4d12f9a2861ca4942dc31 Mon Sep 17 00:00:00 2001 From: "Christihan Laurel [Vauxoo]" Date: Mon, 6 Jan 2025 23:50:38 +0000 Subject: [PATCH] [IMP] product_pricelist_supplierinfo: add option to exclude discount in product supplier info Introduce a new field to optionally exclude the discount set in the product supplier info when calculating the product's price. Additionally, add a test to validate the new functionality. --- .../models/product_pricelist_item.py | 3 +++ .../models/product_supplierinfo.py | 6 +++--- .../models/product_template.py | 4 +++- .../tests/test_product_supplierinfo.py | 16 ++++++++++++++++ .../views/product_pricelist_item_views.xml | 4 ++++ 5 files changed, 29 insertions(+), 4 deletions(-) diff --git a/product_pricelist_supplierinfo/models/product_pricelist_item.py b/product_pricelist_supplierinfo/models/product_pricelist_item.py index c490d920df0..bb6af35ad04 100644 --- a/product_pricelist_supplierinfo/models/product_pricelist_item.py +++ b/product_pricelist_supplierinfo/models/product_pricelist_item.py @@ -20,6 +20,9 @@ class ProductPricelistItem(models.Model): string="Supplier filter", help="Only match prices from the selected supplier", ) + no_supplierinfo_discount = fields.Boolean( + string="Ignore Supplier Info Discount", + ) def _compute_price(self, product, quantity, uom, date, currency=None): result = super()._compute_price(product, quantity, uom, date, currency) diff --git a/product_pricelist_supplierinfo/models/product_supplierinfo.py b/product_pricelist_supplierinfo/models/product_supplierinfo.py index 1a8e637cbba..0ab428b7fb5 100644 --- a/product_pricelist_supplierinfo/models/product_supplierinfo.py +++ b/product_pricelist_supplierinfo/models/product_supplierinfo.py @@ -13,9 +13,9 @@ class ProductSupplierinfo(models.Model): help="Margin to apply on price to obtain sale price", ) - def _get_supplierinfo_pricelist_price(self): + def _get_supplierinfo_pricelist_price(self, no_supplierinfo_discount=False): self.ensure_one() - sale_price = self.price + sale_price = self.price if no_supplierinfo_discount else self.price_discounted if self.sale_margin: - sale_price = (self.price + (self.price * (self.sale_margin / 100))) or 0.0 + sale_price = (sale_price + (sale_price * (self.sale_margin / 100))) or 0.0 return sale_price diff --git a/product_pricelist_supplierinfo/models/product_template.py b/product_pricelist_supplierinfo/models/product_template.py index 589855500b9..32c7dd91c10 100644 --- a/product_pricelist_supplierinfo/models/product_template.py +++ b/product_pricelist_supplierinfo/models/product_template.py @@ -41,7 +41,9 @@ def _get_supplierinfo_pricelist_price( date=date, ) if seller: - price = seller._get_supplierinfo_pricelist_price() + price = seller._get_supplierinfo_pricelist_price( + rule.no_supplierinfo_discount + ) if price: # We need to convert the price if the pricelist and seller have # different currencies so the price have the pricelist currency diff --git a/product_pricelist_supplierinfo/tests/test_product_supplierinfo.py b/product_pricelist_supplierinfo/tests/test_product_supplierinfo.py index 31521cfa97e..4e443bd3387 100644 --- a/product_pricelist_supplierinfo/tests/test_product_supplierinfo.py +++ b/product_pricelist_supplierinfo/tests/test_product_supplierinfo.py @@ -311,3 +311,19 @@ def test_line_uom_and_supplierinfo_uom(self): # And the price with the pricelist and the uom of Units (Instead of Dozen) # will be 100, plus the 20% the total will be 120 per Unit self.assertEqual(product_pricelist_price_unit, 120) + + def test_pricelist_exclude_supplier_info_discount(self): + """Test the scenario where the product supplier info includes a discount,to + verify the functionality of the option to exclude this discount from the price + calculation. + """ + self.product.seller_ids[1].discount = 10 + self.assertAlmostEqual( + self.pricelist._get_product_price(self.product, 1), + 9, + ) + self.pricelist.item_ids[0].no_supplierinfo_discount = True + self.assertAlmostEqual( + self.pricelist._get_product_price(self.product, 1), + 10, + ) diff --git a/product_pricelist_supplierinfo/views/product_pricelist_item_views.xml b/product_pricelist_supplierinfo/views/product_pricelist_item_views.xml index 7089a7a33a5..713896f0af6 100644 --- a/product_pricelist_supplierinfo/views/product_pricelist_item_views.xml +++ b/product_pricelist_supplierinfo/views/product_pricelist_item_views.xml @@ -11,6 +11,10 @@ name="no_supplierinfo_min_quantity" invisible="base != 'supplierinfo'" /> +