Skip to Content
Menu
This question has been flagged
2 Replies
6001 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.

Avatar
Discard
Best Answer

This app is good job for workflow   https://www.odoo.com/apps/modules/10.0/wkf_powerful/

Avatar
Discard
Author Best Answer

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.

Avatar
Discard
Related Posts Replies Views Activity
0
Dec 17
4753
1
Dec 24
49
1
Dec 24
22
1
Nov 24
52
1
Aug 23
1372