From f8694f14ccafa544462c0bd1fd0fa84b1b7a8be3 Mon Sep 17 00:00:00 2001 From: Jeremy Kersten Date: Wed, 30 Aug 2017 15:37:04 +0200 Subject: [PATCH] [FIX] sale_timesheet: fix case where self is multi Commit #71bb9a09f is wrong in case you write on several timesheet at the same time. Self is multi, when you have more than 1 timesheet, we need to check for each, if one is of type delivery --- addons/sale_timesheet/models/account.py | 4 ++-- addons/sale_timesheet/tests/test_timesheet_revenue.py | 9 +++++++-- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/addons/sale_timesheet/models/account.py b/addons/sale_timesheet/models/account.py index 07c70419b89..55683a33745 100644 --- a/addons/sale_timesheet/models/account.py +++ b/addons/sale_timesheet/models/account.py @@ -26,8 +26,8 @@ class AccountAnalyticLine(models.Model): @api.multi def write(self, values): - # prevent to update invoiced timesheets if product_id is not of type order - if self.so_line.product_id.invoice_policy != "order" and self.filtered(lambda timesheet: timesheet.timesheet_invoice_id): + # prevent to update invoiced timesheets if one line is of type delivery + if self.filtered(lambda aal: aal.so_line.product_id.invoice_policy == "delivery") and self.filtered(lambda timesheet: timesheet.timesheet_invoice_id): if any([field_name in values for field_name in ['unit_amount', 'employee_id', 'task_id', 'timesheet_revenue', 'so_line', 'amount', 'date']]): raise UserError(_('You can not modify already invoiced timesheets.')) diff --git a/addons/sale_timesheet/tests/test_timesheet_revenue.py b/addons/sale_timesheet/tests/test_timesheet_revenue.py index 1fa0b40fcd2..6f1533d3ca1 100644 --- a/addons/sale_timesheet/tests/test_timesheet_revenue.py +++ b/addons/sale_timesheet/tests/test_timesheet_revenue.py @@ -186,15 +186,20 @@ class TestSaleTimesheet(TestSale): self.assertEquals(timesheet2.timesheet_invoice_id, invoice) self.assertEquals(timesheet3.timesheet_invoice_id, invoice) - # check that analytic line for product 'ordered' can be altered + # check that analytic line for product 'delivery' cannot be altered with self.assertRaises(UserError): timesheet1.write(dict(unit_amount=10)) self.assertNotEquals(timesheet1.unit_amount, 10) - # check that analytic line for product 'delivered' cannot be altered + # check that analytic line for product 'ordered' can be altered timesheet3.write(dict(unit_amount=10)) self.assertEquals(timesheet3.unit_amount, 10) + # check that if at least 1 analytic line is for product 'delivery', it cannot be altered + with self.assertRaises(UserError): + (timesheet1 + timesheet3).write(dict(unit_amount=15)) + self.assertNotEquals(timesheet1.unit_amount, 15) + self.assertNotEquals(timesheet3.unit_amount, 15) def test_revenue_multi_currency(self): """ Create a SO with 2 lines : one for a delivered service, one for a ordered service. Confirm