=== modified file 'account/report/account_invoice_report.py' --- account/report/account_invoice_report.py 2011-01-25 14:18:33 +0000 +++ account/report/account_invoice_report.py 2011-04-02 10:46:18 +0000 @@ -107,18 +107,25 @@ ai.address_invoice_id as address_invoice_id, ai.account_id as account_id, ai.partner_bank_id as partner_bank_id, +-- FIXED avoid multiply -1 and use - sum(case when ai.type in ('out_refund','in_invoice') then - ail.quantity / u.factor * -1 + -ail.quantity / u.factor else ail.quantity / u.factor end) as product_qty, + +-- FIXED using price_subtotal respects discounts, which is relevant for net sum(case when ai.type in ('out_refund','in_invoice') then - ail.quantity*ail.price_unit * -1 + -ail.price_subtotal else - ail.quantity*ail.price_unit + ail.price_subtotal end) / cr.rate as price_total, + +-- +-- FIXME the line total incl tax can't be caculated by deviding the invoice total / number of lines +-- sum(case when ai.type in ('out_refund','in_invoice') then - ai.amount_total * -1 + -ai.amount_total else ai.amount_total end) / (CASE WHEN @@ -131,17 +138,15 @@ where a.id=ai.id) ELSE 1 END) / cr.rate as price_total_tax, + (case when ai.type in ('out_refund','in_invoice') then - sum(ail.quantity*ail.price_unit*-1) + sum(-ail.price_subtotal) else - sum(ail.quantity*ail.price_unit) - end) / (CASE WHEN - (case when ai.type in ('out_refund','in_invoice') - then sum(ail.quantity/u.factor*-1) - else sum(ail.quantity/u.factor) end) <> 0 + sum(ail.price_subtotal) + end) / (CASE WHEN sum(ail.quantity/u.factor) <> 0 THEN (case when ai.type in ('out_refund','in_invoice') - then sum(ail.quantity/u.factor*-1) + then sum(-ail.quantity/u.factor) else sum(ail.quantity/u.factor) end) ELSE 1 END) @@ -159,7 +164,7 @@ left join account_invoice_line as l ON (a.id=l.invoice_id) where a.id=ai.id)) as due_delay, (case when ai.type in ('out_refund','in_invoice') then - ai.residual * -1 + -ai.residual else ai.residual end)/ (CASE WHEN @@ -174,7 +179,9 @@ END) / cr.rate as residual from account_invoice_line as ail left join account_invoice as ai ON (ai.id=ail.invoice_id) - left join product_template pt on (pt.id=ail.product_id) +-- FIXED wrong join + left join product_product pr on (pr.id=ail.product_id) + left join product_template pt on (pt.id=pr.product_tmpl_id) left join product_uom u on (u.id=ail.uos_id), res_currency_rate cr where cr.id in (select id from res_currency_rate cr2 where (cr2.currency_id = ai.currency_id)