[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
This commit is contained in:
Goffin Simon
2016-07-25 15:57:34 +02:00
parent fc0f023053
commit 19e3757ffb
2 changed files with 15 additions and 4 deletions
@@ -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)
+6 -2
View File
@@ -737,6 +737,10 @@ class SaleOrderLine(models.Model):
vals.update({'invoice_id': invoice_id, 'sale_line_ids': [(6, 0, [line.id])]})
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):
@@ -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):