[IMP] Sales team on invoices

bzr revid: fp@tinyerp.com-20121126083331-43pm5qo3snv7ie19
This commit is contained in:
Fabien Pinckaers
2012-11-26 09:33:31 +01:00
8 changed files with 198 additions and 12 deletions
+33 -11
View File
@@ -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()
+1
View File
@@ -21,5 +21,6 @@
import wizard
import sale_crm
import report
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
+2 -1
View File
@@ -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'],
+25
View File
@@ -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:
@@ -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>
@@ -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:
+15
View File
@@ -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:
+67
View File
@@ -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>