Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

1

[V8/9] Customer record approval

By
Andreas
on 10/14/15, 11:19 AM 342 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 

1

Akhil P Sivan

--Akhil P Sivan--
3423
| 5 3 6
Kochi, India
--Akhil P Sivan--

Interested in exploring Odoo both technically & functionality wise.

email-id : akhilpsivan01@gmail.com

Akhil P Sivan
On 10/15/15, 7:24 AM

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!

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

Andreas
on 10/17/15, 1:35 PM

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.

Andreas
on 10/17/15, 1:43 PM

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.

Akhil P Sivan
on 10/18/15, 6:01 PM

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.

Akhil P Sivan
on 10/19/15, 6:17 AM

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

Asked: 10/14/15, 11:19 AM
Seen: 342 times
Last updated: 10/20/15, 10:41 AM