[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.
This commit is contained in:
Jeremy Kersten
2017-08-25 15:51:41 +02:00
parent 193707632d
commit 71bb9a09ff
2 changed files with 13 additions and 2 deletions
+2 -2
View File
@@ -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.'))
@@ -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.