From 0cf43b7857b45455be2076b52c99f5fa84f1a70d Mon Sep 17 00:00:00 2001
From: "Ferdinand @ Camptocamp" <>
Date: Wed, 13 Apr 2011 13:02:11 +0530
Subject: [PATCH] [FIX] account: Improved invoice analysis report for
calculation of total without tax
lp bug: https://launchpad.net/bugs/748178 fixed
bzr revid: pso@tinyerp.com-20110413073211-nktkleb1izezr7o0
---
.../account/report/account_invoice_report.py | 59 +++++++++++--------
.../report/account_invoice_report_view.xml | 4 +-
2 files changed, 36 insertions(+), 27 deletions(-)
diff --git a/addons/account/report/account_invoice_report.py b/addons/account/report/account_invoice_report.py
index 9c7cf014e4d..4815b00ba25 100644
--- a/addons/account/report/account_invoice_report.py
+++ b/addons/account/report/account_invoice_report.py
@@ -69,6 +69,7 @@ class account_invoice_report(osv.osv):
'address_contact_id': fields.many2one('res.partner.address', 'Contact Address Name', readonly=True),
'address_invoice_id': fields.many2one('res.partner.address', 'Invoice Address Name', readonly=True),
'account_id': fields.many2one('account.account', 'Account',readonly=True),
+ 'account_line_id': fields.many2one('account.account', 'Account Line',readonly=True),
'partner_bank_id': fields.many2one('res.partner.bank', 'Bank Account',readonly=True),
'residual': fields.float('Total Residual', readonly=True),
'delay_to_pay': fields.float('Avg. Delay To Pay', readonly=True, group_operator="avg"),
@@ -106,44 +107,48 @@ class account_invoice_report(osv.osv):
ai.address_contact_id as address_contact_id,
ai.address_invoice_id as address_invoice_id,
ai.account_id as account_id,
+ ail.account_id as account_line_id,
ai.partner_bank_id as partner_bank_id,
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,
+
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
+ end) / (CASE WHEN
(select count(l.id) from account_invoice_line as l
left join account_invoice as a ON (a.id=l.invoice_id)
- where a.id=ai.id) <> 0
- THEN
+ where a.id=ai.id) <> 0
+ THEN
(select count(l.id) from account_invoice_line as l
left join account_invoice as a ON (a.id=l.invoice_id)
- where a.id=ai.id)
- ELSE 1
+ 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
- THEN
- (case when ai.type in ('out_refund','in_invoice')
- then sum(ail.quantity/u.factor*-1)
- else sum(ail.quantity/u.factor) end)
- ELSE 1
+ 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)
+ else sum(ail.quantity/u.factor) end)
+ ELSE 1
END)
/ cr.rate as price_average,
@@ -159,22 +164,23 @@ class account_invoice_report(osv.osv):
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
+ end)/ (CASE WHEN
(select count(l.id) from account_invoice_line as l
left join account_invoice as a ON (a.id=l.invoice_id)
- where a.id=ai.id) <> 0
+ where a.id=ai.id) <> 0
THEN
(select count(l.id) from account_invoice_line as l
left join account_invoice as a ON (a.id=l.invoice_id)
- where a.id=ai.id)
- ELSE 1
+ where a.id=ai.id)
+ ELSE 1
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)
+ 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)
@@ -202,6 +208,7 @@ class account_invoice_report(osv.osv):
ai.address_contact_id,
ai.address_invoice_id,
ai.account_id,
+ ail.account_id,
ai.partner_bank_id,
ai.residual,
ai.amount_total,
diff --git a/addons/account/report/account_invoice_report_view.xml b/addons/account/report/account_invoice_report_view.xml
index 6c1bc3f9762..a0a9729a775 100644
--- a/addons/account/report/account_invoice_report_view.xml
+++ b/addons/account/report/account_invoice_report_view.xml
@@ -27,10 +27,10 @@
+
-
@@ -103,6 +103,7 @@
+
@@ -120,6 +121,7 @@
+