This question has been flagged
1 Reply
3445 Views

Any possibility to add workflow for customer module?

This workflow having purpose to make approval for new record and modification that's applied.

Before customer record have approved state, customer will not able to started create quotation, opportunity etc.


Thanks.

Andreas 

Avatar
Discard
Best Answer

Hi,

You can add workflow to res.partner model. Inorder to have only approved customers in quotations, opportunity etc, later you can domain filter the many2one field using state = approved.

For eg, am adding just two states "New" and "Approved". Please try the following code:

in your python file:

class res_partner(models.Model):

_inherit = 'res.partner'

STATE_SELECTION = [
('new', 'New'),
('approved', 'Approved'),

]
state = fields.Selection(STATE_SELECTION, 'Status', readonly=True,
help="New customer created. "
"New Customer approved. ",
select=True,default='new')
@api.multi
def write(self, vals):

if self.state == 'approved':
vals.update({'state':'new'})

return super(res_partner, self).write(vals)

@api.multi
def approve_customer(self):
self.write({'state':'approved'})

in your workflow xml file:

<?xml version="1.0" encoding="utf-8"?><openerp>
<data>

<record id="customer_flow" model="workflow">
<field name="name">Custmer Workflow</field>
<field name="osv">res.partner</field>
<field name="on_create">True</field>
</record>

<record id="act_new" model="workflow.activity">
<field name="wkf_id" ref="customer_flow"/>
<field name="flow_start">True</field>
<field name="name">new</field>
</record>
<record id="act_approved" model="workflow.activity">
<field name="wkf_id" ref="customer_flow"/>
<field name="name">approved</field>
<field name="flow_stop">True</field>
</record>
<record id="trans_new_confirmed" model="workflow.transition">
<field name="act_from" ref="act_new"/>
<field name="act_to" ref="act_approved"/>
<field name="signal">customer_confirm</field>
</record>


</data>
</openerp>


in your xml view file:

	<record id="view_partner_form_with_states" model="ir.ui.view">
<field name="name">Add states to customer</field>
<field name="model">res.partner</field>
<field name="inherit_id" ref="base.view_partner_form"/>
<field name="arch" type="xml">

<sheet position="before">
<header>
<button name="approve_customer" states="new" type="object" string="Approve" class="oe_highlight" />
<field name="state" widget="statusbar" statusbar_visible="new,approved" statusbar_colors='{"new":"blue","approved":"blue"}' readonly="1" />
</header>
</sheet>
</field>
</record>

Hope this helps!

Avatar
Discard
Author

Hi Akhil P Sivan, that's great and thanks for your response. I already try your code, here my several question: 1. When I click approve button, there are no log for this action. For create or change, usually we saw log / note at the bottom side. 'Note by Administrator - 12:28 AM Partner created". How to add this function when click approved button. 2. When user change or edit the record, this record are back into New State or Draft state again. So, user need to approved those change, before continue. How to catch edit action or is there any mechanism to do that? 3. Is it possible when we have 2 workflow and 2 status bar. Let say for New record and approval process, 1 workflow. After new record approved, this become change request / modification, so there is 1 workflow again for Modification and Approval, also for status bar, will be shown modification and approval. Thanks and Regards, Andreas

Author

1 more, do you have any idea to setup approval button for several group or user only. So for approval only appear when state New and user level Manager. Thanks.

Hi Andreas, you can catch the edit action either by the write() or a boolean field. So you can do the changes approval. Its possible modify the workflow like you said, this is just an example to show you how it can be possible. Just refer purchase_workflow.xml and try to modify this according to your needs. You can use security groups to make Approve button visible only for manager. If my answer helps you, please do upvote.

Andreas, I have updated the answer. So when you edit the state goes back to "draft", which you can approve later. To make it visible only to Manager, you can use groups attribute on the button.