İçereği Atla
Menü
Bu soru işaretlendi
1 Cevapla
142 Görünümler

Follow-up on this post: https://www.odoo.com/nl_NL/forum/help-1/product-view-show-price-of-a-specific-pricelist-287616

I now have the following code:

for record in self:

    pricelist = self.env['product.pricelist'].search([('name', '=', 'Horeca')], limit=1)

    product_variant = record.product_variant_id

    record["x_studio_horeca_price"] = pricelist._get_product_price(product_variant, 1.0) if pricelist and product_variant else 0.0

This works great in the product view, but if I have 2 variants, only the base variant has the correct price. With the second variant, where I add a certain amount, the pricelist price is calculated on the original price, not the variant sale price. 

Any ideas on how to solve this? Should I create a separate field for the variants or can I adapt the existing code ?

Avatar
Vazgeç
En İyi Yanıt

Hi,


The issue arises because the current code calculates prices based on the product template’s base price, not the specific variant’s adjusted price. In Odoo, only the first variant works correctly since product_variant_id it defaults to one variant, and _get_product_price doesn’t automatically include variant extras unless it’s run on the variant itself. To fix this, the computation should be done on the product.product (variant) instead of the template. Ideally, the custom field should be defined on product.product, so each variant has its own Horeca price from the pricelist. If kept on the template, only one price will display, making it better to move the field to variants for accuracy.


Try the following code,


for record in self:

    pricelist = self.env['product.pricelist'].search([('name', '=', 'Horeca')], limit=1)


    product_variant = record if record._name == 'product.product' else record.product_variant_id


    if pricelist and product_variant:

        record["x_studio_horeca_price"] = pricelist._get_product_price(product_variant, 1.0)

    else:

        record["x_studio_horeca_price"] = 0.0


Hope it helps

Avatar
Vazgeç
İlgili Gönderiler Cevaplar Görünümler Aktivite
1
Eki 25
168
Tiered discounts Çözüldü
1
Nis 25
1563
1
Kas 24
1803
1
Eki 24
2090
2
Eki 24
3430