From 130e71f2e44b3508531cbcda2b9ca9de91e8e8fd Mon Sep 17 00:00:00 2001 From: Goffin Simon Date: Tue, 4 Apr 2017 11:39:37 +0200 Subject: [PATCH] [FIX] sale: _get_display_price with pricelist item based on other pricelist Create a product P with a price = 1799 Make a pricelist P1 in USD with an item I1 for a product P with a fixed price to 100. Set P1 with discount_policy = "with_discount"(include in price) Make another pricelist P2 in USD with an item I2 based on P1. I2 is a formula = 50% of the price Set P2 with discount_policy = "without_discount" Create a SO with P2 for the product P Bug: The subtotal of P is 899.5 instead of 50 The problem came from _get_display_price wich in this case recomputed the price according to the discount(in this case equal to 50% and this is the good discount to display because P1 include the discount) and the lst_price of the product(=1799) So the displayed price was equal to 899.5 instead of 50. All the other cases worked because 1. P1 without_discount and P2 without_discount: Price returned by _get_display_price was equal to 1799 with a discount of 97,2% So the subtotal was equal to 50 2. P1 without_discount and P2 with_discount: Price returned by _get_display_price was equal to 100 with a discount of 50% So the subtotal was equal to 50 3. P1 with_discount and P2 with_discount: Price returned by _get_display_price was equal to 50 with a discount of 0% So the subtotal was equal to 50 And the last case(P1 with_discount and P2 without_discount) didn't work because: Price returned by _get_display_price was equal to 1799 with a discount of 50% So the subtotal was equal to 899.5 NB: The subtotal is computed with function "_compute_amount" with the following line: price = line.price_unit * (1 - (line.discount or 0.0) / 100.0) opw:724924 --- addons/sale/models/sale.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/addons/sale/models/sale.py b/addons/sale/models/sale.py index b4f8286a959..c2b26771b94 100644 --- a/addons/sale/models/sale.py +++ b/addons/sale/models/sale.py @@ -835,10 +835,16 @@ class SaleOrderLine(models.Model): @api.multi def _get_display_price(self, product): # TO DO: move me in master/saas-16 on sale.order - if self.order_id.pricelist_id.discount_policy == 'without_discount': + if self.order_id.pricelist_id.discount_policy == 'with_discount': + return product.with_context(pricelist=self.order_id.pricelist_id.id).price + price, rule_id = self.order_id.pricelist_id.get_product_price_rule(self.product_id, self.product_uom_qty or 1.0, self.order_id.partner_id) + pricelist_item = self.env['product.pricelist.item'].browse(rule_id) + if (pricelist_item.base == 'pricelist' and pricelist_item.base_pricelist_id.discount_policy == 'with_discount'): + price, rule_id = pricelist_item.base_pricelist_id.get_product_price_rule(self.product_id, self.product_uom_qty or 1.0, self.order_id.partner_id) + return price + else: from_currency = self.order_id.company_id.currency_id return from_currency.compute(product.lst_price, self.order_id.pricelist_id.currency_id) - return product.with_context(pricelist=self.order_id.pricelist_id.id).price @api.multi @api.onchange('product_id')