Odoo Help


How can I solve this AttributeError?

Barry Achterberg
on 11/4/13, 9:41 AM 1,618 views

Hello, I am editing the 'hr_timesheet_sheet' model and I am trying to create a method that changes the state of the workflow 'hr_timesheet_sheet'. When I click the button button_cancel, I want to call the method button_cancel, but it seems like it can't find my method however I defined it in hr_timesheet_sheet.py

When I click the button it says: AttributeError: 'hr_timesheet_sheet.sheet' object has no attribute 'button_cancel'.

I dont know what I am doing wrong since the button type="object" and the method is defined in hr_timesheet_sheet.py here is my code, maybe someone else can see why my method button_cancel isn't found or that my method is wrong defined. I Appreciate any help!


<form string="Timesheet" version="7.0">
                <button name="button_confirm" states="draft" string="Submit to Manager" type="object" class="oe_highlight"/>
                <button name="done" states="confirm" string="Approve" type="workflow" groups="base.group_hr_user" class="oe_highlight"/>
                <button name="action_set_to_draft" states="done" string="Set to Draft" type="object" class="oe_highlight"/>
                <button name="button_cancel" states="confirm" string="Refuse" type="object" class="oe_highlight"/>
                <field name="state" widget="statusbar" statusbar_visible="new,confirm,done"/>


def button_confirm(self, cr, uid, ids, context=None):
    for sheet in self.browse(cr, uid, ids, context=context):
        if sheet.employee_id and sheet.employee_id.parent_id and sheet.employee_id.parent_id.user_id:
            self.message_subscribe_users(cr, uid, [sheet.id], user_ids=[sheet.employee_id.parent_id.user_id.id], context=context)
        self.check_employee_attendance_state(cr, uid, sheet.id, context=context)
        di = sheet.user_id.company_id.timesheet_max_difference
        if (abs(sheet.total_difference) < di) or not di:
            wf_service = netsvc.LocalService("workflow")
            wf_service.trg_validate(uid, 'hr_timesheet_sheet.sheet', sheet.id, 'confirm', cr)
            raise osv.except_osv(_('Warning!'), _('Please verify that the total difference of the sheet is lower than %.2f.') %(di,))
    return True

def button_cancel(self, cr, uid, ids):
    self.write(cr, uid, ids, {'state': 'draft'})
    return True


<record id="wkf_timesheet" model="workflow">
        <field name="name">hr_timesheet_sheet.sheet</field>
        <field name="osv">hr_timesheet_sheet.sheet</field>
        <field name="on_create">True</field>

    <record id="act_new" model="workflow.activity">
        <field name="wkf_id" ref="wkf_timesheet"/>
        <field name="name">new</field>
        <field name="kind">function</field>
        <field name="action">write({'state':'new'})</field>
        <field name="flow_start">True</field>
    <record id="act_draft" model="workflow.activity">
        <field name="wkf_id" ref="wkf_timesheet"/>
        <field name="name">draft</field>
        <field name="kind">function</field>
        <field name="action">write({'state':'draft'})</field>
    <record id="act_confirm" model="workflow.activity">
        <field name="wkf_id" ref="wkf_timesheet"/>
        <field name="name">confirm</field>
        <field name="kind">function</field>
        <field name="action">write({'state':'confirm'})</field>
    <record id="act_done" model="workflow.activity">
        <field name="wkf_id" ref="wkf_timesheet"/>
        <field name="name">done</field>
        <field name="kind">function</field>
        <field name="action">write({'state':'done'})</field>
        <field name="flow_stop">True</field>

    <record id="t0" model="workflow.transition">
        <field name="act_from" ref="act_new"/>
        <field name="act_to" ref="act_draft"/>
        <field name="group_id" ref="base.group_user"/>
    <record id="t1" model="workflow.transition">
        <field name="act_from" ref="act_draft"/>
        <field name="act_to" ref="act_confirm"/>
        <field name="signal">confirm</field>
        <field name="group_id" ref="base.group_user"/>
    <record id="t2" model="workflow.transition">
        <field name="act_from" ref="act_confirm"/>
        <field name="act_to" ref="act_done"/>
        <field name="signal">done</field>
        <field name="group_id" ref="base.group_user"/>
    <record id="t3" model="workflow.transition">
        <field name="act_from" ref="act_confirm"/>
        <field name="act_to" ref="act_draft"/>
        <field name="signal">cancel</field>
        <field name="group_id" ref="base.group_user"/>

About This Community

This platform 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.


Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

0 follower(s)


Asked: 11/4/13, 9:41 AM
Seen: 1618 times
Last updated: 3/16/15, 8:10 AM