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.

3

How do I add new state and change the workflow of Purchase Order? [Closed]

By
Anabela Damas
on 3/8/13, 1:50 PM 9,227 views

The Question has been closed

by
Anabela Damas
on 04/19/2013 14:59:51

Hi,

I need to change the workflow of Purchase Order, but I want to do a simple module just to do that.

I don't know how to add a new state to Purchase Order, I want to do it in the right way by using inherit but how do I add just a new state?

And then, when I have the new state how do I do the changes to the workflow?

Thanks all!

8

Mohammad Alhashash

--Mohammad Alhashash--
2075
| 5 5 8
Giza, Egypt
--Mohammad Alhashash--

Developer

Mohammad Alhashash
On 3/8/13, 4:24 PM

You need to inherit purchase.order and redefine the state field by adding or removing states. The following example adds new_state state:

class purchase_order(osv.osv):
   _inherit = 'purchase.order'
   STATE_SELECTION = [
        ('new_state', 'New State'),
        ('draft', 'Draft PO'),
        ('sent', 'RFQ Sent'),
        ('confirmed', 'Waiting Approval'),
        ('approved', 'Purchase Order'),
        ('except_picking', 'Shipping Exception'),
        ('except_invoice', 'Invoice Exception'),
        ('done', 'Done'),
        ('cancel', 'Cancelled')
    ]
   _columns = {
       'state': fields.selection(STATE_SELECTION, 'Status', readonly=True, help="The status of the purchase order or the quotation request. A quotation is a purchase order in a 'Draft' status. Then the order has to be confirmed by the user, the status switch to 'Confirmed'. Then the supplier must confirm the order to change the status to 'Approved'. When the purchase order is paid and received, the status becomes 'Done'. If a cancel action occurs in the invoice or in the reception of goods, the status becomes in exception.", select=True),
   }
sale_order()

check this question about sales order for a possible issue if other modules are also modifying the state field .

To modify the workflow, you can add new workflow items or modify existing items using xml records that reference purchase module records. Note that you need to add module_name. prefix to any id defined in the module you are modifying. The following example adds a new activity and modifies trans_sent_confirmed transition to the purchase order:

    <record id="act_new_state" model="workflow.activity">
        <field name="wkf_id" ref="purchase.purchase_order"/>
        <field name="name">new_state</field>
        <field name="kind">function</field>
        <field name="action">write({'state':'new_state'})</field>
    </record>
    <record id="purchase.trans_sent_confirmed" model="workflow.transition">
        <field name="act_from" ref="purchase.act_sent"/>
        <field name="act_to" ref="act_new_state"/>
        <field name="signal">purchase_confirm</field>
    </record>

Thanks! But I created a new module to do my changes, and in the file /addons/mymodule/mymodule_workflw.xml I've put the last code that you gave me, I had created in the views the button to change the state, but can't put the purchase order with my new_state! =(

Versão Integral, Anabela Damas
on 3/14/13, 4:16 PM

I've tried this code in /addons/purchase/purchase_workflow.xml and everything is ok. But now I wanted to put the code into my module, I've tried but I couldn't make this work. Probably the problem is ref="purchase_order.act_sent" and/or record id="purchase_order.trans_sent_confirmed" and/or ref="purchase_order.purchase_order"... Do you know what's wrong?

Versão Integral, Anabela Damas
on 3/15/13, 9:22 AM

Yes, you are right. The module name is purchase not purchase_order. I updated the answer.

Mohammad Alhashash
on 3/15/13, 11:35 AM

Still don't work =S In your code I just change this <field name="signal">purchase_confirm</field> to <field name="signal">purchase_received</field>. And in addons/mymodule/mymodule_view.xml : <record id="purchase_order_form_change" model="ir.ui.view"> <field name="name">purchase.order.form.change</field> <field name="model">purchase.order</field> <field name="inherit_id" ref="purchase.purchase_order_form"/> <field name="arch" type="xml"> <button name="purchase_confirm" states="sent" position="replace"> <button name="purchase_confirm" states="sent" string="Confirm Order"/>

Versão Integral, Anabela Damas
on 3/15/13, 1:06 PM
<button name="purchase_received" states="sent" string="Received PQ" class="oe_highlight"/>

</button> Am I missing something with my purchase_received? Do I have to declare it in some file?

Thanks for everything!

Versão Integral, Anabela Damas
on 3/15/13, 1:08 PM

I've discovered what was missing... I've totally forget to declare mymodule/mymodule_workflow.xml in mymodule/__openerp__.py... Thanks for all the help!

Versão Integral, Anabela Damas
on 3/15/13, 3:44 PM

About This Community

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

Question tools

1 follower(s)

Stats

Asked: 3/8/13, 1:50 PM
Seen: 9227 times
Last updated: 8/8/16, 9:15 AM