Skip to content

Commit

Permalink
[FIX] product: variant sale price is wrong
Browse files Browse the repository at this point in the history
If applied, this commit will fix the following bug by using the price
with the additional cost added instead of only the price

Steps to reproduce:

1- install sales
2- create a product p with variant pv
3- set an extra value for pv
4- go to Products>Product Variants
5- open the pv in form view
6- the Sales Price is the price of p not pv
(which should be p + extra value)
7- also the tax string is calculated on p not pv

Bug:

```list_price``` is being used

Fix:

replace ```list_price``` with  ```lst_price```

OPW-2774199

closes odoo#87248

Signed-off-by: William André (wan) <wan@odoo.com>
  • Loading branch information
momegahed committed Apr 7, 2022
1 parent 80acf44 commit 46526f6
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 14 deletions.
37 changes: 24 additions & 13 deletions addons/account/models/product.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,24 +63,30 @@ def get_product_accounts(self, fiscal_pos=None):
@api.depends('taxes_id', 'list_price')
def _compute_tax_string(self):
for record in self:
currency = record.currency_id
res = record.taxes_id.compute_all(record.list_price, product=record, partner=self.env['res.partner'])
joined = []
included = res['total_included']
if currency.compare_amounts(included, record.list_price):
joined.append(_('%s Incl. Taxes', format_amount(self.env, included, currency)))
excluded = res['total_excluded']
if currency.compare_amounts(excluded, record.list_price):
joined.append(_('%s Excl. Taxes', format_amount(self.env, excluded, currency)))
if joined:
record.tax_string = f"(= {', '.join(joined)})"
else:
record.tax_string = " "
record.tax_string = record._construct_tax_string(record.list_price)

def _construct_tax_string(self, price):
currency = self.currency_id
res = self.taxes_id.compute_all(price, product=self, partner=self.env['res.partner'])
joined = []
included = res['total_included']
if currency.compare_amounts(included, price):
joined.append(_('%s Incl. Taxes', format_amount(self.env, included, currency)))
excluded = res['total_excluded']
if currency.compare_amounts(excluded, price):
joined.append(_('%s Excl. Taxes', format_amount(self.env, excluded, currency)))
if joined:
tax_string = f"(= {', '.join(joined)})"
else:
tax_string = " "
return tax_string


class ProductProduct(models.Model):
_inherit = "product.product"

tax_string = fields.Char(compute='_compute_tax_string')

def _get_product_accounts(self):
return self.product_tmpl_id._get_product_accounts()

Expand Down Expand Up @@ -156,3 +162,8 @@ def _get_tax_included_unit_price(self, company, currency, document_date, documen
product_price_unit = product_currency._convert(product_price_unit, currency, company, document_date)

return product_price_unit

@api.depends('lst_price', 'product_tmpl_id', 'taxes_id')
def _compute_tax_string(self):
for record in self:
record.tax_string = record.product_tmpl_id._construct_tax_string(record.lst_price)
3 changes: 2 additions & 1 deletion addons/product/views/product_views.xml
Original file line number Diff line number Diff line change
Expand Up @@ -365,9 +365,10 @@
</xpath>
<field name="list_price" position="attributes">
<attribute name="attrs">{'readonly': [('product_variant_count', '&gt;', 1)]}</attribute>
<attribute name="invisible">1</attribute>
</field>
<field name="list_price" position="after">
<field name="lst_price" invisible="1"/>
<field name="lst_price" class="oe_inline" widget='monetary' options="{'currency_field': 'currency_id', 'field_digits': True}"/>
</field>
<group name="packaging" position="attributes">
<attribute name="attrs">{'invisible': 0}</attribute>
Expand Down

0 comments on commit 46526f6

Please sign in to comment.