Price set to 0 with price lists based on another one

Bug #319020 reported by Eduardo Ruiz
18
This bug affects 3 people
Affects Status Importance Assigned to Milestone
Odoo Addons (MOVED TO GITHUB)
Invalid
Undecided
Unassigned

Bug Description

version trunk.

Here an example how it fails calculating the price in sale order:

Pricelist_A > Rule_1: No filter for products. Computation based on another pricelist (B)
Pricelist_A > Rule_2: No filter for products. Computation = price list * 1.25
No more rules.

Pricelist_B > Rule_1: Filter for product = PC1. Computation = price list * 0 + 99
No more rules.

Products:
PC1: list price = 400€
PC2: list price = 500€

Sale Order:
Price List applied: Pricelist A
Sale order line with product PC1: unit price = 99€ > Ok, good !
Sale order line with product PC2: unit price = 0 € > Ko, not good ! The correct price is 625 €.

Revision history for this message
Fabien (Open ERP) (fp-tinyerp) wrote :

Your example works fine for me, exactly how you expected.
Check your pricelist computation.

Changed in openobject-addons:
status: New → Invalid
Revision history for this message
Eduardo Ruiz (readylan) wrote :

Actually, in code (addons/product/pricelist.py):

 def price_get(self, cr, uid, ids, prod_id, qty, partner=None, context=None):
     .......
            cr.execute(
                'SELECT i.*, pl.currency_id '
                'FROM product_pricelist_item AS i, '
                    'product_pricelist_version AS v, product_pricelist AS pl '
                'WHERE (product_tmpl_id IS NULL OR product_tmpl_id = %s) '
                    'AND (product_id IS NULL OR product_id = %s) '
                    'AND (' + categ_where + ' OR (categ_id IS NULL)) '
                    'AND price_version_id = %s '
                    'AND (min_quantity IS NULL OR min_quantity <= %s) '
                    'AND i.price_version_id = v.id AND v.pricelist_id = pl.id '
                'ORDER BY sequence LIMIT 1',
                (tmpl_id, prod_id, plversion['id'], qty))
            res = cr.dictfetchone()

            if res:
                if res['base'] == -1: ************************* when based on another pricelist
                    if not res['base_pricelist_id']:
                        price = 0.0
                    else:
                        price_tmp = self.price_get(cr, uid,
                                [res['base_pricelist_id']], prod_id,
                                qty, res['price_version_id'])[res['base_pricelist_id']]
                        ptype_src = self.browse(cr, uid,
                                res['base_pricelist_id']).currency_id.id
                        price = currency_obj.compute(cr, uid, ptype_src,
                                res['currency_id'], price_tmp, round=False)
    .............

            else:
                # False means no valid line found ! But we may not raise an
                # exception here because it breaks the search

**************** that's the problem. The first time the function founds a valid rule of "type -1", causing the function to call himself whith the new pricelist. In that second time it doesn't match and exits incorrectly, i think.
The valid line is not really valid because the "clild" list hasn't got a price for the product.
Can you help with this?

                price = False
            result[id] = price
    ............

Revision history for this message
Eduardo Ruiz (readylan) wrote :

sorry, the previous comments are incorrect. The exact point where i think it fails is :

192 price_tmp = self.price_get(cr, uid,
193 [res['base_pricelist_id']], prod_id,
194 qty)[res['base_pricelist_id']]

where it gets price_tmp = False

Revision history for this message
Eduardo Ruiz (readylan) wrote :

better i will stop talking .... I take back what I said in my previous comment. I need to study the code and find a solution.

Revision history for this message
Fabien (Open ERP) (fp-tinyerp) wrote : Re: [Bug 319020] Re: Price set to 0 with price lists based on another one

Sorry but I don't think there is a problem in pricelists.
Can you check your configuration and especially the sequene that decide
the order of applying the rules.

Eduardo Ruiz wrote:
> sorry, the previous comments are incorrect. The exact point where i
> think it fails is :
>
> 192 price_tmp = self.price_get(cr, uid,
> 193 [res['base_pricelist_id']], prod_id,
> 194 qty)[res['base_pricelist_id']]
>
> where it gets price_tmp = False
>

--
Fabien Pinckaers
CEO Tiny - OpenERP Editor
Chaussée de Namur 40
B-1367 Grand-Rosière
Belgium
Phone: +32.81.81.37.00
Fax: +32.81.73.35.01
Web: http://openerp.com

Great Achievements Start With Tiny Investments
   -- Marty, 2005

Revision history for this message
Eduardo Ruiz (readylan) wrote :

It will be better to do a try with the small example above to see what is happening.
There are not problem with the sequence. The one and only problem is that rules based on another pricelist "force" to have a matching rule por all products in this second pricelist., otherwise you get a "0", since this rule match (because there are not filter for products) but do not match (because secondary pricelist can not assign a price).

Y ahora en español, porque si no lo suelto, exploto:

El ejemplo inicial es muy simple y permite comprobar el problema rápidamente.

La finalidad del caso es conseguir una tarifa de ventas con "excepciones", las cuales estarían recogidas en una tarifa secundaria llamada, por ejemplo, ofertas.
En la tarifa de ofertas, solamente asignaremos precio a los productos que nos interese, por tanto no es una tarifa capaz de asignar precio a todos los productos (solamente a los que están en oferta). Tendrá por lo tanto 'n' reglas que definen el precio para 'n' productos.
Por otra parte, en la tarifa general de ventas, incluyo una primera regla (sequence=0) que no filtra los productos y que está basada en la tarifa de ofertas. Esto es para que el programa compruebe siempre si el producto está en oferta.

Ya en pedidos de venta, si el producto se encuentra en la tarifa de ofertas todo va bien, el problema se produce cuando el producto no se encuentra en esta tarifa. La funcion "price_get" considera que ya ha encontrado una regla de tarifa que puede poner precio al producto, sin embargo, al basarse esta regla en otra tarifa, esto puede no ser siempre así.
En lugar de poner precio 0, la función tendría que detectar la "no validez" de la regla basada en otra tarifa y seguir procesando reglas de la tarifa principal.

Revision history for this message
matrixx91 (matrixx91) wrote :

Hello Eduardo,

I agree with you, your first example are showing the real problem returning zero for the products that are not includes on the pricelist (B).

I will try your code to resolve my problem.

Are you still using this code, Eduardo?

Waiting your comments,

Marc

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.