Skip to Content
Menu
This question has been flagged
3984 Views

Hello,

I have created a module and have added the field state with "draft", "open" , "paid", "cancel" attributes. I have also created the workflow.xml and the methods. However, the code is not working! When I clicked on the Confirm Application button, the state does not change from "draft" to "open".

Here are my codes:


(1) module.py


'state'  : fields.selection([('draft', "New"), ('open', "Awaiting Payments"), ('paid', "Paid"), ('cancel', "Cancelled")], 'Status', default='draft'),


@api.multi   

def action_draft(self):
        self.write({'state': 'draft'})           

@api.multi   

def action_open(self):
        self.state = 'open'       

@api.multi   

def action_paid(self):
        self.state = 'paid'        

@api.multi   

def action_cancel(self):
        self.state = 'cancel'



(2) module_view.xml


<header>                   

<button name="button_confirm"            string="Confirm Application"            type="workflow"            states="draft"/>                                            <button name="button_email" type="workflow"            string="Send by Email" states="open" class="oe_highlight"/>                                           

<button name="button_print" type="workflow"            string="Print" states="open"            class="oe_highlight"/>                                            <button name="button_register" type="workflow"            string="Register Payment" states="open"            class="oe_highlight"/>                      

  <button name="button_refund" type="workflow"            string="Refund Invoice" states="paid"            class="oe_highlight"/>                       

<button name="button_cancel" type="workflow"            string="Cancel Application" states="draft,open,paid"            class="oe_highlight"/>                                                                                       

<field name="state" widget="statusbar" statusbar_visible="draft,open,paid,cancel" statusbar_colors='{"confirmed":"blue"}'/>       

</header>



(3) workflow.xml


<openerp>    <data>       

<record model="workflow" id="wkf_session">            <field name="name">land6.workflow</field>            <field name="osv">land6.test</field>            <field name="on_create">True</field>        </record>
        <record model="workflow.activity" id="draft">            <field name="name">draft</field>            <field name="wkf_id" ref="wkf_session"/>            <field name="flow_start" eval="True"/>            <field name="kind">function</field>            <field name="action">action_draft()</field>        </record>        <record model="workflow.activity" id="open">            <field name="name">open</field>            <field name="wkf_id" ref="wkf_session"/>            <field name="kind">function</field>            <field name="action">action_open()</field>        </record>                <record model="workflow.activity" id="paid">            <field name="name">paid</field>            <field name="wkf_id" ref="wkf_session"/>            <field name="kind">function</field>            <field name="action">action_paid()</field>            <field name="flow_stop">True</field>        </record>
                <record model="workflow.activity" id="cancel">            <field name="name">cancel</field>            <field name="wkf_id" ref="wkf_session"/>            <field name="kind">function</field>            <field name="action">action_cancel()</field>            <field name="flow_stop">True</field>        </record>
                                                <record model="workflow.transition" id="land_draft_to_open">            <field name="act_from" ref="draft"/>            <field name="act_to" ref="open"/>            <field name="signal">button_confirm</field>            <field name="condition">True</field>        </record>               

<record model="workflow.transition" id="land_open_to_paid">           

<field name="act_from" ref="open"/>           

<field name="act_to" ref="paid"/>           

<field name="signal">button_register</field>       

</record>              

  <record model="workflow.transition" id="land_paid_to_cancel">           

<field name="act_from" ref="paid"/>         

   <field name="act_to" ref="cancel"/>           

<field name="signal">button_cancel</field>       

</record>             

   <record model="workflow.transition" id="land_draft_to_cancel">           

<field name="act_from" ref="draft"/>           

<field name="act_to" ref="cancel"/>           

<field name="signal">button_cancel</field>        </record>       

<record model="workflow.transition" id="land_open_to_cancel">           

<field name="act_from" ref="open"/>          

  <field name="act_to" ref="cancel"/>           

<field name="signal">button_cancel</field>       

</record>   

</data>

</openerp>


Avatar
Discard
Related Posts Replies Views Activity
0
Jun 16
2768
1
Mar 17
4261
0
Oct 16
3127
0
May 16
2954
0
Sep 23
496