[FIX] purchase: Purchase Analysis view was using incorrect JOIN order
authorOlivier Dony <odo@openerp.com>
Mon, 4 Nov 2013 16:58:26 +0000 (17:58 +0100)
committerOlivier Dony <odo@openerp.com>
Mon, 4 Nov 2013 16:58:26 +0000 (17:58 +0100)
The starting table for Purchase Analysis is purchase_order_line
not purchase_order. The previous code was using a wrong JOIN
combination starting from purchase_order, which resulted in
a crash if an empty PO was created.
In order to prevent this an extra  WHERE clause on product_id
being NOT NULL was added, but this was incorrect too as it
prevented PO lines with no product_id value from appearing
in the Purchase Analysis results, while being perfectly valid.

bzr revid: odo@openerp.com-20131104165826-kltuzlh4i8q89sk0

addons/purchase/report/purchase_report.py

index 1855ed1..c4c9c64 100644 (file)
@@ -96,16 +96,14 @@ class purchase_report(osv.osv):
                     count(*) as nbr,
                     (l.price_unit*l.product_qty)::decimal(16,2) as price_total,
                     avg(100.0 * (l.price_unit*l.product_qty) / NULLIF(t.standard_price*l.product_qty/u.factor*u2.factor, 0.0))::decimal(16,2) as negociation,
-
                     sum(t.standard_price*l.product_qty/u.factor*u2.factor)::decimal(16,2) as price_standard,
                     (sum(l.product_qty*l.price_unit)/NULLIF(sum(l.product_qty/u.factor*u2.factor),0.0))::decimal(16,2) as price_average
-                from purchase_order s
-                    left join purchase_order_line l on (s.id=l.order_id)
+                from purchase_order_line l
+                    join purchase_order s on (l.order_id=s.id)
                         left join product_product p on (l.product_id=p.id)
                             left join product_template t on (p.product_tmpl_id=t.id)
                     left join product_uom u on (u.id=l.product_uom)
                     left join product_uom u2 on (u2.id=t.uom_id)
-                where l.product_id is not null
                 group by
                     s.company_id,
                     s.create_uid,