margin-analysis icon indicating copy to clipboard operation
margin-analysis copied to clipboard

[16] product_margin_classification changes template list_price instead of variant_extra_price

Open FreezeS opened this issue 11 months ago • 2 comments

Hi guys,

In the current implementation, product_margin_classification is completely unusable for products with variants that have different costs. Changing the sale price of a variant will change the sale price of all the other variants.

How to reproduce in runboat:

  • create a new attribute "Pins", radio, dynamically. Add 3 values: 5,10,15

  • create a new product "Test1", at Attributes and Variants select Pins, add all 3 values

  • make a new sales order, select product Test1, when popup appears, select Pins - 5. Repeat to create all 3 variants.

  • go to the Test1 template, set list_price 50$.

  • click on 3 Variants, edit each and set cost the same as pins value. After it should look like this: Image

  • go to margin classifications, create a 33% margin like this:

Image

  • go to Inventory - Products - Product variants, select Test1 with Pins: 5 and set the margin classification

Image

  • click on Decrease price

What I expected to happen:

  • variant_extra_price to be set at -42.5 resulting in a sales price of 7.5 for the variant and the sale price of the other variants to remain unchanged

What happens:

  • list_price of the template Test1 is set to 7.5 affecting the sales price of all the other variants

Image

  • now if I go to another variant, select the same classification and set the price:

Image This changed the price for the 5 pin version as well:

Image

Proposed fix

def use_theoretical_price(self):
        for product in self:
            product.lst_price = product.theoretical_price

should be

def use_theoretical_price(self):
        for product in self:
            product.variant_extra_price = product.theoretical_price - product.list_price

From my very limited experience, lst_price should not be edited directly as it affects the template list_price. Every modification of a variant's price should be via variant_extra_price. Can anyone with more experience chime in?

FreezeS avatar Jan 23 '25 16:01 FreezeS

There hasn't been any activity on this issue in the past 6 months, so it has been marked as stale and it will be closed automatically if no further activity occurs in the next 30 days. If you want this issue to never become stale, please ask a PSC member to apply the "no stale" label.

github-actions[bot] avatar Jul 27 '25 12:07 github-actions[bot]

Could you provide a patch, with according new tests ?

thanks !

legalsylvain avatar Jul 28 '25 07:07 legalsylvain