From 71bb9a09ffa00a8186edea3eb47478fffe70ad5a Mon Sep 17 00:00:00 2001 From: Jeremy Kersten Date: Fri, 25 Aug 2017 14:13:11 +0200 Subject: [PATCH] [FIX] sale_timesheet: don't block th edition of timesheet if prepaid. In case where the product is of invoice_type 'order' and not 'delivery', we allow the user to edit the anlaytics lines / timesheet. Previously, an employee was unable to edit an timesheet line once saved. When you work on prepaid pack / long task, it is frequent to edit existing timesheet line. --- addons/sale_timesheet/models/account.py | 4 ++-- addons/sale_timesheet/tests/test_timesheet_revenue.py | 11 +++++++++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/addons/sale_timesheet/models/account.py b/addons/sale_timesheet/models/account.py index 1f1737e86ef..07c70419b89 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 self.filtered(lambda timesheet: timesheet.timesheet_invoice_id): + # 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): 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 c1f13ee9b51..1fa0b40fcd2 100644 --- a/addons/sale_timesheet/tests/test_timesheet_revenue.py +++ b/addons/sale_timesheet/tests/test_timesheet_revenue.py @@ -2,6 +2,7 @@ # Part of Odoo. See LICENSE file for full copyright and licensing details. from odoo.addons.sale.tests.test_sale_common import TestSale +from odoo.exceptions import UserError from odoo.tools import float_compare, float_repr @@ -185,6 +186,16 @@ 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 + 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 + timesheet3.write(dict(unit_amount=10)) + self.assertEquals(timesheet3.unit_amount, 10) + + def test_revenue_multi_currency(self): """ Create a SO with 2 lines : one for a delivered service, one for a ordered service. Confirm and invoice it. For this, we use a partner having a DIFFERENT currency from the current company.