Skip to content

Commit

Permalink
[FIX] product,sale: allow negative discounts in pricelist advanced fo…
Browse files Browse the repository at this point in the history
…rmula

Between v9.0 and v10.0 a pricelist refactoring made it so negative
discounts no longer worked correctly. They should always be
included in the unit price of the product (not to be displayed as a
negative discount even if the option to display the discount is
enabled).

This commit also corrects currency conversion issues when basing the
price on another pricelist with a differnt currency, and when making
the sales order in a company with a different currency than the
pricelists currency.
  • Loading branch information
Icallhimtest committed Oct 25, 2017
1 parent b7d2bb3 commit 33a0435
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
2 changes: 1 addition & 1 deletion addons/product/models/product_pricelist.py
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,7 @@ def _get_pricelist_item_name_price(self):
elif self.compute_price == 'percentage':
self.price = _("%s %% discount") % (self.percent_price)
else:
self.price = _("%s %% discount and %s surcharge") % (abs(self.price_discount), self.price_surcharge)
self.price = _("%s %% discount and %s surcharge") % (self.price_discount, self.price_surcharge)

@api.onchange('applied_on')
def _onchange_applied_on(self):
Expand Down
15 changes: 8 additions & 7 deletions addons/sale/models/sale.py
Original file line number Diff line number Diff line change
Expand Up @@ -850,15 +850,16 @@ 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 == '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)
final_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
if pricelist_item.base == 'pricelist':
base_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)
base_price = pricelist_item.base_pricelist_id.currency_id.compute(base_price, self.order_id.pricelist_id.currency_id)
else:
from_currency = self.order_id.company_id.currency_id
product_price = product[pricelist_item.base] if (pricelist_item and pricelist_item.base != 'pricelist') else product.lst_price
return from_currency.compute(product_price, self.order_id.pricelist_id.currency_id)
base_price = product[pricelist_item.base] if pricelist_item else product.lst_price
base_price = product.currency_id.compute(base_price, self.order_id.pricelist_id.currency_id)
# negative discounts (= surcharge) are included in the display price (= unit price)
return max(base_price, final_price)

@api.multi
@api.onchange('product_id')
Expand Down

0 comments on commit 33a0435

Please sign in to comment.