Use function name in workflow instead of python code

This commit is contained in:
Nicolas Évrard committed 2011-08-11 16:34:35 +02:00
1 parent 973dee4c97
commit bf5869495e
2 files changed
+33 -24

No files matched your search

+28 -13
View File
@@ -188,19 +188,6 @@ class SaleOpportunity(ModelWorkflow, ModelSQL, ModelView):
res['payment_term']).rec_name
return res
def set_end_date(self, opportunity_id, state):
"""
This will fill the end_date for a lead/opportunity and change the state
:param opportunity_id: the id of the opportunity
:param state: the target state
"""
date_obj = Pool().get('ir.date')
self.write(opportunity_id, {
'end_date': date_obj.today(),
'state': state,
})
def button_lead(self, ids):
self.workflow_trigger_create(ids)
return True
@@ -275,6 +262,34 @@ class SaleOpportunity(ModelWorkflow, ModelSQL, ModelView):
})
return sale_id
def wkf_lead(self, opportunity):
self.write(opportunity.id, {'state': 'lead'})
def wkf_opportunity(self, opportunity):
self.write(opportunity.id, {'state': 'opportunity'})
def wkf_converted(self, opportunity):
date_obj = Pool().get('ir.date')
self.write(opportunity.id, {
'end_date': date_obj.today(),
'state': 'converted',
})
self.create_sale(opportunity.id)
def wkf_cancelled(self, opportunity):
date_obj = Pool().get('ir.date')
self.write(opportunity.id, {
'end_date': date_obj.today(),
'state': 'cancelled',
})
def wkf_lost(self, opportunity):
date_obj = Pool().get('ir.date')
self.write(opportunity.id, {
'end_date': date_obj.today(),
'state': 'lost',
})
SaleOpportunity()
+5 -11
View File
@@ -251,36 +251,30 @@
<record model="workflow.activity" id="opportunity_activity_lead">
<field name="name">Lead</field>
<field name="workflow" ref="opportunity_workflow"/>
<field name="kind">function</field>
<field name="action">write({'state': 'lead'})</field>
<field name="method">wkf_lead</field>
<field name="flow_start" eval="True"/>
</record>
<record model="workflow.activity" id="opportunity_activity_opportunity">
<field name="name">Opportunity</field>
<field name="workflow" ref="opportunity_workflow"/>
<field name="kind">function</field>
<field name="action">write({'state': 'opportunity'})</field>
<field name="method">wkf_opportunity</field>
</record>
<record model="workflow.activity" id="opportunity_activity_converted">
<field name="name">Converted</field>
<field name="workflow" ref="opportunity_workflow"/>
<field name="kind">function</field>
<field name="action">set_end_date('converted')
create_sale()</field>
<field name="method">wkf_converted</field>
<field name="flow_stop" eval="True"/>
</record>
<record model="workflow.activity" id="opportunity_activity_cancelled">
<field name="name">Cancelled</field>
<field name="workflow" ref="opportunity_workflow"/>
<field name="kind">function</field>
<field name="action">set_end_date('cancelled')</field>
<field name="method">wkf_cancelled</field>
<field name="flow_stop" eval="True"/>
</record>
<record model="workflow.activity" id="opportunity_activity_lost">
<field name="name">Lost</field>
<field name="workflow" ref="opportunity_workflow"/>
<field name="kind">function</field>
<field name="action">set_end_date('lost')</field>
<field name="method">wkf_lost</field>
<field name="flow_stop" eval="True"/>
</record>