Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIX] product: variant sale price is wrong #87248

Closed

Conversation

momegahed
Copy link
Contributor

@momegahed momegahed commented Mar 25, 2022

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

@robodoo
Copy link
Contributor

robodoo commented Mar 25, 2022

Pull request status dashboard

@C3POdoo C3POdoo added the OE the report is linked to a support ticket (opw-...) label Mar 25, 2022
@momegahed momegahed force-pushed the 15.0-product-OPW-2774199-fix-mome branch 5 times, most recently from 5853016 to b01d367 Compare March 30, 2022 14:49
Copy link
Contributor

@adwid adwid left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Considering how lst_price is computed (= list_price + extra_prices) + the fact that lst_price is the one used on the tree view of product.product:

<field name="lst_price" optional="show" string="Sales Price"/>

Your changes in the XML file seem legit

However, I don't understand why there is an issue with the computation of tax_string ? Note that the addition of non-stored fields should be avoided as much as possible. Also, the implementation of product_product._compute_tax_string is strange. product.product is a child of product.template, so the method overrides the original one while its body calls the original one

Also, could you be more precise in the steps-to-reproduce ? I'm not sure it is that clear that the user has to set an extra-price on a specific variant attribute (I have had to read the ticket again 😇)

@momegahed
Copy link
Contributor Author

Considering how lst_price is computed (= list_price + extra_prices) + the fact that lst_price is the one used on the tree view of product.product:

<field name="lst_price" optional="show" string="Sales Price"/>

Your changes in the XML file seem legit
However, I don't understand why there is an issue with the computation of tax_string ? Note that the addition of non-stored fields should be avoided as much as possible. Also, the implementation of product_product._compute_tax_string is strange. product.product is a child of product.template, so the method overrides the original one while its body calls the original one

Also, could you be more precise in the steps-to-reproduce ? I'm not sure it is that clear that the user has to set an extra-price on a specific variant attribute (I have had to read the ticket again 😇)

the inheritance between product.product and product.template is delegation inheritance not traditional inheritance

thus the method override wouldn't work

okay to the second point

@adwid
Copy link
Contributor

adwid commented Apr 1, 2022

My bad for the inheritance
I am still not convinced by the changes, I didn't find a use of tax_string anywhere but on a form of a product template:

<span class="ml-2"/><field name="tax_string"/>

but maybe I'm missing something ?
@agr-odoo Could you check this ?

@momegahed
Copy link
Contributor Author

My bad for the inheritance I am still not convinced by the changes, I didn't find a use of tax_string anywhere but on a form of a product template:

<span class="ml-2"/><field name="tax_string"/>

but maybe I'm missing something ?
@agr-odoo Could you check this ?

product.product form view interits from product.template and the same field is needed there albeit it needs correction in the calculation thus the need for the changes

@momegahed momegahed requested a review from adwid April 1, 2022 13:18
Copy link
Contributor

@agr-odoo agr-odoo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm ok with the idea. This needs to be fixed as price and tax string of the variant product shows the template product data

On the actual implementation it would be better to have also the opinion of @Feyensv

addons/product/views/product_views.xml Show resolved Hide resolved
addons/account/models/product.py Show resolved Hide resolved
@Feyensv
Copy link
Contributor

Feyensv commented Apr 4, 2022

I also don't understand the need of the tax_string code and I don't see any mention of it in the source ticket.
If nobody needs it, don't add it, it's not like something is wrong without the tax explanation (furthermore, existing database won't have the change anyway).

For the lst_price change, could you investigate why it works fine in previous versions, and maybe link the commit/PR that caused the problem ? (probably #75862 but I cannot say for sure)

@agr-odoo
Copy link
Contributor

agr-odoo commented Apr 4, 2022

I also don't understand the need of the tax_string code and I don't see any mention of it in the source ticket. If nobody needs it, don't add it, it's not like something is wrong without the tax explanation (furthermore, existing database won't have the change anyway).

The tax explanation needs to be fixed (or hidden) as it uses the values of the template product
Example:
Template product have a sales price 750.00 with 15% tax not included in price
-> tax string in template product is "(= $ 862.50 Incl. Taxes)"
Variant product add +50.00
-> tax string in variant prod before patch is the same "(= $ 862.50 Incl. Taxes)" (see screenshot)
-> tax string in variant prod after patch is "(= $ 920.00 Incl. Taxes)"
screenshot_005

@Feyensv
Copy link
Contributor

Feyensv commented Apr 4, 2022

Okay, makes sense now, but there really should be some explanation about it in the PR/commit, which isn't the case currently ...

@momegahed momegahed force-pushed the 15.0-product-OPW-2774199-fix-mome branch 2 times, most recently from e8d78f6 to f141a15 Compare April 4, 2022 10:46
addons/product/views/product_views.xml Show resolved Hide resolved
addons/account/models/product.py Outdated Show resolved Hide resolved
addons/account/models/product.py Show resolved Hide resolved
@momegahed momegahed force-pushed the 15.0-product-OPW-2774199-fix-mome branch 2 times, most recently from c136cb0 to a167afd Compare April 4, 2022 14:27
Copy link
Contributor

@william-andre william-andre left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please mark the PR as ready so that I can approve it when you are finished with the last changes :)


def _compute_tax_string(self):
for record in self:
record.tax_string = record.product_tmpl_id._construct_tax_string(record, record.lst_price)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This tracebacks, and it is missing dependencies

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please mark the PR as ready so that I can approve it when you are finished with the last changes :)

well, my fear is that because now _construct_tax_string is an instance method and the inheritance is delegation (so polymorphism won't work), it will be very confusing later when extending this. for now it is not an issue because the only attribute used to calculate the tax string is the price but imagine wanting to add other variables that might differ between product.product and product.template.

tl;dr
self in _construct_tax_string is always product_tmpl_id regardless of where it was called from

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also why the style check fails with C0305, I added one line at the end

You have 2 end of line char instead of one, leading in one blank/useless line

self in _construct_tax_string is always product_tmpl_id regardless of where it was called from

How is that answering any of my remarks?
And why is that an issue?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did fix the errors, I don't know what dependencies it misses.

this was another point.

the issue is that the intuitive behavior when someone sees this implementation will be that this is a normal case of polymorphism and can thus be extended further which is not the case

@momegahed momegahed force-pushed the 15.0-product-OPW-2774199-fix-mome branch from a167afd to b1dbb41 Compare April 5, 2022 07:56
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
@momegahed momegahed force-pushed the 15.0-product-OPW-2774199-fix-mome branch from b1dbb41 to 0503be2 Compare April 6, 2022 10:56
@momegahed momegahed marked this pull request as ready for review April 6, 2022 11:04
@C3POdoo C3POdoo requested a review from a team April 6, 2022 11:06
Copy link
Contributor

@william-andre william-andre left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
OE the report is linked to a support ticket (opw-...)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants