summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGoffin Simon <sig@odoo.com>2016-07-25 13:47:07 +0200
committerGoffin Simon <sig@odoo.com>2016-07-25 15:57:34 +0200
commit19e3757ffb0a68cd1aec8d7cde30f8a385981946 (patch)
tree0c5746bac127c165a54b574bc329e4cbca2886d7
parentfc0f02305347ed46e8fdc7dd68188d17dc9b09a6 (diff)
[FIX] product_visible_discount, sale: compute the right unit price
When the module product_visible_discount is installed, the field 'discount_policy' allows to display the discount in the sale order or allows to consider the discount as include in the price_unit. The field price on product.product always compute the price according to the pricelist then it always includes the discount in the price. The field lst_price on product.product never compute the price according to the pricelist then it always gives the sale price. According to the discount_policy, the price or the lst_price must be taken. opw:683771
-rw-r--r--addons/product_visible_discount/product_visible_discount.py11
-rw-r--r--addons/sale/sale.py8
2 files changed, 15 insertions, 4 deletions
diff --git a/addons/product_visible_discount/product_visible_discount.py b/addons/product_visible_discount/product_visible_discount.py
index 286b30743a7..78500bf31c9 100644
--- a/addons/product_visible_discount/product_visible_discount.py
+++ b/addons/product_visible_discount/product_visible_discount.py
@@ -67,12 +67,19 @@ class sale_order_line(osv.osv):
list_price = self.order_id.pricelist_id.with_context(pricelist_context).price_rule_get(self.product_id.id, self.product_uom_qty or 1.0, self.order_id.partner_id)
new_list_price, currency_id = self.with_context(context_partner)._get_real_price_currency(self.product_id.id, list_price, self.product_uom_qty, self.product_uom.id, self.order_id.pricelist_id.id)
new_list_price = self.env['account.tax']._fix_tax_included_price(new_list_price, self.product_id.taxes_id, self.tax_id)
+ list_price = list_price[self.order_id.pricelist_id.id][0]
- if list_price[self.order_id.pricelist_id.id][0] != 0 and new_list_price != 0:
+ if list_price != 0 and new_list_price != 0:
if self.product_id.company_id and self.order_id.pricelist_id.currency_id != self.product_id.company_id.currency_id:
# new_list_price is in company's currency while price in pricelist currency
ctx = dict(context_partner, date=self.order_id.date_order)
new_list_price = self.env['res.currency'].browse(currency_id).with_context(ctx).compute(new_list_price, self.order_id.pricelist_id.currency_id)
- discount = (new_list_price - self.price_unit) / new_list_price * 100
+ discount = (new_list_price - list_price) / new_list_price * 100
if discount > 0:
self.discount = discount
+
+ @api.multi
+ def _get_display_price(self, product):
+ if self.order_id.pricelist_id.discount_policy == 'without_discount':
+ return product.lst_price
+ return super(sale_order_line, self)._get_display_price(product)
diff --git a/addons/sale/sale.py b/addons/sale/sale.py
index a9d62e52d53..6821a7061aa 100644
--- a/addons/sale/sale.py
+++ b/addons/sale/sale.py
@@ -738,6 +738,10 @@ class SaleOrderLine(models.Model):
self.env['account.invoice.line'].create(vals)
@api.multi
+ def _get_display_price(self, product):
+ return product.price
+
+ @api.multi
@api.onchange('product_id')
def product_id_change(self):
if not self.product_id:
@@ -765,7 +769,7 @@ class SaleOrderLine(models.Model):
self._compute_tax_id()
if self.order_id.pricelist_id and self.order_id.partner_id:
- vals['price_unit'] = self.env['account.tax']._fix_tax_included_price(product.price, product.taxes_id, self.tax_id)
+ vals['price_unit'] = self.env['account.tax']._fix_tax_included_price(self._get_display_price(product), product.taxes_id, self.tax_id)
self.update(vals)
return {'domain': domain}
@@ -784,7 +788,7 @@ class SaleOrderLine(models.Model):
uom=self.product_uom.id,
fiscal_position=self.env.context.get('fiscal_position')
)
- self.price_unit = self.env['account.tax']._fix_tax_included_price(product.price, product.taxes_id, self.tax_id)
+ self.price_unit = self.env['account.tax']._fix_tax_included_price(self._get_display_price(product), product.taxes_id, self.tax_id)
@api.multi
def unlink(self):