[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
This commit is contained in:
parent
f8a2299525
commit
ee844c0ac6
|
@ -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.
|
||||
|
|
|
@ -152,7 +152,7 @@
|
|||
-->
|
||||
</group>
|
||||
<group>
|
||||
<field name="user_id"/>
|
||||
<field name="user_id" on_change="on_change_user(user_id, context)"/>
|
||||
<label for="section_id"/>
|
||||
<div>
|
||||
<field name="section_id"/>
|
||||
|
|
|
@ -36,6 +36,22 @@ class res_users(osv.Model):
|
|||
'default_section_id': fields.many2one('crm.case.section', 'Default Sales Team'),
|
||||
}
|
||||
|
||||
|
||||
class sale_crm_lead(osv.Model):
|
||||
_inherit = 'crm.lead'
|
||||
|
||||
def on_change_user(self, cr, uid, ids, user_id, context=None):
|
||||
""" Override of on change user_id on lead/opportunity; when having sale
|
||||
the new logic is :
|
||||
- use user.default_section_id
|
||||
- or fallback on previous behavior """
|
||||
if user_id:
|
||||
user = self.pool.get('res.users').browse(cr, uid, user_id, context=context)
|
||||
if user.default_section_id and user.default_section_id.id:
|
||||
return {'value': {'section_id': user.default_section_id.id}}
|
||||
return super(sale_crm_lead, self).on_change_user(cr, uid, ids, user_id, context=context)
|
||||
|
||||
|
||||
class account_invoice(osv.osv):
|
||||
_inherit = 'account.invoice'
|
||||
_columns = {
|
||||
|
|
Loading…
Reference in New Issue