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