[FIX] sale_project : create on order when type updated to service

Steps :
Install Sales, Project and Inventory.
Create a Storable Product.
Create a SO with this product, but do not confirm it.
Change this product :
	> Type : Service
	> Sales > Service Tracking : Create a task in SO's project
Confirm the SO.

Issue :
Neither a delivery or a task is created.

Cause :
Confirming the SO calls SO._timesheet_service_generation(),
which filtered its SOLs based on is_service to 'create on order'.
As this field is not updated when changing the type of the product,
the SOL with the service is filtered out.

Fix :
Update SOL_.is_service when changing SOL.product_id.type.

opw-2786655

closes odoo/odoo#87308

X-original-commit: f1518e8c9a6c7819a0d7f72a524c189cd9de5fc6
Signed-off-by: Laurent Stukkens (ltu) <ltu@odoo.com>
Signed-off-by: Xavier <xbo@odoo.com>
This commit is contained in:
Audric Onockx (auon)
2022-03-26 11:23:38 +01:00
parent f82843cb7b
commit 0dc5984d4d
2 changed files with 23 additions and 2 deletions
@@ -18,12 +18,12 @@ class SaleOrderLine(models.Model):
is_service = fields.Boolean("Is a Service", compute='_compute_is_service', store=True, compute_sudo=True, help="Sales Order item should generate a task and/or a project, depending on the product settings.")
reached_milestones_ids = fields.One2many('project.milestone', 'sale_line_id', string='Reached Milestones', domain=[('is_reached', '=', True)])
@api.depends('product_id')
@api.depends('product_id.type')
def _compute_is_service(self):
for so_line in self:
so_line.is_service = so_line.product_id.type == 'service'
@api.depends('product_id')
@api.depends('product_id.type')
def _compute_product_updatable(self):
for line in self:
if line.product_id.type == 'service' and line.state == 'sale':
@@ -152,3 +152,24 @@ class TestSaleProject(TransactionCase):
self.assertEqual(task.sale_line_id, sale_line_1_order_2)
self.assertIn(task.sale_line_id, self.project_global._get_sale_order_items())
self.assertEqual(self.project_global._get_sale_orders(), sale_order | sale_order_2)
def test_sol_product_type_update(self):
partner = self.env['res.partner'].create({'name': "Mur en brique"})
sale_order = self.env['sale.order'].with_context(tracking_disable=True).create({
'partner_id': partner.id,
'partner_invoice_id': partner.id,
'partner_shipping_id': partner.id,
})
self.product_order_service3.type = 'consu'
sale_order_line = self.env['sale.order.line'].create({
'order_id': sale_order.id,
'name': self.product_order_service3.name,
'product_id': self.product_order_service3.id,
'product_uom_qty': 5,
'product_uom': self.product_order_service3.uom_id.id,
'price_unit': self.product_order_service3.list_price
})
self.assertFalse(sale_order_line.is_service, "As the product is consumable, the SOL should not be a service")
self.product_order_service3.type = 'service'
self.assertTrue(sale_order_line.is_service, "As the product is a service, the SOL should be a service")