From 889d4d7ebc72e5f61a07615f1a4796e524e15d7e Mon Sep 17 00:00:00 2001
From: "rch (Open ERP)" <>
Date: Thu, 29 Apr 2010 17:16:49 +0530
Subject: [PATCH] [IMP]: Improve SQL report for Invoice by adding sum Residual
and Delay To Pay fields.
bzr revid: rch_open_erp-20100429114649-o46vjjrf11y4ulyx
---
addons/account/report/account_invoice_report.py | 15 ++++++++++++---
.../report/account_invoice_report_view.xml | 2 ++
2 files changed, 14 insertions(+), 3 deletions(-)
diff --git a/addons/account/report/account_invoice_report.py b/addons/account/report/account_invoice_report.py
index 5aff8f34f89..af8ef08e353 100644
--- a/addons/account/report/account_invoice_report.py
+++ b/addons/account/report/account_invoice_report.py
@@ -65,7 +65,9 @@ class account_invoice_report(osv.osv):
'address_contact_id': fields.many2one('res.partner.address', 'Contact Address', readonly=True),
'address_invoice_id': fields.many2one('res.partner.address', 'Invoice Address', readonly=True),
'account_id': fields.many2one('account.account', 'Account',readonly=True),
- 'partner_bank': fields.many2one('res.partner.bank', 'Bank Account',readonly=True)
+ 'partner_bank': 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"),
}
_order = 'date desc'
def init(self, cr):
@@ -97,12 +99,19 @@ class account_invoice_report(osv.osv):
s.address_contact_id as address_contact_id,
s.address_invoice_id as address_invoice_id,
s.account_id as account_id,
- s.partner_bank as partner_bank
+ s.partner_bank as partner_bank,
+ sum(s.residual) as residual,
+ case when s.state != 'paid' then null else
+ extract(epoch from avg(am.date_created-l.create_date))/(24*60*60)::decimal(16,2)
+ end as delay_to_pay
from
account_invoice_line l
left join
account_invoice s on (s.id=l.invoice_id)
- left join product_uom u on (u.id=l.uos_id)
+ left join product_uom u on (u.id=l.uos_id),
+ account_move_line am left join account_invoice i on (i.move_id=am.move_id)
+ where
+ am.account_id=i.account_id
group by
s.type,
s.date_invoice,
diff --git a/addons/account/report/account_invoice_report_view.xml b/addons/account/report/account_invoice_report_view.xml
index 4764e0a5942..fea7dbadd93 100644
--- a/addons/account/report/account_invoice_report_view.xml
+++ b/addons/account/report/account_invoice_report_view.xml
@@ -32,6 +32,8 @@
+
+