[FIX] stock: no tracking for service product

Steps to reproduce the bug:
- Create a storable “P1”:
   - tracking= serial
   - save
- Change the type of product to service

Problem:
some fields for tracked products are not hidden, because the product
tracking is not updated.

Solution:
Convert _onchange_type into compute methods.
The tracking is updated even if the change type is applied from the
"product.product" form.

opw-3499976

closes odoo/odoo#136738

X-original-commit: 22fe0ee4764705e55e81f62e07d29fc9bd8296e1
Signed-off-by: William Henrotin (whe) <whe@odoo.com>
Signed-off-by: Djamel Touati (otd) <otd@odoo.com>
This commit is contained in:
Djamel Touati
2023-09-28 03:19:17 +00:00
parent 2257c295e1
commit ead6124b2d
2 changed files with 21 additions and 1 deletions
+1 -1
View File
@@ -826,7 +826,7 @@ class ProductTemplate(models.Model):
@api.depends('type')
def _compute_tracking(self):
self.filtered(
lambda t: not t.tracking or t.type == 'consu' and t.tracking != 'none'
lambda t: not t.tracking or t.type in ('consu', 'service') and t.tracking != 'none'
).tracking = 'none'
@api.onchange('type')
+20
View File
@@ -325,3 +325,23 @@ class TestVirtualAvailable(TestStockCommon):
]:
product_qty = self.product_3.with_context(warehouse=wh, location=loc).qty_available
self.assertEqual(product_qty, expected)
def test_change_type_tracked_product(self):
product = self.env['product.template'].create({
'name': 'Brand new product',
'type': 'product',
'tracking': 'serial',
})
product_form = Form(product)
product_form.detailed_type = 'service'
product = product_form.save()
self.assertEqual(product.tracking, 'none')
product.detailed_type = 'product'
product.tracking = 'serial'
self.assertEqual(product.tracking, 'serial')
# change the type from "product.product" form
product_form = Form(product.product_variant_id)
product_form.detailed_type = 'service'
product = product_form.save()
self.assertEqual(product.tracking, 'none')