Skip to content
Permalink
Browse files

m

  • Loading branch information...
nim-odoo committed Mar 25, 2019
1 parent 86eb3b4 commit 969141f05b066b1c725903142ef471f34d3b814b
Showing with 14 additions and 16 deletions.
  1. +10 −5 addons/sale/models/sale.py
  2. +4 −11 addons/website_sale/models/sale_order.py
@@ -1205,7 +1205,6 @@ def _onchange_discount(self):
self.env.user.has_group('sale.group_discount_per_so_line')):
return

self.discount = 0.0
product = self.product_id.with_context(
lang=self.order_id.partner_id.lang,
partner=self.order_id.partner_id.id,
@@ -1217,17 +1216,23 @@ def _onchange_discount(self):
)

product_context = dict(self.env.context, partner_id=self.order_id.partner_id.id, date=self.order_id.date_order, uom=self.product_uom.id)
self.dicount = self._get_discount(
self.order_id.pricelist_id, self.product_id, self.product_uom_qty,
self.order_id.partner_id, product, self.product_uom, product_context
)

price, rule_id = self.order_id.pricelist_id.with_context(product_context).get_product_price_rule(self.product_id, self.product_uom_qty or 1.0, self.order_id.partner_id)
new_list_price, currency_id = self.with_context(product_context)._get_real_price_currency(product, rule_id, self.product_uom_qty, self.product_uom, self.order_id.pricelist_id.id)
def _get_discount(self, pricelist_id, product_id, product_uom_qty, partner_id, product_with_context, product_uom, product_context):
price, rule_id = pricelist_id.with_context(product_context).get_product_price_rule(product_id, product_uom_qty or 1.0, partner_id)
new_list_price, currency_id = self.with_context(product_context)._get_real_price_currency(product_with_context, rule_id, product_uom_qty, product_uom, pricelist_id.id)

if new_list_price != 0:
if self.order_id.pricelist_id.currency_id.id != currency_id:
# we need new_list_price in the same currency as price, which is in the SO's pricelist's currency
new_list_price = self.env['res.currency'].browse(currency_id).with_context(product_context).compute(new_list_price, self.order_id.pricelist_id.currency_id)
new_list_price = self.env['res.currency'].browse(currency_id).with_context(product_context).compute(new_list_price, pricelist_id.currency_id)
discount = (new_list_price - price) / new_list_price * 100
if discount > 0:
self.discount = discount
return discount
return 0

###########################
# Analytic Methods
@@ -97,21 +97,14 @@ def _website_product_id_change(self, order_id, product_id, qty=0):
'date': order.date_order,
'pricelist': order.pricelist_id.id,
})
product_without_context = self.env['product.product'].browse(product_id)
product = self.env['product.product'].with_context(product_context).browse(product_id)
discount = 0

if order.pricelist_id.discount_policy == 'without_discount':
# This part is pretty much a copy-paste of the method '_onchange_discount' of
# 'sale.order.line'.
price, rule_id = order.pricelist_id.with_context(product_context).get_product_price_rule(product, qty or 1.0, order.partner_id)
pu, currency_id = request.env['sale.order.line'].with_context(product_context)._get_real_price_currency(product, rule_id, qty, product.uom_id, order.pricelist_id.id)
if pu != 0:
if order.pricelist_id.currency_id.id != currency_id:
# we need new_list_price in the same currency as price, which is in the SO's pricelist's currency
pu = request.env['res.currency'].browse(currency_id).with_context(product_context).compute(pu, order.pricelist_id.currency_id)
discount = (pu - price) / pu * 100
if discount < 0:
discount = 0
discount = request.env['sale.order.line']._get_discount(
order.pricelist_id, product_without_context, qty, order.partner_id, product, product.uom_id, product_context
)
else:
pu = product.price
if order.pricelist_id and order.partner_id:

0 comments on commit 969141f

Please sign in to comment.
You can’t perform that action at this time.