From 0c4a6566399121699d3ee7aedae660a53163ad8a Mon Sep 17 00:00:00 2001 From: Christophe Matthieu Date: Wed, 6 Feb 2013 12:57:36 +0100 Subject: [PATCH] [IMP] salesteams: add account, crm: on_change user_id, change the salesteams bzr revid: chm@openerp.com-20130206115736-fw3coo0u50itvjlq --- addons/crm/crm.py | 22 +++++++++++----------- addons/crm/crm_lead.py | 7 +++++++ addons/crm/crm_lead_view.xml | 4 ++-- addons/crm/crm_salesteams.xml | 8 +++++--- addons/crm/static/src/css/crm.css | 2 +- addons/sale_crm/sale_crm.py | 24 ++++++++++-------------- addons/sale_crm/sale_crm_view.xml | 15 +++++++++++++++ 7 files changed, 51 insertions(+), 31 deletions(-) diff --git a/addons/crm/crm.py b/addons/crm/crm.py index c00b5ff2597..471ba1613d8 100644 --- a/addons/crm/crm.py +++ b/addons/crm/crm.py @@ -109,19 +109,18 @@ class crm_case_section(osv.osv): def get_full_name(self, cr, uid, ids, field_name, arg, context=None): return dict(self.name_get(cr, uid, ids, context=context)) - def get_number_leads(self, cr, uid, ids, field_name, arg, context=None): + def get_number_items(self, cr, uid, ids, model, domain, context=None): res = dict.fromkeys(ids, 0) - lead_obj = self.pool.get('crm.lead') + obj = self.pool.get(model) for section_id in ids: - res[section_id] = lead_obj.search(cr, uid, [("section_id", "=", section_id), '|', '|', ("type", "=", "lead"), ("type", "=", "both"), ("type", "=", False), ('state', 'not in', ['done', 'cancel'])], count=True, context=context) + res[section_id] = obj.search(cr, uid, [("section_id", "=", section_id)] + domain, count=True, context=context) return res - def get_number_opportunities(self, cr, uid, ids, field_name, arg, context=None): - res = dict.fromkeys(ids, 0) - lead_obj = self.pool.get('crm.lead') - for section_id in ids: - res[section_id] = lead_obj.search(cr, uid, [("section_id", "=", section_id), '|', ("type", "=", "opportunity"), ("type", "=", "both"), ('state', 'not in', ['done', 'cancel'])], context=context, count=True) - return res + def _get_number_leads(self, cr, uid, ids, field_name, arg, context=None): + return self.get_number_items(cr, uid, ids, 'crm.lead', ['|', '|', ("type", "=", "lead"), ("type", "=", "both"), ("type", "=", False), ('state', 'not in', ['done', 'cancel'])], context=context) + + def _get_number_opportunities(self, cr, uid, ids, field_name, arg, context=None): + return self.get_number_items(cr, uid, ids, 'crm.lead', ['|', ("type", "=", "opportunity"), ("type", "=", "both"), ('state', 'not in', ['done', 'cancel'])], context=context) _columns = { 'name': fields.char('Sales Team', size=64, required=True, translate=True), @@ -142,8 +141,9 @@ class crm_case_section(osv.osv): 'alias_id': fields.many2one('mail.alias', 'Alias', ondelete="cascade", required=True, help="The email address associated with this team. New emails received will automatically " "create new leads assigned to the team."), - 'number_lead': fields.function(get_number_leads, type='integer', readonly=True), - 'number_opportunity': fields.function(get_number_opportunities, type='integer', readonly=True), + 'number_lead': fields.function(_get_number_leads, type='integer', readonly=True), + 'number_opportunity': fields.function(_get_number_opportunities, type='integer', readonly=True), + 'color': fields.integer('Color Index'), } def _get_stage_common(self, cr, uid, context): diff --git a/addons/crm/crm_lead.py b/addons/crm/crm_lead.py index aec5e353d48..3f23284f03a 100644 --- a/addons/crm/crm_lead.py +++ b/addons/crm/crm_lead.py @@ -90,6 +90,13 @@ class crm_lead(base_stage, format_address, osv.osv): context['dynamic_help_documents'] = _("leads") return super(crm_lead, self).dynamic_help(cr, uid, help, context=context) + def onchange_user_id(self, cr, uid, ids, section_id, user_id, context=None): + if user_id: + section_ids = self.pool.get('crm.case.section').search(cr, uid, ['|', ('user_id', '=', user_id), ('member_ids', '=', user_id)], context=context) + if section_ids and (not section_id or section_id not in section_ids): + section_id = section_ids[0] + return {'value': {'section_id': section_id}} + def create(self, cr, uid, vals, context=None): if context is None: context = {} diff --git a/addons/crm/crm_lead_view.xml b/addons/crm/crm_lead_view.xml index 3e9249aa6fa..3f5c5449f87 100644 --- a/addons/crm/crm_lead_view.xml +++ b/addons/crm/crm_lead_view.xml @@ -152,7 +152,7 @@ --> - +