hr_timesheet_sheet: can not write attendance

Bug #798190 reported by Wolfgang Taferner (TaPo-IT)
8
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Odoo Addons (MOVED TO GITHUB)
Fix Released
Low
OpenERP R&D Addons Team 3

Bug Description

Exception is thrown when there is no sheet_id linked

    def write(self, cr, uid, ids, vals, context=None):
        if context is None:
            context = {}
        self._check(cr, uid, ids) <-- exception
        res = super(hr_attendance,self).write(cr, uid, ids, vals, context=context)
        .
        .
        .

_check should be adapted like other methods

    def _check(self, cr, uid, ids, context=None):
        if context is None:
            context = {}
        if 'sheet_id' in context:
            for att in self.browse(cr, uid, ids, context=context):
                if att.sheet_id and att.sheet_id.state not in ('draft', 'new'):
                    raise osv.except_osv(_('Error !'), _('You cannot modify an entry in a confirmed timesheet !'))
        return True

Related branches

Revision history for this message
Vishal Parmar(Open ERP) (vpa-openerp) wrote :

Hello Wolfgang Taferner,

I have checked your issue but all are working fine at my end.

From current behavior you can not modify your time sheet when it's become in confirm and done state.

So In confirm and done state you can not modify your time sheet and when you tried to modify it you

will face this type of error message 'You cannot modify an entry in a confirmed timesheet !'

which is current behavior and it is working fine,.

For your more reference I have attached video so would you please check it and notify us where you faced the problem.

Thanks and waiting for your reply.

Revision history for this message
Vishal Parmar(Open ERP) (vpa-openerp) wrote :
Changed in openobject-addons:
status: New → Incomplete
Revision history for this message
Wolfgang Taferner (TaPo-IT) (w.taferner) wrote :

Hi Vishal,
Thank you for the video ;-) I guess my description was really incomplete.

It does throw an exception when you call the write method from another inherited object (in my case: project.task.work). I could not reproduce it yet, but I think I may know the source of the "problem" now.

When you call object.browse(cr, uid, ids) sometimes you get back an object of type openerp.osv.orm.browse_record which does then throw an exception in a for loop (no list) instead of an object of type openerp.osv.orm.browse_record_list which is the intended object for a loop.

I do not know if this behavior of the general method browse is correct but it does stop the code flow under certain conditions (probably when there are no results) which happened somewhere else in my code as well.
I solved it for myself to check before looping an object if it is an instance of osv.orm.browse_record_list.

Is it correct that you can get back an object of type osv.orm.browse_record when you call self.browse?

If so what is the advantage to get back such an object?

Revision history for this message
Wolfgang Taferner (TaPo-IT) (w.taferner) wrote :

Ok, I just got the exception with the _check function in the hr_timesheet_sheet again and this time it is the method unlink of inherited hr.attendance in hr_timesheet_sheet which also calls _check.

_check is imho deprecated anyway because there is a constraint in the inherited class hr_timesheet_line which checks the state.

Here is my inherited (hr.attendance) def and the exception:

    def unlink(self, cr, uid, ids, context=None):
        if context == None:
            context = {}
        context['handling'] = 'delete'
        context['hint'] = '\n\nPlease delete the task work first!'
        self.check_linked_work (cr, uid, ids, context=context)

        return super(hr_attendance,self).unlink(cr, uid, ids, context=context)

[2011-06-22 11:29:32,382][?] WARNING:browse_record:[01]: Field '0' does not exist in object 'browse_record(hr.attendance, 206)':
[2011-06-22 11:29:32,382][?] WARNING:browse_record:[02]: None
[2011-06-22 11:29:32,383][?] ERROR:web-services:Uncaught exception
Traceback (most recent call last):
  File "/data/launchpad/openobject-server/trunk/openerp/osv/osv.py", line 120, in wrapper
    return f(self, dbname, *args, **kwargs)
  File "/data/launchpad/openobject-server/trunk/openerp/osv/osv.py", line 174, in execute
    res = self.execute_cr(cr, uid, obj, method, *args, **kw)
  File "/data/launchpad/openobject-server/trunk/openerp/osv/osv.py", line 165, in execute_cr
    return getattr(object, method)(cr, uid, *args, **kw)
  File "/current/server/addons/project_timesheet/project_timesheet.py", line 185, in unlink
    self.pool.get('project.task.work').unlink(cr, uid, work_ids, *args, **kwargs)
  File "/current/server/addons/hr_project/hr_project.py", line 241, in unlink
    attendance_obj.unlink(cr, uid, start_id)
  File "/current/server/addons/hr_project/hr_project.py", line 407, in unlink
    return super(hr_attendance,self).unlink(cr, uid, ids, context=context)
  File "/current/server/addons/hr_timesheet_sheet/hr_timesheet_sheet.py", line 622, in unlink
    self._check(cr, uid, ids)
  File "/current/server/addons/hr_timesheet_sheet/hr_timesheet_sheet.py", line 638, in _check
    for att in self.browse(cr, uid, ids):
  File "/data/launchpad/openobject-server/trunk/openerp/osv/orm.py", line 223, in __getitem__
    name, self))
KeyError: "Field '0' does not exist in object 'browse_record(hr.attendance, 206)'"

Revision history for this message
Wolfgang Taferner (TaPo-IT) (w.taferner) wrote :

My solution would be to change all _check def in hr_timesheet_sheet like this:

    def _check(self, cr, uid, ids):
        if isinstance(self.browse(cr, uid, ids), osv.orm.browse_record_list):
            for att in self.browse(cr, uid, ids):
                if att.sheet_id and att.sheet_id.state not in ('draft', 'new'):
                    raise osv.except_osv(_('Error !'), _('You can not modify an entry in a confirmed timesheet !'))
        return True

The problem seems to be when there is no sheet_id linked yet to hr.attendance as I mentioned in the bug report :-)

Revision history for this message
Amit Parik (amit-parik) wrote :

Hello,

The problem is occurs only when you have call the write method via script and passed the integer value in ids not the list.

I have attached a script which have run the write method and when you run this script you have faced the problem.

So I am confirming this issue.

Thanks.

Revision history for this message
Amit Parik (amit-parik) wrote :
Changed in openobject-addons:
assignee: nobody → OpenERP R&D Addons Team 3 (openerp-dev-addons3)
importance: Undecided → Low
status: Incomplete → Confirmed
Changed in openobject-addons:
milestone: none → 6.1
Changed in openobject-addons:
status: Confirmed → In Progress
Changed in openobject-addons:
status: In Progress → Fix Committed
Revision history for this message
Bharat Devnani (Open ERP) (bde-openerp) wrote :

Hello Wolfgang Taferner,

The Revision ID and Number of this bug are as follows:

Revision ID : bde@tiny2-desktop-20110701094510-x6ysb65d71blszkd
Revision Number : 4839

Thanks for Reporting, the solution of this bug will be merged in addons soon.

Thanks & Regards,
Devnani Bharat R.

tfr (Openerp) (tfr)
Changed in openobject-addons:
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.