[IMP]crm: Improve state field as function field according to stage changes and added a group technical feature in state field

bzr revid: mma@tinyerp.com-20120419060131-ojhyh5og0p4cplyz
This commit is contained in:
Mayur Maheshwari (OpenERP)
2012-04-19 11:31:31 +05:30
parent 1c97067398
commit 529a02cc58
4 changed files with 50 additions and 21 deletions
+1 -5
View File
@@ -71,11 +71,7 @@ class crm_case_stage(osv.osv):
'on_change': fields.boolean('Change Probability Automatically', help="Setting this stage will change the probability automatically on the opportunity."),
'requirements': fields.text('Requirements'),
'section_ids':fields.many2many('crm.case.section', 'section_stage_rel', 'stage_id', 'section_id', 'Sections'),
'state': fields.selection(AVAILABLE_STATES, 'State', size=16,
help='The state is set to \'Draft\', when a case is created.\
\nIf the case is in progress the state is set to \'Open\'.\
\nWhen the case is over, the state is set to \'Done\'.\
\nIf the case needs to be reviewed then the state is set to \'Pending\'.'),
'state': fields.selection(AVAILABLE_STATES, 'State', size=16, help="This state is related to stage"),
'case_default': fields.boolean('Common to All Teams', help="If you check this field, this stage will be proposed by default on each sales team. It will not assign this stage to existing teams."),
}
+34 -2
View File
@@ -138,6 +138,31 @@ class crm_lead(crm_case, osv.osv):
break
return res
def _get_state(self, cr, uid, ids, name, arg, context=None):
res = {}
for lead in self.browse(cr, uid, ids, context=context):
if lead.stage_id:
res[lead.id] = lead.stage_id.state
return res
def _get_stage(self, cr, uid, ids, context=None):
crm_lead_obj = self.pool.get('crm.lead')
result = {}
for stage in self.browse(cr, uid, ids, context=context):
if stage.state:
crm_lead_ids = crm_lead_obj.search(cr, uid, [('state', '=', stage.state)], context=context)
for lead in crm_lead_obj.browse(cr, uid, crm_lead_ids, context=context):
result[lead.id] = True
return result.keys()
def _save_state(self, cr, uid, crm_lead_id, field_name, field_value, arg, context=None):
crm_case_obj = self.pool.get('crm.case.stage')
stage_ids = crm_case_obj.search(cr, uid, [('state', '=', field_value)], order='sequence', context=context)
if stage_ids:
return cr.execute("""update crm_lead set state=%s, stage_id=%s where id=%s""", (field_value, stage_ids[0], crm_lead_id))
else:
return cr.execute("""update crm_lead set state=%s where id=%s""", (field_value, crm_lead_id))
_columns = {
'partner_id': fields.many2one('res.partner', 'Partner', ondelete='set null',
select=True, help="Optional linked partner, usually after conversion of the lead"),
@@ -175,7 +200,14 @@ class crm_lead(crm_case, osv.osv):
multi='day_open', type="float", store=True),
'day_close': fields.function(_compute_day, string='Days to Close', \
multi='day_close', type="float", store=True),
'state': fields.related('stage_id','state', type='char', selection=crm.AVAILABLE_STATES, string="State", store=True, readonly=True),
'state': fields.function(_get_state, fnct_inv=_save_state, type='selection', selection=crm.AVAILABLE_STATES, string="State", readonly=True,
store = {
'crm.lead': (lambda self, cr, uid, ids, c={}: ids, ['stage_id'], 10),
'crm.case.stage': (_get_stage, ['state'], 10)
}, help='The state is set to \'Draft\', when a case is created.\
\nIf the case is in progress the state is set to \'Open\'.\
\nWhen the case is over, the state is set to \'Done\'.\
\nIf the case needs to be reviewed then the state is set to \'Pending\'.'),
'message_ids': fields.one2many('mail.message', 'res_id', 'Messages', domain=[('model','=',_name)]),
'subjects': fields.function(_get_email_subject, fnct_search=_history_search, string='Subject of Email', type='char', size=64),
@@ -202,7 +234,7 @@ class crm_lead(crm_case, osv.osv):
'active': lambda *a: 1,
'user_id': crm_case._get_default_user,
'email_from': crm_case._get_default_email,
'state': lambda *a: 'draft',
'state': 'draft',
'type': lambda *a: 'lead',
'section_id': crm_case._get_section,
'company_id': lambda s, cr, uid, c: s.pool.get('res.company')._company_default_get(cr, uid, 'crm.lead', context=c),
+14 -14
View File
@@ -53,14 +53,14 @@
<field name="arch" type="xml">
<form string="Leads Form" layout="manual">
<div class="oe_form_topbar">
<button name="case_cancel" string="Cancel" states="draft,open,pending" type="object" icon="gtk-cancel" />
<button name="case_open" string="Open" states="draft,pending" type="object" icon="gtk-go-forward" />
<button name="case_mark_lost" string="Close" states="open,pending" type="object" icon="gtk-close" />
<button name="case_pending" string="Pending" states="open" type="object" icon="gtk-media-pause" />
<button name="case_cancel" string="Cancel" states="draft,open,pending" type="object" icon="gtk-cancel" groups="base.group_no_one"/>
<button name="case_open" string="Open" states="draft,pending" type="object" icon="gtk-go-forward" groups="base.group_no_one"/>
<button name="case_mark_lost" string="Close" states="open,pending" type="object" icon="gtk-close" groups="base.group_no_one"/>
<button name="case_pending" string="Pending" states="open" type="object" icon="gtk-media-pause" groups="base.group_no_one"/>
<button name="case_escalate" string="Escalate" states="open,pending" type="object" groups="base.group_extended" icon="gtk-go-up" />
<button name="case_reset" string="Reset to Draft" states="done,cancel" type="object" icon="gtk-convert" />
<button name="case_reset" string="Reset to Draft" states="done,cancel" type="object" icon="gtk-convert" groups="base.group_no_one"/>
<div class="oe_right">
<field name="state" nolabel="1" widget="statusbar" statusbar_visible="draft,open,done" statusbar_colors='{"pending":"blue"}'/>
<field name="state" nolabel="1" widget="statusbar" statusbar_visible="draft,open,done" statusbar_colors='{"pending":"blue"}' groups="base.group_no_one"/>
</div>
</div>
<sheet layout="auto">
@@ -192,13 +192,13 @@
icon="gtk-go-forward" />
<field name="section_id" invisible="context.get('invisible_section', True)" />
<field name="user_id" />
<field name="state" />
<field name="state" groups="base.group_no_one"/>
<button name="case_open" string="Open"
states="draft,pending" type="object"
icon="gtk-go-forward" />
icon="gtk-go-forward" groups="base.group_no_one"/>
<button name="case_close" string="Close"
states="open,draft,pending" type="object"
icon="gtk-close" />
icon="gtk-close" groups="base.group_no_one"/>
<button name="%(crm.action_crm_lead2opportunity_partner)d"
string="Convert to Opportunity"
states="draft,open,pending" icon="gtk-index"
@@ -233,7 +233,7 @@
<field name="type">kanban</field>
<field name="arch" type="xml">
<kanban default_group_by="stage_id">
<field name="state"/>
<field name="state" groups="base.group_no_one"/>
<field name="color"/>
<field name="priority"/>
<field name="planned_revenue" sum="Expected Revenues"/>
@@ -300,10 +300,10 @@
<a string="Add Internal Note" name="%(crm.action_crm_add_note)d" context="{'model': 'crm.lead' }" icon="terp-document-new" type="action"/>
</div>
<div class="oe_kanban_right">
<a name="case_mark_lost" string="Mark Lost" states="open,pending" type="object" icon="kanban-stop" />
<a name="case_pending" string="Pending" states="draft,open" type="object" icon="kanban-pause" />
<a name="case_open" string="Open" states="pending" type="object" icon="gtk-media-play" />
<a name="case_mark_won" string="Mark Won" states="open,pending" type="object" icon="kanban-apply" />
<a name="case_mark_lost" string="Mark Lost" states="open,pending" type="object" icon="kanban-stop" groups="base.group_no_one"/>
<a name="case_pending" string="Pending" states="draft,open" type="object" icon="kanban-pause" groups="base.group_no_one"/>
<a name="case_open" string="Open" states="pending" type="object" icon="gtk-media-play" groups="base.group_no_one"/>
<a name="case_mark_won" string="Mark Won" states="open,pending" type="object" icon="kanban-apply" groups="base.group_no_one"/>
</div>
<br class="oe_kanban_clear"/>
</div>
+1
View File
@@ -143,6 +143,7 @@
<field name="sequence"/>
<field name="name"/>
<field name="probability"/>
<field name="state"/>
</tree>
</field>
</record>