python - Overriding OpenERP constraints -
i want write module overrides 1 of constraints on model object, overriding constraint method doesn't work. override of method never gets called, because openerp uses own inheritance mechanism.
i'm trying make rules sign in / sign out actions little more flexible in hr_timesheet_sheet
module employees can record hours on previous day after they've signed in today. that, want override hr.attendance
constraint on action
field , allow changes, perform check @ timesheet level attendance actions in logical sequence.
i found hr.attendance
constraint.
def _altern_si_so(self, cr, uid, ids, context=none): """ alternance sign_in/sign_out check. previous (if exists) must of opposite action. next (if exists) must of opposite action. """ att in self.browse(cr, uid, ids, context=context): # search , browse first previous , first next records prev_att_ids = self.search(cr, uid, [('employee_id', '=', att.employee_id.id), ('name', '<', att.name), ('action', 'in', ('sign_in', 'sign_out'))], limit=1, order='name desc') next_add_ids = self.search(cr, uid, [('employee_id', '=', att.employee_id.id), ('name', '>', att.name), ('action', 'in', ('sign_in', 'sign_out'))], limit=1, order='name asc') prev_atts = self.browse(cr, uid, prev_att_ids, context=context) next_atts = self.browse(cr, uid, next_add_ids, context=context) # check alternance, return false if @ least 1 condition not satisfied if prev_atts , prev_atts[0].action == att.action: # previous exists , same action return false if next_atts , next_atts[0].action == att.action: # next exists , same action return false if (not prev_atts) , (not next_atts) , att.action != 'sign_in': # first attendance must sign_in return false return true _constraints = [(_altern_si_so, 'error: sign in (resp. sign out) must follow sign out (resp. sign in)', ['action'])]
i tried overriding constraint method in module, version never got called.
def _altern_si_so(self, cr, uid, ids): """ implementing logic @ attendance level doesn't work, skip it, , check @ whole time sheet level. 's good!""" return true
i tried adding own constraint on same field, called both versions , base module's constraint reject save.
i found bug on launchpad describes problem i'm having , fix. turns out can override constraints now, it's fiddly. have declare own constraint on same field same function name base module. , call constraint instead of base version.
here's my module overrides hr_attendance
constraint on actions , allows combination.
class hr_attendance(osv.osv): _inherit = 'hr.attendance' def _altern_si_so(self, cr, uid, ids): """ implementing logic @ attendance level doesn't work, skip it, , check @ whole time sheet level. 's good!""" return true _constraints = [(_altern_si_so, 'error: should never see message.', ['action'])]
Comments
Post a Comment