From 5f45e7ca96f34fa8e904cdaa46576b60ffcfb477 Mon Sep 17 00:00:00 2001 From: David Monjoie Date: Thu, 26 Feb 2015 15:42:01 +0100 Subject: [PATCH] [FIX] hr_timesheet_sheet: properly unlink timesheets when deleting a timesheet_sheet Adaptation of https://github.com/acsone/odoo/commit/afe4a97d037b4075c8cd0514b6d1b829e1208629, but we properly unlink the timesheet lines themselves instead of going for the account.analytic.lines like the original commit proposition did. Actually, the unlink method of hr.analytic.timesheet already unlinks the corresponding acount.analytic.line, but those records were previously deleted via ondelete='cascade', which didn't trigger the unlink method at all, so the associated analytic lines were not deleted accordingly. Fixes opw 628256. --- addons/hr_timesheet_sheet/hr_timesheet_sheet.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/addons/hr_timesheet_sheet/hr_timesheet_sheet.py b/addons/hr_timesheet_sheet/hr_timesheet_sheet.py index f59bceb9a82..d2d0d0a0533 100644 --- a/addons/hr_timesheet_sheet/hr_timesheet_sheet.py +++ b/addons/hr_timesheet_sheet/hr_timesheet_sheet.py @@ -256,6 +256,14 @@ class hr_timesheet_sheet(osv.osv): raise osv.except_osv(_('Invalid Action!'), _('You cannot delete a timesheet which is already confirmed.')) elif sheet['total_attendance'] <> 0.00: raise osv.except_osv(_('Invalid Action!'), _('You cannot delete a timesheet which have attendance entries.')) + + toremove = [] + analytic_timesheet = self.pool.get('hr.analytic.timesheet') + for sheet in self.browse(cr, uid, ids, context=context): + for timesheet in sheet.timesheet_ids: + toremove.append(timesheet.id) + analytic_timesheet.unlink(cr, uid, toremove, context=context) + return super(hr_timesheet_sheet, self).unlink(cr, uid, ids, context=context) def onchange_employee_id(self, cr, uid, ids, employee_id, context=None):