[IMP] crm: set user partner team as default team
This fix sets the first sales team of the current user as the default sales team if no other one is given. For models: crm.lead, crm.phonecall, crm.claim, crm.helpdesk, project.issue, sale.order, account.invoice Existing methods are removed and new methods in sales team model (crm.team) have to be called when needed. closes #6438 opw-633562
This commit is contained in:
+4
-24
@@ -92,31 +92,11 @@ class crm_lead(format_address, osv.osv):
|
||||
context['empty_list_help_document_name'] = _("leads")
|
||||
return super(crm_lead, self).get_empty_list_help(cr, uid, help, context=context)
|
||||
|
||||
def _get_default_team_id(self, cr, uid, user_id=False, context=None):
|
||||
""" Gives default team by checking if present in the context """
|
||||
team_id = self._resolve_team_id_from_context(cr, uid, context=context) or False
|
||||
return team_id
|
||||
|
||||
def _get_default_stage_id(self, cr, uid, context=None):
|
||||
""" Gives default stage_id """
|
||||
team_id = self._get_default_team_id(cr, uid, context=context)
|
||||
team_id = self.pool['crm.team']._get_default_team_id(cr, uid, context=context)
|
||||
return self.stage_find(cr, uid, [], team_id, [('fold', '=', False)], context=context)
|
||||
|
||||
def _resolve_team_id_from_context(self, cr, uid, context=None):
|
||||
""" Returns ID of team based on the value of 'team_id'
|
||||
context key, or None if it cannot be resolved to a single
|
||||
Sales Team.
|
||||
"""
|
||||
if context is None:
|
||||
context = {}
|
||||
if type(context.get('default_team_id')) in (int, long):
|
||||
return context.get('default_team_id')
|
||||
if isinstance(context.get('default_team_id'), basestring):
|
||||
team_ids = self.pool.get('crm.team').name_search(cr, uid, name=context['default_team_id'], context=context)
|
||||
if len(team_ids) == 1:
|
||||
return int(team_ids[0][0])
|
||||
return None
|
||||
|
||||
def _resolve_type_from_context(self, cr, uid, context=None):
|
||||
""" Returns the type (lead or opportunity) from the type context
|
||||
key. Returns None if it cannot be resolved.
|
||||
@@ -137,7 +117,7 @@ class crm_lead(format_address, osv.osv):
|
||||
# - OR ('case_default', '=', True), ('fold', '=', False): add default columns that are not folded
|
||||
# - OR ('team_ids', '=', team_id), ('fold', '=', False) if team_id: add team columns that are not folded
|
||||
search_domain = []
|
||||
team_id = self._resolve_team_id_from_context(cr, uid, context=context)
|
||||
team_id = self.pool['crm.team']._resolve_team_id_from_context(cr, uid, context=context)
|
||||
if team_id:
|
||||
search_domain += ['|', ('team_ids', '=', team_id)]
|
||||
search_domain += [('id', 'in', ids)]
|
||||
@@ -292,7 +272,7 @@ class crm_lead(format_address, osv.osv):
|
||||
'type': 'lead',
|
||||
'user_id': lambda s, cr, uid, c: uid,
|
||||
'stage_id': lambda s, cr, uid, c: s._get_default_stage_id(cr, uid, c),
|
||||
'team_id': lambda s, cr, uid, c: s._get_default_team_id(cr, uid, context=c),
|
||||
'team_id': lambda s, cr, uid, c: s.pool['crm.team']._get_default_team_id(cr, uid, context=c),
|
||||
'company_id': lambda s, cr, uid, c: s.pool.get('res.company')._company_default_get(cr, uid, 'crm.lead', context=c),
|
||||
'priority': lambda *a: crm.AVAILABLE_PRIORITIES[0][0],
|
||||
'color': 0,
|
||||
@@ -339,7 +319,7 @@ class crm_lead(format_address, osv.osv):
|
||||
def on_change_user(self, cr, uid, ids, user_id, context=None):
|
||||
""" When changing the user, also set a team_id or restrict team id
|
||||
to the ones user_id is member of. """
|
||||
team_id = self._get_default_team_id(cr, uid, context=context)
|
||||
team_id = self.pool['crm.team']._get_default_team_id(cr, uid, user_id=user_id, context=context)
|
||||
if user_id and not team_id and self.pool['res.users'].has_group(cr, uid, 'base.group_multi_salesteams'):
|
||||
team_ids = self.pool.get('crm.team').search(cr, uid, ['|', ('user_id', '=', user_id), ('member_ids', '=', user_id)], context=context)
|
||||
if team_ids:
|
||||
|
||||
@@ -77,6 +77,7 @@ class crm_phonecall(osv.osv):
|
||||
'priority': '1',
|
||||
'state': _get_default_state,
|
||||
'user_id': lambda self, cr, uid, ctx: uid,
|
||||
'team_id': lambda s, cr, uid, c: s.pool['crm.team']._get_default_team_id(cr, uid, context=c),
|
||||
'active': 1
|
||||
}
|
||||
|
||||
|
||||
@@ -59,13 +59,9 @@ class crm_claim(osv.osv):
|
||||
_order = "priority,date desc"
|
||||
_inherit = ['mail.thread']
|
||||
|
||||
def _get_default_team_id(self, cr, uid, context=None):
|
||||
""" Gives default team by checking if present in the context """
|
||||
return self.pool.get('crm.lead')._resolve_team_id_from_context(cr, uid, context=context) or False
|
||||
|
||||
def _get_default_stage_id(self, cr, uid, context=None):
|
||||
""" Gives default stage_id """
|
||||
team_id = self._get_default_team_id(cr, uid, context=context)
|
||||
team_id = self.pool['crm.team']._get_default_team_id(cr, uid, context=context)
|
||||
return self.stage_find(cr, uid, [], team_id, [('sequence', '=', '1')], context=context)
|
||||
|
||||
_columns = {
|
||||
@@ -103,7 +99,7 @@ class crm_claim(osv.osv):
|
||||
|
||||
_defaults = {
|
||||
'user_id': lambda s, cr, uid, c: uid,
|
||||
'team_id': lambda s, cr, uid, c: s._get_default_team_id(cr, uid, c),
|
||||
'team_id': lambda s, cr, uid, c: s.pool['crm.team']._get_default_team_id(cr, uid, context=c),
|
||||
'date': fields.datetime.now,
|
||||
'company_id': lambda s, cr, uid, c: s.pool.get('res.company')._company_default_get(cr, uid, 'crm.case', context=c),
|
||||
'priority': '1',
|
||||
|
||||
@@ -81,6 +81,7 @@ class crm_helpdesk(osv.osv):
|
||||
'user_id': lambda s, cr, uid, c: uid,
|
||||
'state': lambda *a: 'draft',
|
||||
'date': fields.datetime.now,
|
||||
'team_id': lambda s, cr, uid, c: s.pool['crm.team']._get_default_team_id(cr, uid, context=c),
|
||||
'company_id': lambda s, cr, uid, c: s.pool.get('res.company')._company_default_get(cr, uid, 'crm.helpdesk', context=c),
|
||||
'priority': '1',
|
||||
}
|
||||
|
||||
@@ -294,6 +294,7 @@ class project_issue(osv.Model):
|
||||
|
||||
_defaults = {
|
||||
'active': 1,
|
||||
'team_id': lambda s, cr, uid, c: s.pool['crm.team']._get_default_team_id(cr, uid, context=c),
|
||||
'stage_id': lambda s, cr, uid, c: s._get_default_stage_id(cr, uid, c),
|
||||
'company_id': lambda s, cr, uid, c: s.pool.get('res.company')._company_default_get(cr, uid, 'crm.helpdesk', context=c),
|
||||
'priority': '0',
|
||||
|
||||
+3
-43
@@ -155,26 +155,6 @@ class sale_order(osv.osv):
|
||||
raise UserError(_('There is no default company for the current user!'))
|
||||
return company_id
|
||||
|
||||
def _get_default_team_id(self, cr, uid, context=None):
|
||||
""" Gives default team by checking if present in the context """
|
||||
team_id = self._resolve_team_id_from_context(cr, uid, context=context) or False
|
||||
return team_id
|
||||
|
||||
def _resolve_team_id_from_context(self, cr, uid, context=None):
|
||||
""" Returns ID of team based on the value of 'team_id'
|
||||
context key, or None if it cannot be resolved to a single
|
||||
Sales Team.
|
||||
"""
|
||||
if context is None:
|
||||
context = {}
|
||||
if type(context.get('default_team_id')) in (int, long):
|
||||
return context.get('default_team_id')
|
||||
if isinstance(context.get('default_team_id'), basestring):
|
||||
team_ids = self.pool.get('crm.team').name_search(cr, uid, name=context['default_team_id'], context=context)
|
||||
if len(team_ids) == 1:
|
||||
return int(team_ids[0][0])
|
||||
return None
|
||||
|
||||
_columns = {
|
||||
'name': fields.char('Order Reference', required=True, copy=False,
|
||||
readonly=True, states={'draft': [('readonly', False)], 'sent': [('readonly', False)]}, select=True),
|
||||
@@ -256,7 +236,7 @@ class sale_order(osv.osv):
|
||||
'partner_invoice_id': lambda self, cr, uid, context: context.get('partner_id', False) and self.pool.get('res.partner').address_get(cr, uid, [context['partner_id']], ['invoice'])['invoice'],
|
||||
'partner_shipping_id': lambda self, cr, uid, context: context.get('partner_id', False) and self.pool.get('res.partner').address_get(cr, uid, [context['partner_id']], ['delivery'])['delivery'],
|
||||
'note': lambda self, cr, uid, context: self.pool.get('res.users').browse(cr, uid, uid, context=context).company_id.sale_note,
|
||||
'team_id': lambda s, cr, uid, c: s._get_default_team_id(cr, uid, c),
|
||||
'team_id': lambda s, cr, uid, c: s.pool['crm.team']._get_default_team_id(cr, uid, context=c),
|
||||
}
|
||||
_sql_constraints = [
|
||||
('name_uniq', 'unique(name, company_id)', 'Order Reference must be unique per Company!'),
|
||||
@@ -343,7 +323,7 @@ class sale_order(osv.osv):
|
||||
val.update(delivery_onchange['value'])
|
||||
if pricelist:
|
||||
val['pricelist_id'] = pricelist
|
||||
if not self._get_default_team_id(cr, uid, context=context) and part.team_id:
|
||||
if not self.pool['crm.team']._get_default_team_id(cr, uid, context=context) and part.team_id:
|
||||
val['team_id'] = part.team_id.id
|
||||
sale_note = self.get_salenote(cr, uid, ids, part.id, context=context)
|
||||
if sale_note: val.update({'note': sale_note})
|
||||
@@ -1185,32 +1165,12 @@ class mail_compose_message(osv.Model):
|
||||
class account_invoice(osv.Model):
|
||||
_inherit = 'account.invoice'
|
||||
|
||||
def _get_default_team_id(self, cr, uid, context=None):
|
||||
""" Gives default team by checking if present in the context """
|
||||
team_id = self._resolve_team_id_from_context(cr, uid, context=context) or False
|
||||
return team_id
|
||||
|
||||
def _resolve_team_id_from_context(self, cr, uid, context=None):
|
||||
""" Returns ID of team based on the value of 'team_id'
|
||||
context key, or None if it cannot be resolved to a single
|
||||
Sales Team.
|
||||
"""
|
||||
if context is None:
|
||||
context = {}
|
||||
if type(context.get('default_team_id')) in (int, long):
|
||||
return context.get('default_team_id')
|
||||
if isinstance(context.get('default_team_id'), basestring):
|
||||
team_ids = self.pool.get('crm.team').name_search(cr, uid, name=context['default_team_id'], context=context)
|
||||
if len(team_ids) == 1:
|
||||
return int(team_ids[0][0])
|
||||
return None
|
||||
|
||||
_columns = {
|
||||
'team_id': fields.many2one('crm.team', 'Sales Team', oldname='section_id'),
|
||||
}
|
||||
|
||||
_defaults = {
|
||||
'team_id': lambda self, cr, uid, c=None: self._get_default_team_id(cr, uid, context=c)
|
||||
'team_id': lambda s, cr, uid, c: s.pool['crm.team']._get_default_team_id(cr, uid, context=c),
|
||||
}
|
||||
|
||||
def confirm_paid(self, cr, uid, ids, context=None):
|
||||
|
||||
@@ -63,6 +63,28 @@ class crm_team(osv.Model):
|
||||
team_result[self._period_number - (month_delta.months + 1)] = {'value': group.get(value_field, 0), 'tooltip': group.get(groupby_field, 0)}
|
||||
return team_result
|
||||
|
||||
def _get_default_team_id(self, cr, uid, user_id=None, context=None):
|
||||
team_id = self._resolve_team_id_from_context(cr, uid, context=context) or False
|
||||
if not team_id:
|
||||
team_ids = self.search(cr, uid, [('member_ids', '=', user_id or uid)], limit=1, context=context)
|
||||
team_id = team_ids[0] if team_ids else False
|
||||
return team_id
|
||||
|
||||
def _resolve_team_id_from_context(self, cr, uid, context=None):
|
||||
""" Returns ID of team based on the value of 'default_team_id'
|
||||
context key, or None if it cannot be resolved to a single
|
||||
Sales Team.
|
||||
"""
|
||||
if context is None:
|
||||
context = {}
|
||||
if type(context.get('default_team_id')) in (int, long):
|
||||
return context.get('default_team_id')
|
||||
if isinstance(context.get('default_team_id'), basestring):
|
||||
team_ids = self.name_search(cr, uid, name=context['default_team_id'], context=context)
|
||||
if len(team_ids) == 1:
|
||||
return int(team_ids[0][0])
|
||||
return None
|
||||
|
||||
_columns = {
|
||||
'name': fields.char('Sales Team', size=64, required=True, translate=True),
|
||||
'complete_name': fields.function(get_full_name, type='char', size=256, readonly=True, store=True, string="Full Name"),
|
||||
|
||||
Reference in New Issue
Block a user