Odoo 9的工作流程

时间:2017-01-12 10:29:19

标签: python xml openerp workflow

我创建了一个字段 state 的模块,该模块具有以下属性“draft”,“open”,“paid”,“cancel”。在xml中,我有一个按钮确认,当用户点击此按钮时,状态必须从“草稿”更改为“打开”。但是,代码不起作用,状态不变。任何线索? 感谢

以下是我的代码:

(1)module.py

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

def action_draft(self, cr, uid, ids, context=None):
        return self.write(cr, uid, ids, {'state':'draft'})

def action_open(self , cr, uid, ids, context=None):
        return self.write(cr, uid, ids, {'state':'open'})

def action_paid(self , cr, uid, ids, context=None):
        return self.write(cr, uid, ids, {'state':'paid'})

def action_cancel(self , cr, uid, ids, context=None):
        return self.write(cr, uid, ids, {'state':'cancel'})

(2)module.xml

<header>

            <button name="button_confirm" string="Confirm Application"  states="draft" class="oe_highlight" type="action"/>

            <button name="button_email"  string="Send by Email" states="open" class="oe_highlight" type="action"/>

            <button name="button_print" string="Print" states="open" class="oe_highlight" type="action"/>

            <button name="%(test9_receipt_action)d" string="Register Payment" states="open" class="oe_highlight" type="action"/>

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

            <button name="button_cancel" type="action" 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_land2">
            <field name="name">m.wkf.land2</field>
            <field name="osv">m.land2</field>
            <field name="on_create">True</field>
        </record>

        <!-- Draft-->

        <record model="workflow.activity" id="land_draft">
            <field name="name">draft</field>
            <field name="wkf_id" ref="wkf_land2"/>
            <field name="flow_start" eval="True"/>
        </record>

        <!-- Awaiting Payments-->
        <record model="workflow.activity" id="land_open">
            <field name="name">open</field>
            <field name="wkf_id" ref="wkf_land2"/>
            <field name="kind">function</field>
            <field name="action">write({'state':'open'})</field>
        </record>


        <!--Paid-->
        <record model="workflow.activity" id="land_paid">
            <field name="name">paid</field>
            <field name="wkf_id" ref="wkf_land2"/>
            <field name="kind">function</field>
            <field name="action">write({'state':'paid'})</field>
            <field name="flow_stop">True</field>
        </record>

        <!--Cancel-->
        <record model="workflow.activity" id="land_cancel">
            <field name="name">cancel</field>
            <field name="wkf_id" ref="wkf_land2"/>
            <field name="kind">function</field>
            <field name="action">write({'state':'cancel'})</field>
            <field name="flow_stop">True</field>
        </record>



        <!-- WORKFLOW TRANSITION -->


        <record model="workflow.transition" id="land_draft_to_open">
            <field name="act_from" ref="land_draft"/>
            <field name="act_to" ref="land_open"/>
            <field name="condition">True</field>
            <field name="signal">button_confirm</field>
        </record>

        <record model="workflow.transition" id="land_open_to_paid">
            <field name="act_from" ref="land_open"/>
            <field name="act_to" ref="land_paid"/>
            <field name="condition">True</field>
            <field name="signal">button_register</field>
        </record>

        <record model="workflow.transition" id="land_paid_to_cancel">
            <field name="act_from" ref="land_paid"/>
            <field name="act_to" ref="land_cancel"/>
            <field name="signal">button_cancel</field>
            <field name="condition">True</field>
        </record>

        <record model="workflow.transition" id="land_draft_to_cancel">
            <field name="act_from" ref="land_draft"/>
            <field name="act_to" ref="land_cancel"/>
            <field name="signal">button_cancel</field>
            <field name="condition">True</field>
        </record>
        <record model="workflow.transition" id="land_open_to_cancel">
            <field name="act_from" ref="land_open"/>
            <field name="act_to" ref="land_cancel"/>
            <field name="signal">button_cancel</field>
            <field name="condition">True</field>
        </record>
    </data>
</openerp>

1 个答案:

答案 0 :(得分:1)

按钮的名称应与您的功能名称相同。

示例:

time

...button name="action_cancel" type="action" string="Cancel Applicat...