[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
This commit is contained in:
@@ -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.'))
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user