Contributors mailing list archives

contributors@odoo-community.org

Browse archives

Avatar

Fwd: Pricelist based on max purchase cost

by
Francesco Ballerini
- 29/01/2023 19:29:15

Good morning OCA Contributors, 

I was doing some analysis on models 'product.pricelist', 'product.pricelist.item', 'product.supplierinfo' (never checked those models before) and product.product and I'd like to add some technical info to my previous message. 

This message doesn't really add many functional infos to the previous message, it's more a technical example to explain from code point of view what I would like to achieve, hoping it helps either to give better indications to find what I'm looking for or, in the worst case, I hope I can have some feedback for developing a 'decent looking' solution.

Before joining the 'funny part' I would like to correct myself since I realized that "standard_price" field is not related to seller_ids.
That doesn't change much in the general sense since I probably need a loop/search on "price" field of model "product.supplierinfo" to retrieve the higher seller price and use it in the pricelist formula (TLTR) but it wasn't very accurate.

That said, if I only speak from my perspective/needs, so in a 'vertical' way of thinking, I probably need something that, before calling the _compute_price method in model 'product.pricelist.item' will check the seller_ids (or a stored value for the max seller id price) and takes max seller id price value instead of "standard_price" (or "list_price"), so the formula:

"price = (price - (price * (self.price_discount / 100))) or 0.0"  -- where price is taken as " standard_price" in product.product model

will become 

"price = (price - (max_seller_price* (self.price_discount / 100))) or 0.0"

Side note: This will also require an additional key in field "base" to setup a different workflow for pricelist based on formula → seller prices

If calculated 'on the fly' it can is almost surely bad in terms of performance so I think it's better to store the maximum seller price somewhere in the product record, I'm not sure about the right moment to calculate and store the value though, maybe when a new purchase is performed, but still have to think about this detail.
This way, the max seller price can be passed in the function  _compute_price and there should not be performance issues on the sale order.

To achieve this a new field should be added to product.template model, so I can store the value and pass to the formula if the conditions are met.

Is this feature somehow achievable, or maybe there is even a better way to achieve it? If not or partially achieved, I could also consider some more extensible variants if the community is interested to this feature:

Variant 1

1) Add 3 field to product.template model: "seller_cost_max", "seller_cost_min", "seller_cost_average" and compute the values (still not sure when)

2) add a Selection field to model 'product.pricelist.item' to choose if you want to apply 

- apply standard_price
- apply seller_cost_max
- apply seller_cost_min
- apply seller_cost_average

To the formula 
"price = (price - (chosen_value* (self.price_discount / 100))) or 0.0"

Variant 2 (save some DB columns)

1) Store only 1 value between max/min/average cost in a new field, "seller_price_computed", you can decide which calculation method to use thanks to a select field in res.config.settings.

2) Add a flag to 'product.pricelist.item' to choose if you want to apply the 'standard_price' or "seller_price_computed" to the formula.

I added this last part in case you like the idea and this feature is not or partially implemented, please for now just consider it as an idea on the table. I'm also pretty confident that that this feature, or part of it is already implemented in odoo14, so I'll wait for your feedback!

Cheers,
Francesco Ballerini



---------- Forwarded message ---------
Da: Francesco Ballerini <francescobl.lavoro@gmail.com>
Date: sab 28 gen 2023 alle ore 20:09
Subject: Pricelist based on max purchase cost
To: contributors@odoo-community.org <contributors@odoo-community.org>


Hello OCA contributors, I am looking at pricelist in Odoo14. Firstly I have checked in the brand repository https://github.com/OCA/brand/tree/14.0 and found an awsome PR that integrates brand with product pricelist. Thanks for the awsome work you make for Odoo. About the brand I’d like to know if there is something that allows to filter products by brand in website as well.

 

But mostly I’d like to ask for a feature that I did not find in Odoo14. Basically we need a pricelist that apply a % discount  based on the maximum purchase price.

 

The closest thing I manage to reach is to apply a pricelist based on formula that applies % discount based on product cost but we need much more than this. I did not found any repository for pricelists, so I’d like to ask if there is something module or way to achieve this feature, or what do you advice to achieve it.

 

Thank you very much,

 

Francesco Ballerini

 

 

 

Inviato da Posta per Windows

 


Privo di virus.www.avast.com

Reference