Skip to content

Commit

Permalink
[IMP] product_pricelist_supplierinfo: add option to exclude discount …
Browse files Browse the repository at this point in the history
…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.
  • Loading branch information
CLaurelB committed Jan 7, 2025
1 parent c5805cf commit 928c03f
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions product_pricelist_supplierinfo/models/product_supplierinfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 3 additions & 1 deletion product_pricelist_supplierinfo/models/product_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 16 additions & 0 deletions product_pricelist_supplierinfo/tests/test_product_supplierinfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@
name="no_supplierinfo_min_quantity"
invisible="base != 'supplierinfo'"
/>
<field
name="no_supplierinfo_discount"
invisible="base != 'supplierinfo'"
/>
<field name="filter_supplier_id" invisible="base != 'supplierinfo'" />
</xpath>
</field>
Expand Down

0 comments on commit 928c03f

Please sign in to comment.