|
|
discount_enabled = self.env["product.pricelist.item"]._is_discount_feature_enabled()
for line in self:
if not line.product_id or line.display_type:
line.discount = 0.0
if not (line.order_id.pricelist_id and discount_enabled and line.product_uom_id):
continue
if line.combo_item_id:
line.discount = line._get_linked_line().discount
continue
line.discount = 0.0
if not line.pricelist_item_id._show_discount():
# No pricelist rule was found for the product
# therefore, the pricelist didn't apply any discount/change
# to the existing sales price.
continue
line = line.with_company(line.company_id)
pricelist_price = line._get_pricelist_price()
base_price = line._get_pricelist_price_before_discount()
if base_price != 0: # Avoid division by zero
discount = (base_price - pricelist_price) / base_price * 100
if (discount > 0 and base_price > 0) or (discount < 0 and base_price < 0):
# only show negative discounts if price is negative
# otherwise it's a surcharge which shouldn't be shown to the customer
line.discount = discount
|
|