From 0a97c08aedcec44ba43eef43336409b95a0af530 Mon Sep 17 00:00:00 2001 From: "rha@tinyerp.com" <> Date: Thu, 23 Dec 2010 15:07:00 +0530 Subject: [PATCH] [Fix]: Bug #692698 purchase analysis - division by zero bzr revid: rha@tinyerp.com-20101223093700-53cspuk8klp27h8q --- addons/purchase/report/purchase_report.py | 7 ++----- addons/sale/report/sale_report.py | 3 ++- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/addons/purchase/report/purchase_report.py b/addons/purchase/report/purchase_report.py index cd197222eaa..502aec06801 100644 --- a/addons/purchase/report/purchase_report.py +++ b/addons/purchase/report/purchase_report.py @@ -99,12 +99,9 @@ class purchase_report(osv.osv): extract(epoch from age(l.date_planned,s.date_order))/(24*60*60)::decimal(16,2) as delay_pass, count(*) as nbr, (l.price_unit*l.product_qty*u.factor)::decimal(16,2) as price_total, - avg(case when t.standard_price <= 0 then (l.price_unit*l.product_qty*u.factor) - else - (100.0 * (l.price_unit*l.product_qty*u.factor) / (t.standard_price*l.product_qty*u.factor)) - end) as negociation, + avg(100.0 * (l.price_unit*l.product_qty*u.factor)/(nullif(t.standard_price*l.product_qty*u.factor,0)))::decimal(16,2) as negociation, sum(t.standard_price*l.product_qty*u.factor)::decimal(16,2) as price_standard, - (sum(l.product_qty*l.price_unit)/sum(l.product_qty*u.factor))::decimal(16,2) as price_average + (sum(l.product_qty*l.price_unit)/sum(nullif(l.product_qty*u.factor,0)))::decimal(16,2) as price_average from purchase_order s left join purchase_order_line l on (s.id=l.order_id) left join product_product p on (l.product_id=p.id) diff --git a/addons/sale/report/sale_report.py b/addons/sale/report/sale_report.py index 75c37ff9416..ae4edbb1f9d 100644 --- a/addons/sale/report/sale_report.py +++ b/addons/sale/report/sale_report.py @@ -94,7 +94,8 @@ class sale_report(osv.osv): u.name as uom_name, sum(l.product_uom_qty * u.factor) as product_uom_qty, sum(l.product_uom_qty*l.price_unit) as price_total, - (sum(l.product_uom_qty*l.price_unit)/sum(l.product_uom_qty * u.factor)*count(l.product_id))::decimal(16,2) as price_average, + (sum(l.product_uom_qty*l.price_unit)/sum(nullif(l.product_uom_qty * u.factor,0))*count(l.product_id))::decimal(16,2) as price_average, + pt.categ_id, l.order_id from sale_order_line l