[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:
@@ -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')
|
||||
|
||||
@@ -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')
|
||||
|
||||
Reference in New Issue
Block a user