diff --git a/addons/account/report/account_invoice_report.py b/addons/account/report/account_invoice_report.py
index e6202e7394f..68eaedb20a6 100644
--- a/addons/account/report/account_invoice_report.py
+++ b/addons/account/report/account_invoice_report.py
@@ -100,14 +100,13 @@ class account_invoice_report(osv.osv):
'user_currency_residual': fields.function(_compute_amounts_in_user_currency, string="Total Residual", type='float', digits_compute=dp.get_precision('Account'), multi="_compute_amounts"),
'delay_to_pay': fields.float('Avg. Delay To Pay', readonly=True, group_operator="avg"),
'due_delay': fields.float('Avg. Due Delay', readonly=True, group_operator="avg"),
- 'section_id': fields.many2one('crm.case.section', 'Sales Team'),
}
_order = 'date desc'
- def init(self, cr):
- tools.drop_view_if_exists(cr, 'account_invoice_report')
- cr.execute("""
- create or replace view account_invoice_report as (
- select min(ail.id) as id,
+
+
+ def _select(self):
+ select_str = """
+ SELECT min(ail.id) as id,
ai.date_invoice as date,
to_char(ai.date_invoice, 'YYYY') as year,
to_char(ai.date_invoice, 'MM') as month,
@@ -125,7 +124,6 @@ class account_invoice_report(osv.osv):
ai.journal_id as journal_id,
ai.fiscal_position as fiscal_position,
ai.user_id as user_id,
- ai.section_id as section_id,
ai.company_id as company_id,
count(ail.*) as nbr,
ai.type as type,
@@ -185,15 +183,30 @@ class account_invoice_report(osv.osv):
where a.id=ai.id)
ELSE 1
END) / cr.rate as residual
- from account_invoice_line as ail
+ """
+ return select_str
+
+ def _where(self):
+ where_str = """
+ WHERE cr.id in (select id from res_currency_rate cr2 where (cr2.currency_id = ai.currency_id)
+ and ((ai.date_invoice is not null and cr.name <= ai.date_invoice) or (ai.date_invoice is null and cr.name <= NOW())) order by name desc limit 1)
+ """
+ return where_str
+
+ def _from(self):
+ from_str = """
+ FROM account_invoice_line as ail
left join account_invoice as ai ON (ai.id=ail.invoice_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)
- and ((ai.date_invoice is not null and cr.name <= ai.date_invoice) or (ai.date_invoice is null and cr.name <= NOW())) order by name desc limit 1)
- group by ail.product_id,
+ """
+ return from_str
+
+ def _group_by(self):
+ group_by_str = """
+ GROUP BY ail.product_id,
ai.date_invoice,
ai.id,
cr.rate,
@@ -219,10 +232,16 @@ class account_invoice_report(osv.osv):
ai.residual,
ai.amount_total,
u.uom_type,
- u.category_id,
- ai.section_id
- )
- """)
+ u.category_id
+ """
+ return group_by_str
+
+ def init(self, cr):
+ # self._table = account_invoice_report
+ tools.drop_view_if_exists(cr, self._table)
+ cr.execute("CREATE or REPLACE VIEW %s as (%s %s %s %s)" % (
+ self._table,
+ self._select(), self._from(), self._where(), self._group_by()))
account_invoice_report()
diff --git a/addons/account/report/account_invoice_report_view.xml b/addons/account/report/account_invoice_report_view.xml
index 6d37e867390..289db376e5d 100644
--- a/addons/account/report/account_invoice_report_view.xml
+++ b/addons/account/report/account_invoice_report_view.xml
@@ -27,7 +27,6 @@
-
@@ -66,7 +65,6 @@
-
@@ -83,7 +81,6 @@
-
diff --git a/addons/sale_crm/__init__.py b/addons/sale_crm/__init__.py
index ac44586e7db..cda0cd795a2 100644
--- a/addons/sale_crm/__init__.py
+++ b/addons/sale_crm/__init__.py
@@ -21,5 +21,6 @@
import wizard
import sale_crm
+import report
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
diff --git a/addons/sale_crm/__openerp__.py b/addons/sale_crm/__openerp__.py
index 82e267337f9..4ef6b6059f2 100644
--- a/addons/sale_crm/__openerp__.py
+++ b/addons/sale_crm/__openerp__.py
@@ -43,7 +43,8 @@ modules.
'sale_crm_view.xml',
'process/sale_crm_process.xml',
'security/sale_crm_security.xml',
- 'security/ir.model.access.csv'
+ 'security/ir.model.access.csv',
+ 'report/sale_crm_account_invoice_report_view.xml',
],
'demo': [],
'test': ['test/sale_crm.yml'],
diff --git a/addons/sale_crm/report/__init__.py b/addons/sale_crm/report/__init__.py
new file mode 100644
index 00000000000..d7c6d373468
--- /dev/null
+++ b/addons/sale_crm/report/__init__.py
@@ -0,0 +1,25 @@
+# -*- coding: utf-8 -*-
+##############################################################################
+#
+# OpenERP, Open Source Management Solution
+# Copyright (C) 2004-2010 Tiny SPRL ().
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as
+# published by the Free Software Foundation, either version 3 of the
+# License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Affero General Public License for more details.
+#
+# You should have received a copy of the GNU Affero General Public License
+# along with this program. If not, see .
+#
+##############################################################################
+
+import sales_crm_account_invoice_report
+
+# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
+
diff --git a/addons/sale_crm/report/sale_crm_account_invoice_report_view.xml b/addons/sale_crm/report/sale_crm_account_invoice_report_view.xml
new file mode 100644
index 00000000000..41166d56713
--- /dev/null
+++ b/addons/sale_crm/report/sale_crm_account_invoice_report_view.xml
@@ -0,0 +1,20 @@
+
+
+
+
+
+
+ account.invoice.report.tree
+ account.invoice.report
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/addons/sale_crm/report/sales_crm_account_invoice_report.py b/addons/sale_crm/report/sales_crm_account_invoice_report.py
new file mode 100644
index 00000000000..8e356527536
--- /dev/null
+++ b/addons/sale_crm/report/sales_crm_account_invoice_report.py
@@ -0,0 +1,35 @@
+# -*- coding: utf-8 -*-
+##############################################################################
+#
+# OpenERP, Open Source Management Solution
+# Copyright (C) 2004-2010 Tiny SPRL ().
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as
+# published by the Free Software Foundation, either version 3 of the
+# License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Affero General Public License for more details.
+#
+# You should have received a copy of the GNU Affero General Public License
+# along with this program. If not, see .
+#
+##############################################################################
+from osv import fields,osv
+
+class account_invoice_report(osv.osv):
+ _inherit = 'account.invoice.report'
+ _columns = {
+ 'section_id': fields.many2one('crm.case.section', 'Sales Team'),
+ }
+
+ def _select(self):
+ return super(account_invoice_report, self)._select() + ", ai.section_id as section_id"
+
+ def _group_by(self):
+ return super(account_invoice_report, self)._group_by() + ", ai.section_id"
+
+# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: