[IMP] sale_timesheet: sale line of subtask

Before this commit, a subtask was forced to have the same SO line
than its mother.
We now want to make it updatable: the default value will be the one
from its mother, but the user can change it manually and set it to
whatever he want (it still should be a service SO line, belonging to
the same customer than the task).

Task #1857652
This commit is contained in:
jem-odoo
2018-08-02 16:12:39 +02:00
parent 17d0de306e
commit a628d80d5e
3 changed files with 24 additions and 26 deletions
+1 -23
View File
@@ -90,29 +90,13 @@ class ProjectTask(models.Model):
for task in self:
if task.sale_line_id:
if not task.sale_line_id.is_service or task.sale_line_id.is_expense:
raise ValidationError(_('You cannot link the order item %s - %s to this task because it is a re-invoiced expense.' % (task.sale_line_id.order_id.id, task.sale_line_id.product_id.name)))
@api.model
def create(self, values):
# sub task has the same so line than their parent
parent_id = values['parent_id'] if 'parent_id' in values else self.env.context.get('default_parent_id')
if parent_id:
values['sale_line_id'] = self.env['project.task'].browse(parent_id).sudo().sale_line_id.id
return super(ProjectTask, self).create(values)
raise ValidationError(_('You cannot link the order item %s - %s to this task because it is a re-invoiced expense.' % (task.sale_line_id.order_id.id, task.sale_line_id.product_id.name)))
@api.multi
def write(self, values):
# sub task has the same so line than their parent
if 'parent_id' in values:
values['sale_line_id'] = self.env['project.task'].browse(values['parent_id']).sudo().sale_line_id.id
result = super(ProjectTask, self).write(values)
# reassign SO line on related timesheet lines
if 'sale_line_id' in values:
# subtasks should have the same SO line than their mother
self.sudo().mapped('child_ids').write({
'so_line': values['sale_line_id']
})
self.sudo().mapped('timesheet_ids').write({
'so_line': values['sale_line_id']
})
@@ -124,12 +108,6 @@ class ProjectTask(models.Model):
raise ValidationError(_('You cannot delete a task related to a sales order. You can only archive it.'))
return super(ProjectTask, self).unlink()
@api.multi
def _subtask_implied_fields(self):
fields_list = super(ProjectTask, self)._subtask_implied_fields()
fields_list += ['sale_line_id']
return fields_list
@api.multi
def action_view_so(self):
self.ensure_one()
@@ -344,7 +344,16 @@ class TestSaleService(TestCommonSaleTimesheetNoChart):
'price_unit': self.product_delivery_timesheet3.list_price,
'order_id': self.sale_order.id,
})
so_line_deliver_new_task_project_2 = self.env['sale.order.line'].create({
'name': self.product_delivery_timesheet3.name + "(2)",
'product_id': self.product_delivery_timesheet3.id,
'product_uom_qty': 10,
'product_uom': self.product_delivery_timesheet3.uom_id.id,
'price_unit': self.product_delivery_timesheet3.list_price,
'order_id': self.sale_order.id,
})
so_line_deliver_new_task_project.product_id_change()
so_line_deliver_new_task_project_2.product_id_change()
self.sale_order.action_confirm()
project = so_line_deliver_new_task_project.project_id
@@ -358,14 +367,13 @@ class TestSaleService(TestCommonSaleTimesheetNoChart):
'parent_id': task.id,
'project_id': project.id,
'name': '%s: substask1' % (task.name,),
'sale_line_id': False # forcing, but should have not effect
})
task2 = self.env['project.task'].create({
'project_id': project.id,
'name': '%s: substask1' % (task.name,)
})
self.assertEqual(subtask.sale_line_id, task.sale_line_id, "A child task should have the same SO line than its mother")
self.assertEqual(subtask.sale_line_id, task.sale_line_id, "By, default, a child task should have the same SO line than its mother")
self.assertEqual(task2.sale_line_id, project.sale_line_id, "A new task in a billable project should have the same SO line than its project")
self.assertEqual(task2.partner_id, so_line_deliver_new_task_project.order_partner_id, "A new task in a billable project should have the same SO line than its project")
@@ -373,6 +381,18 @@ class TestSaleService(TestCommonSaleTimesheetNoChart):
subtask.write({'project_id': self.project_global.id})
self.assertEqual(subtask.sale_line_id, task.sale_line_id, "A child task should always have the same SO line than its mother, even when changing project")
self.assertEqual(subtask.sale_line_id, so_line_deliver_new_task_project)
# changing the SO line of the mother task
task.write({'sale_line_id': so_line_deliver_new_task_project_2.id})
self.assertEqual(subtask.sale_line_id, so_line_deliver_new_task_project, "A child task is not impacted by the change of SO line of its mother")
self.assertEqual(task.sale_line_id, so_line_deliver_new_task_project_2, "A mother task can have its SO line set manually")
# changing the SO line of a subtask
subtask.write({'sale_line_id': so_line_deliver_new_task_project_2.id})
self.assertEqual(subtask.sale_line_id, so_line_deliver_new_task_project_2, "A child can have its SO line set manually")
def test_change_ordered_qty(self):
""" Changing the ordered quantity of a SO line that have created a task should update the planned hours of this task """
@@ -41,7 +41,7 @@
string="Sales Order"/>
</xpath>
<field name="user_id" position="after">
<field name="sale_line_id" string="Sales Order Item" attrs="{'invisible': [('partner_id', '=', False)], 'readonly': [('parent_id', '!=', False)]}" options='{"no_open": True, "no_create": True}'/>
<field name="sale_line_id" string="Sales Order Item" attrs="{'invisible': [('partner_id', '=', False)]}" options='{"no_open": True, "no_create": True}'/>
</field>
</field>
</record>