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.

0

How to modify hr.wkf.expenses workflow to add new state?

By
Mariusz Mizgier
on 11/25/13, 8:54 AM 2,027 views

I've made files such as hr_expense_board_confirmation.py:

class hr_expense_expense(osv.osv):

_inherit = ['hr.expense.expense']
_columns = {
    'state': fields.selection([
        ('draft', 'New'),
        ('cancelled', 'Refused'),
        ('confirm', 'Waiting Approval'),
        ('waiting', 'Waiting for Chairman Approval')
        ('accepted', 'Approved'),
        ('done', 'Waiting Payment'),
        ('paid', 'Paid'),
        ],
        'Status', readonly=True, track_visibility='onchange',
        help='When the expense request is created the status is \'Draft\'.\n It is confirmed by the user and request is sent to admin, the status is \'Waiting Confirmation\'.\
        \nIf the admin accepts it, the status is \'Accepted\'.\n If the accounting entries are made for the expense request, the status is \'Waiting Payment\'.'),

}

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

hr_expense_expense()

Then hr_expense_board_workflow.xml

    <record id="act_waiting" model="workflow.activity">
        <field name="wkf_id" ref="hr_expense.wkf_expenses"/>
        <field name="name">waiting</field>
        <field name="kind">function</field>
        <field name="action">expense_waiting()</field>
    </record>

    <record id="t3" model="workflow.transition">
        <field name="act_from" ref="hr_expense.act_accepted"/>
        <field name="act_to" ref="act_waiting"/>
        <field name="signal">waiting</field>
        <field name="group_id" ref="base.group_hr_user"/>
    </record>

    <record id="t5" model="workflow.transition">
        <field name="act_from" ref="act_waiting"/>
        <field name="act_to" ref="hr_expense.act_refused"/>
        <field name="signal">refuse</field>
        <field name="group_id" ref="base.group_hr_user"/>
    </record>

    <record id="t11" model="workflow.transition">
        <field name="act_from" ref="act_waiting"/>
        <field name="act_to" ref="hr_expense.act_done"/>
        <field name="signal">done</field>
        <field name="group_id" ref="base.group_hr_user"/>
    </record>

And finally hr_expense_board_view.xml

        <record model="ir.ui.view" id="hr_board_view">
        <field name="name">hr.expense.expense1</field>
        <field name="model">hr.expense.expense</field>
        <field name="inherit_id" ref="hr_expense.view_expenses_form"/>
        <field name="arch" type="xml">
            <header>
                <xpath expr="/form/header/button[@name='confirm']" position="replace">
                    <button name="confirm" states="draft" string="Submit to Manager" type="workflow" class="oe_highlight"/>
                </xpath>
                <xpath expr="/form/header/button[@name='validate']" position="replace">
                    <button name="validate" states="confirm" string="Approve" type="workflow" groups="base.group_hr_user" class="oe_highlight"/>
                </xpath>
                <xpath expr="/form/header/button[@name='refuse']" position="replace">
                    <button name="refuse" states="confirm,accepted, waiting" string="Refuse" type="workflow" groups="base.group_hr_user" />
                </xpath>
                <xpath expr="/form/header/button[@name='draft']" position="replace">
                    <button name="draft" states="confirm,cancelled" string="Set to Draft" type="workflow" groups="base.group_hr_user" />
                </xpath>                
                <xpath expr="/form/header/button[@name='done]" position="replace">
                    <button name="done" states="accepted" string="Generate Accounting Entries" type="workflow" groups="account.group_account_invoice" class="oe_highlight"/>
                </xpath>                    
                <button name="waiting" states="accepted" string="Confirmed by Chairman" type="workflow" groups="base.group_hr_user" class="oe_highlight" />
                <xpath expr="/form/header/field[@name='state']" position="replace">
                    <field name="state" widget="statusbar" statusbar_visible="draft,confirm,waiting,accepted,done,paid,cancelled" statusbar_colors='{"invoice_except":"red","waiting_date":"blue"}'/>   
                </xpath>                        
            </header>
        </field>
    </record>

After trying to push button 'Confirmed by Chairman', I get an error like this:

 File "", line 1, in <module>
 NameError: name 'expense_waiting' is not defined

What is the case? expense_waiting has been defined correctly, I believe. I know that status bar will be shown two times (that is a case I will follow after this bug can be eliminated). Any ideas would be very appreciated.

0
Mariusz Mizgier
On 11/25/13, 3:14 PM

Seems like _columns is not passed to hr.expense.expense - any idea why is that happening? If _columns are not passed, neither will expense_waiting will, but I have no clue, what is wrong here.

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: 11/25/13, 8:54 AM
Seen: 2027 times
Last updated: 3/16/15, 8:10 AM