From ee844c0ac678153015b1dc7854b0acfc0b8f9bcd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thibault=20Delavall=C3=A9e?= Date: Thu, 11 Apr 2013 14:33:56 +0200 Subject: [PATCH] [FIX] crm: fixed on_change_user that was crashing because refers to a default_section_id field that is added in sale_crm bridge module. New behavior is : one of the team user_id is a member (crm), or default_section_id if defined or default behavior (sale_crm) bzr revid: tde@openerp.com-20130411123356-kc8ty16i71nwgzsm --- addons/crm/crm_lead.py | 11 +++++++---- addons/crm/crm_lead_view.xml | 2 +- addons/sale_crm/sale_crm.py | 16 ++++++++++++++++ 3 files changed, 24 insertions(+), 5 deletions(-) diff --git a/addons/crm/crm_lead.py b/addons/crm/crm_lead.py index 509bcf106b6..7dd4d0e1064 100644 --- a/addons/crm/crm_lead.py +++ b/addons/crm/crm_lead.py @@ -357,11 +357,14 @@ class crm_lead(base_stage, format_address, osv.osv): return {'value' : values} def on_change_user(self, cr, uid, ids, user_id, context=None): + """ When changing the user, also set a section_id or restrict section id + to the ones user_id is member of. """ + section_id = False if user_id: - user = self.pool.get('res.users').browse(cr, uid, user_id, context=context) - return {'value':{'section_id': user.default_section_id and user.default_section_id.id or False}} - else: - return {'value':{'section_id':False}} + section_ids = self.pool.get('crm.case.section').search(cr, uid, ['|', ('user_id', '=', user_id), ('member_ids', '=', user_id)], context=context) + if section_ids: + section_id = section_ids[0] + return {'value': {'section_id': section_id}} def _check(self, cr, uid, ids=False, context=None): """ Override of the base.stage method. diff --git a/addons/crm/crm_lead_view.xml b/addons/crm/crm_lead_view.xml index c14686b7211..fb18e747fd7 100644 --- a/addons/crm/crm_lead_view.xml +++ b/addons/crm/crm_lead_view.xml @@ -152,7 +152,7 @@ --> - +