summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFabien Pinckaers <fp@tinyerp.com>2012-11-26 09:33:31 +0100
committerFabien Pinckaers <fp@tinyerp.com>2012-11-26 09:33:31 +0100
commitb28d6f1e7da58bc3ce2d3ad730e1d3183dd84cf8 (patch)
tree9fabc417243bfb6a5e0200bcc21bef72efd0391c
parentd9936eda84a8effa293791df8ae305a6bde71c3d (diff)
parent852e87f32f0643ecaddfed15c46aff527cd9187b (diff)
[IMP] Sales team on invoices
bzr revid: fp@tinyerp.com-20121126083331-43pm5qo3snv7ie19
-rw-r--r--addons/account/report/account_invoice_report.py44
-rw-r--r--addons/sale_crm/__init__.py1
-rw-r--r--addons/sale_crm/__openerp__.py3
-rw-r--r--addons/sale_crm/report/__init__.py25
-rw-r--r--addons/sale_crm/report/sale_crm_account_invoice_report_view.xml20
-rw-r--r--addons/sale_crm/report/sales_crm_account_invoice_report.py35
-rw-r--r--addons/sale_crm/sale_crm.py15
-rw-r--r--addons/sale_crm/sale_crm_view.xml67
8 files changed, 198 insertions, 12 deletions
diff --git a/addons/account/report/account_invoice_report.py b/addons/account/report/account_invoice_report.py
index fa2d071695b..68eaedb20a6 100644
--- a/addons/account/report/account_invoice_report.py
+++ b/addons/account/report/account_invoice_report.py
@@ -102,11 +102,11 @@ class account_invoice_report(osv.osv):
'due_delay': fields.float('Avg. Due Delay', readonly=True, group_operator="avg"),
}
_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,
@@ -183,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,
@@ -218,8 +233,15 @@ class account_invoice_report(osv.osv):
ai.amount_total,
u.uom_type,
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/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 (<http://tiny.be>).
+#
+# 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 <http://www.gnu.org/licenses/>.
+#
+##############################################################################
+
+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 @@
+<?xml version="1.0" encoding="utf-8"?>
+<openerp>
+<data>
+
+ <!-- Update account invoice !-->
+ <record model="ir.ui.view" id="account_invoice_report_tree">
+ <field name="name">account.invoice.report.tree</field>
+ <field name="model">account.invoice.report</field>
+ <field name="inherit_id" ref="account.view_account_invoice_report_tree"/>
+ <field name="arch" type="xml">
+ <data>
+ <xpath expr="//field[@name='date']" position="after">
+ <field name="section_id"/>
+ </xpath>
+ </data>
+ </field>
+ </record>
+
+</data>
+</openerp>
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 (<http://tiny.be>).
+#
+# 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 <http://www.gnu.org/licenses/>.
+#
+##############################################################################
+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:
diff --git a/addons/sale_crm/sale_crm.py b/addons/sale_crm/sale_crm.py
index 80e9f3b4f42..3bca4053194 100644
--- a/addons/sale_crm/sale_crm.py
+++ b/addons/sale_crm/sale_crm.py
@@ -46,4 +46,19 @@ class sale_order(osv.osv):
sale_order()
+class res_users(osv.Model):
+ _inherit = 'res.users'
+ _columns = {
+ 'default_section_id': fields.many2one('crm.case.section', 'Default Sales Team'),
+ }
+
+class account_invoice(osv.osv):
+ _inherit = 'account.invoice'
+ _columns = {
+ 'section_id': fields.many2one('crm.case.section', 'Sales Team'),
+ }
+ _defaults = {
+ 'section_id': lambda self,cr,uid,c: self.pool.get('res.users').browse(cr, uid, uid, c).default_section_id.id or False,
+ }
+
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
diff --git a/addons/sale_crm/sale_crm_view.xml b/addons/sale_crm/sale_crm_view.xml
index 665474c22c0..0b5fce2f5cd 100644
--- a/addons/sale_crm/sale_crm_view.xml
+++ b/addons/sale_crm/sale_crm_view.xml
@@ -46,5 +46,72 @@
</field>
</record>
+ <!-- Update account invoice list view!-->
+ <record model="ir.ui.view" id="account_invoice_tree">
+ <field name="name">Account Invoice</field>
+ <field name="model">account.invoice</field>
+ <field name="inherit_id" ref="account.invoice_tree"/>
+ <field name="arch" type="xml">
+ <data>
+ <xpath expr="//field[@name='date_invoice']" position="after">
+ <field name="section_id" invisible="1"/>
+ </xpath>
+ </data>
+ </field>
+ </record>
+
+ <record id="account_invoice_groupby_inherit" model="ir.ui.view">
+ <field name="name">account.invoice.groupby</field>
+ <field name="model">account.invoice</field>
+ <field name="inherit_id" ref="account.view_account_invoice_filter"/>
+ <field name="arch" type="xml">
+ <xpath expr="//group/filter[@string='Due Date']" position="after">
+ <filter string="Sales Team" domain="[]" context="{'group_by':'section_id'}"/>
+ </xpath>
+ </field>
+ </record>
+
+ <!-- Update account invoice !-->
+ <record model="ir.ui.view" id="account_invoice_form">
+ <field name="name">Account Invoice</field>
+ <field name="model">account.invoice</field>
+ <field name="inherit_id" ref="account.invoice_form"/>
+ <field name="arch" type="xml">
+ <data>
+ <xpath expr="//field[@name='user_id']" position="after">
+ <field name="section_id"/>
+ </xpath>
+ </data>
+ </field>
+ </record>
+
+ <!-- Update user form !-->
+ <record model="ir.ui.view" id="res_user_form">
+ <field name="name">Users Preferences</field>
+ <field name="model">res.users</field>
+ <field name="inherit_id" ref="base.view_users_form"/>
+ <field name="arch" type="xml">
+ <data>
+ <xpath expr="//field[@name='email']" position="after">
+ <field name="default_section_id"/>
+ </xpath>
+ </data>
+ </field>
+ </record>
+
+ <!-- Update Preferences form !-->
+ <record id="view_users_form_preferences" model="ir.ui.view">
+ <field name="name">res.users.preferences.form</field>
+ <field name="model">res.users</field>
+ <field name="inherit_id" ref="base.view_users_form_simple_modif"/>
+ <field name="arch" type="xml">
+ <data>
+ <xpath expr="//field[@name='company_id']" position="after">
+ <field name="default_section_id"/>
+ </xpath>
+ </data>
+ </field>
+ </record>
+
</data>
</openerp>