From 76376ed19c5caf0a755a3af775174bbe691082d2 Mon Sep 17 00:00:00 2001 From: Vijaykumar Baladaniya Date: Tue, 20 Nov 2012 19:09:40 +0530 Subject: [PATCH 01/10] [IMP] Improve sales team invoice. bzr revid: vba@tinyerp.com-20121120133940-dnu83uuxqkqg1tto --- addons/sale_crm/sale_crm.py | 33 ++++++++++++++++++++++++ addons/sale_crm/sale_crm_view.xml | 42 +++++++++++++++++++++++++++++++ 2 files changed, 75 insertions(+) diff --git a/addons/sale_crm/sale_crm.py b/addons/sale_crm/sale_crm.py index 80e9f3b4f42..4b646c7b871 100644 --- a/addons/sale_crm/sale_crm.py +++ b/addons/sale_crm/sale_crm.py @@ -46,4 +46,37 @@ class sale_order(osv.osv): sale_order() + +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, + } + + def create(self, cr, uid, vals, context=None): + section_id = vals.get('section_id', False) + invoice_type = context.get('type', False) + user_id = vals.get('user_id', False) + if not section_id and invoice_type in ['out_invoice', 'out_refund'] and user_id: + vals['section_id'] = user_id + obj_id = super(account_invoice, self).create(cr, uid, vals, context=context) + return obj_id + +account_invoice() + + +class res_users(osv.Model): + _inherit = 'res.partner' + + _columns = { + 'default_section_id': fields.many2one('crm.case.section', 'Default Sales Team'), + } + +res_users() + # 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..0aa8e08d524 100644 --- a/addons/sale_crm/sale_crm_view.xml +++ b/addons/sale_crm/sale_crm_view.xml @@ -46,5 +46,47 @@ + + + Account Invoice + account.invoice + + + + + + + + + + + + + Users Preferences + res.users + + + + + + + + + + + + + res.users.preferences.form + res.users + + + + + + + + + + From d6e87438d9c4d193862a877101969f26903f1405 Mon Sep 17 00:00:00 2001 From: Vijaykumar Baladaniya Date: Wed, 21 Nov 2012 10:32:15 +0530 Subject: [PATCH 02/10] [IMP] Add a group by on invoice tree for salesteam. bzr revid: vba@tinyerp.com-20121121050215-jswj8y7khi6ap37n --- addons/sale_crm/sale_crm_view.xml | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/addons/sale_crm/sale_crm_view.xml b/addons/sale_crm/sale_crm_view.xml index 0aa8e08d524..400a686b6af 100644 --- a/addons/sale_crm/sale_crm_view.xml +++ b/addons/sale_crm/sale_crm_view.xml @@ -46,6 +46,32 @@ + + + Account Invoice + account.invoice + + + + + + + + + + + + account.invoice.groupby + account.invoice + + + + + + + + + Account Invoice From 4cbd5c58fc4ae3ad41634209dc645a5670817d86 Mon Sep 17 00:00:00 2001 From: Vijaykumar Baladaniya Date: Wed, 21 Nov 2012 11:28:17 +0530 Subject: [PATCH 03/10] [IMP]Add section_id in the invoice analysis report. bzr revid: vba@tinyerp.com-20121121055817-3sw9yoac1xv12l2i --- addons/account/report/account_invoice_report.py | 5 ++++- addons/account/report/account_invoice_report_view.xml | 3 +++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/addons/account/report/account_invoice_report.py b/addons/account/report/account_invoice_report.py index fa2d071695b..e6202e7394f 100644 --- a/addons/account/report/account_invoice_report.py +++ b/addons/account/report/account_invoice_report.py @@ -100,6 +100,7 @@ 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): @@ -124,6 +125,7 @@ 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, @@ -217,7 +219,8 @@ class account_invoice_report(osv.osv): ai.residual, ai.amount_total, u.uom_type, - u.category_id + u.category_id, + ai.section_id ) """) diff --git a/addons/account/report/account_invoice_report_view.xml b/addons/account/report/account_invoice_report_view.xml index 289db376e5d..6d37e867390 100644 --- a/addons/account/report/account_invoice_report_view.xml +++ b/addons/account/report/account_invoice_report_view.xml @@ -27,6 +27,7 @@ + @@ -65,6 +66,7 @@ + @@ -81,6 +83,7 @@ + From d17568d5723e1dd351b2a551fc64eadd890fa9f0 Mon Sep 17 00:00:00 2001 From: Vijaykumar Baladaniya Date: Wed, 21 Nov 2012 15:49:09 +0530 Subject: [PATCH 04/10] [IMP] Add section_id in the invoice analysis report. bzr revid: vba@tinyerp.com-20121121101909-hez6fxcqcyn3njy8 --- .../account/report/account_invoice_report.py | 49 +++++++++++++------ .../report/account_invoice_report_view.xml | 3 -- addons/sale_crm/__init__.py | 1 + addons/sale_crm/__openerp__.py | 3 +- addons/sale_crm/report/__init__.py | 25 ++++++++++ .../sale_crm_account_invoice_report_view.xml | 20 ++++++++ .../sales_crm_account_invoice_report.py | 35 +++++++++++++ 7 files changed, 117 insertions(+), 19 deletions(-) create mode 100644 addons/sale_crm/report/__init__.py create mode 100644 addons/sale_crm/report/sale_crm_account_invoice_report_view.xml create mode 100644 addons/sale_crm/report/sales_crm_account_invoice_report.py 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: From 81b9e073ee58742c4433792b84ae9d814e66cc9c Mon Sep 17 00:00:00 2001 From: Vijaykumar Baladaniya Date: Wed, 21 Nov 2012 16:20:07 +0530 Subject: [PATCH 05/10] [IMP] Improve default_section_id. bzr revid: vba@tinyerp.com-20121121105007-8i3en0t0retn27nz --- addons/sale_crm/sale_crm.py | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/addons/sale_crm/sale_crm.py b/addons/sale_crm/sale_crm.py index 4b646c7b871..e86100fe503 100644 --- a/addons/sale_crm/sale_crm.py +++ b/addons/sale_crm/sale_crm.py @@ -46,6 +46,14 @@ class sale_order(osv.osv): sale_order() +class res_users(osv.Model): + _inherit = 'res.partner' + + _columns = { + 'default_section_id': fields.many2one('crm.case.section', 'Default Sales Team'), + } + +res_users() class account_invoice(osv.osv): _inherit = 'account.invoice' @@ -69,14 +77,4 @@ class account_invoice(osv.osv): account_invoice() - -class res_users(osv.Model): - _inherit = 'res.partner' - - _columns = { - 'default_section_id': fields.many2one('crm.case.section', 'Default Sales Team'), - } - -res_users() - # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: From 7efa6b76855b5673bd305aba513385da48f07945 Mon Sep 17 00:00:00 2001 From: Vijaykumar Baladaniya Date: Wed, 21 Nov 2012 16:50:38 +0530 Subject: [PATCH 06/10] [IMP] Change argument. bzr revid: vba@tinyerp.com-20121121112038-8n21ntn7m25j73i6 --- addons/sale_crm/sale_crm.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addons/sale_crm/sale_crm.py b/addons/sale_crm/sale_crm.py index e86100fe503..640038a0df5 100644 --- a/addons/sale_crm/sale_crm.py +++ b/addons/sale_crm/sale_crm.py @@ -66,7 +66,7 @@ class account_invoice(osv.osv): 'section_id': lambda self,cr,uid,c: self.pool.get('res.users').browse(cr, uid, uid, c).default_section_id.id, } - def create(self, cr, uid, vals, context=None): + def create(self, cr, uid, vals, context={}): section_id = vals.get('section_id', False) invoice_type = context.get('type', False) user_id = vals.get('user_id', False) From 950ae6e125062e5de9163ff9e6730aa398fc80f7 Mon Sep 17 00:00:00 2001 From: Vijaykumar Baladaniya Date: Wed, 21 Nov 2012 18:11:28 +0530 Subject: [PATCH 07/10] Set a default_section_id at create time. bzr revid: vba@tinyerp.com-20121121124128-8smdl8valzdp4efk --- addons/sale_crm/sale_crm.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/addons/sale_crm/sale_crm.py b/addons/sale_crm/sale_crm.py index 640038a0df5..05c2f7c1b86 100644 --- a/addons/sale_crm/sale_crm.py +++ b/addons/sale_crm/sale_crm.py @@ -47,7 +47,7 @@ class sale_order(osv.osv): sale_order() class res_users(osv.Model): - _inherit = 'res.partner' + _inherit = 'res.users' _columns = { 'default_section_id': fields.many2one('crm.case.section', 'Default Sales Team'), @@ -66,12 +66,14 @@ class account_invoice(osv.osv): 'section_id': lambda self,cr,uid,c: self.pool.get('res.users').browse(cr, uid, uid, c).default_section_id.id, } - def create(self, cr, uid, vals, context={}): + def create(self, cr, uid, vals, context=None): section_id = vals.get('section_id', False) invoice_type = context.get('type', False) user_id = vals.get('user_id', False) + user_obj = self.pool.get('res.users').browse(cr, uid, user_id, context=context) + user_default_section_id = user_obj.default_section_id.id or False if not section_id and invoice_type in ['out_invoice', 'out_refund'] and user_id: - vals['section_id'] = user_id + vals['section_id'] = user_default_section_id obj_id = super(account_invoice, self).create(cr, uid, vals, context=context) return obj_id From c4366709a84aad7106ea71678634bd36e11c184a Mon Sep 17 00:00:00 2001 From: Vijaykumar Baladaniya Date: Wed, 21 Nov 2012 18:52:38 +0530 Subject: [PATCH 08/10] Improve code. bzr revid: vba@tinyerp.com-20121121132238-blrkmrt10wsyxdqm --- addons/sale_crm/sale_crm.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/addons/sale_crm/sale_crm.py b/addons/sale_crm/sale_crm.py index 05c2f7c1b86..fa82358e15f 100644 --- a/addons/sale_crm/sale_crm.py +++ b/addons/sale_crm/sale_crm.py @@ -70,10 +70,9 @@ class account_invoice(osv.osv): section_id = vals.get('section_id', False) invoice_type = context.get('type', False) user_id = vals.get('user_id', False) - user_obj = self.pool.get('res.users').browse(cr, uid, user_id, context=context) - user_default_section_id = user_obj.default_section_id.id or False - if not section_id and invoice_type in ['out_invoice', 'out_refund'] and user_id: - vals['section_id'] = user_default_section_id + user_obj = self.pool.get('res.users').browse(cr, uid, user_id, context=context) + if not section_id and invoice_type in ['out_invoice', 'out_refund'] and user_id and user_obj.default_section_id: + vals['section_id'] = user_obj.default_section_id.id obj_id = super(account_invoice, self).create(cr, uid, vals, context=context) return obj_id From b434782c969e9f62dcf071e0f8da93ac1e0695b9 Mon Sep 17 00:00:00 2001 From: Vijaykumar Baladaniya Date: Wed, 21 Nov 2012 19:18:31 +0530 Subject: [PATCH 09/10] Improve context. bzr revid: vba@tinyerp.com-20121121134831-39shqk4z9mwj2eu4 --- addons/sale_crm/sale_crm.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/addons/sale_crm/sale_crm.py b/addons/sale_crm/sale_crm.py index fa82358e15f..c4852ad6a95 100644 --- a/addons/sale_crm/sale_crm.py +++ b/addons/sale_crm/sale_crm.py @@ -67,15 +67,18 @@ class account_invoice(osv.osv): } def create(self, cr, uid, vals, context=None): + if context is None: + context = {} section_id = vals.get('section_id', False) invoice_type = context.get('type', False) user_id = vals.get('user_id', False) - user_obj = self.pool.get('res.users').browse(cr, uid, user_id, context=context) + user_obj = self.pool.get('res.users').browse(cr, uid, user_id, context=context) if not section_id and invoice_type in ['out_invoice', 'out_refund'] and user_id and user_obj.default_section_id: vals['section_id'] = user_obj.default_section_id.id obj_id = super(account_invoice, self).create(cr, uid, vals, context=context) return obj_id + account_invoice() # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: From 03be78558362e19dc29972f5f754a816d104ae71 Mon Sep 17 00:00:00 2001 From: Vijaykumar Baladaniya Date: Thu, 22 Nov 2012 16:21:08 +0530 Subject: [PATCH 10/10] [IMP] Improve changes. bzr revid: vba@tinyerp.com-20121122105108-svykp47xpq1ghvdy --- addons/sale_crm/sale_crm_view.xml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/addons/sale_crm/sale_crm_view.xml b/addons/sale_crm/sale_crm_view.xml index 400a686b6af..4a3bc6c599c 100644 --- a/addons/sale_crm/sale_crm_view.xml +++ b/addons/sale_crm/sale_crm_view.xml @@ -66,7 +66,6 @@ - @@ -79,7 +78,7 @@ - +