Files
odoo_source/addons/crm/sales_team.py
T
Mansi Gandhi acbe01a1de [IMP] crm:Various improvements,
>In Dashboard/Your pipeline and in Sales/Your Pipeline: Remove the Direct Sales team filter.
	>In the kanban view, if the expected revenu = 0, the "," shouldn't appear.
	>In lead form view, remove the Opportunity header and move Probability under Analysis in Extra Info tab.
	>Rename Your Pipeline into My Pipeline to match the menu entry.
2016-05-27 12:03:35 +02:00

93 lines
4.3 KiB
Python

# -*- coding: utf-8 -*-
from openerp.osv import fields, osv
from openerp.tools.safe_eval import safe_eval as eval
from openerp.tools.translate import _
class crm_team(osv.Model):
_name = 'crm.team'
_inherit = ['mail.alias.mixin', 'crm.team']
_columns = {
'resource_calendar_id': fields.many2one('resource.calendar', "Working Time", help="Used to compute open days"),
'use_leads': fields.boolean('Leads',
help="The first contact you get with a potential customer is a lead you qualify before converting it into a real business opportunity. Check this box to manage leads in this sales team."),
'use_opportunities': fields.boolean('Opportunities', help="Check this box to manage opportunities in this sales team."),
'alias_id': fields.many2one('mail.alias', 'Alias', ondelete="restrict", required=True, help="The email address associated with this team. New emails received will automatically create new leads assigned to the team."),
}
_defaults = {
'use_opportunities': True,
}
def get_alias_model_name(self, vals):
return 'crm.lead'
def get_alias_values(self):
has_group_use_lead = self.env['res.users'].has_group('crm.group_use_lead')
values = super(crm_team, self).get_alias_values()
values['alias_defaults'] = defaults = eval(self.alias_defaults or "{}")
defaults['type'] = 'lead' if has_group_use_lead and self.use_leads else 'opportunity'
defaults['team_id'] = self.id
return values
def onchange_use_leads_opportunities(self, cr, uid, ids, use_leads, use_opportunities, context=None):
if use_leads or use_opportunities:
return {'value': {}}
return {'value': {'alias_name': False}}
def create(self, cr, uid, vals, context=None):
generate_alias_name = self.pool['ir.values'].get_default(cr, uid, 'sales.config.settings', 'generate_sales_team_alias')
if generate_alias_name and not vals.get('alias_name'):
vals['alias_name'] = vals.get('name')
return super(crm_team, self).create(cr, uid, vals, context=context)
def write(self, cr, uid, ids, vals, context=None):
res = super(crm_team, self).write(cr, uid, ids, vals, context=context)
if vals.get('use_leads') or vals.get('alias_defaults'):
for team in self.browse(cr, uid, ids, context=context):
team.alias_id.write(team.get_alias_values())
return res
def action_your_pipeline(self, cr, uid, context=None):
IrModelData = self.pool['ir.model.data']
action = IrModelData.xmlid_to_object(cr, uid, 'crm.crm_lead_opportunities_tree_view', context=context).read(['name', 'help', 'res_model', 'target', 'domain', 'context', 'type', 'search_view_id'])
if not action:
action = {}
else:
action = action[0]
user_team_id = self.pool['res.users'].browse(cr, uid, uid, context=context).sale_team_id.id
if not user_team_id:
user_team_id = self.search(cr, uid, [], context=context, limit=1)
user_team_id = user_team_id and user_team_id[0] or False
action['help'] = """<p class='oe_view_nocontent_create'>Click here to add new opportunities</p><p>
Looks like you are not a member of a sales team. You should add yourself
as a member of one of the sales team.
</p>"""
if user_team_id:
action['help'] += "<p>As you don't belong to any sales team, Odoo opens the first one by default.</p>"
action_context = eval(action['context'], {'uid': uid})
if user_team_id:
action_context.update({
'default_team_id': user_team_id,
})
tree_view_id = IrModelData.xmlid_to_res_id(cr, uid, 'crm.crm_case_tree_view_oppor')
form_view_id = IrModelData.xmlid_to_res_id(cr, uid, 'crm.crm_case_form_view_oppor')
kanb_view_id = IrModelData.xmlid_to_res_id(cr, uid, 'crm.crm_case_kanban_view_leads')
action.update({
'views': [
[kanb_view_id, 'kanban'],
[tree_view_id, 'tree'],
[form_view_id, 'form'],
[False, 'graph'],
[False, 'calendar'],
[False, 'pivot']
],
'context': action_context,
})
return action