Skip to content
Snippets Groups Projects
Commit d3808a5d authored by Djamel Touati's avatar Djamel Touati
Browse files

[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#135852

Signed-off-by: default avatarWilliam Henrotin (whe) <whe@odoo.com>
parent 5d98384e
No related branches found
No related tags found
No related merge requests found
......@@ -601,7 +601,10 @@ class ProductTemplate(models.Model):
tracking = fields.Selection([
('serial', 'By Unique Serial Number'),
('lot', 'By Lots'),
('none', 'No Tracking')], string="Tracking", help="Ensure the traceability of a storable product in your warehouse.", default='none', required=True)
('none', 'No Tracking')],
string="Tracking", required=True, default='none',
compute='_compute_tracking', store=True, readonly=False,
help="Ensure the traceability of a storable product in your warehouse.")
description_picking = fields.Text('Description on Picking', translate=True)
description_pickingout = fields.Text('Description on Delivery Orders', translate=True)
description_pickingin = fields.Text('Description on Receptions', translate=True)
......@@ -688,6 +691,12 @@ class ProductTemplate(models.Model):
}
return prod_available
@api.depends('type')
def _compute_tracking(self):
self.filtered(
lambda t: not t.tracking or t.type in ('consu', 'service') and t.tracking != 'none'
).tracking = 'none'
@api.model
def _get_action_view_related_putaway_rules(self, domain):
return {
......@@ -744,8 +753,6 @@ class ProductTemplate(models.Model):
@api.onchange('type')
def _onchange_type(self):
res = super(ProductTemplate, self)._onchange_type() or {}
if self.type == 'consu' and self.tracking != 'none':
self.tracking = 'none'
# Return a warning when trying to change the product type
if self.ids and self.product_variant_ids.ids and self.env['stock.move.line'].sudo().search_count([
......
......@@ -276,3 +276,22 @@ class TestVirtualAvailable(TestStockCommon):
res = self.env['product.template'].name_search(name='123', operator='not ilike')
res_ids = [r[0] for r in res]
self.assertNotIn(template.id, res_ids)
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.type = 'service'
product = product_form.save()
self.assertEqual(product.tracking, 'none')
product.type = 'product'
product.tracking = 'serial'
self.assertEqual(product.tracking, 'serial')
product_form = Form(product.product_variant_id)
product_form.type = 'service'
product = product_form.save()
self.assertEqual(product.tracking, 'none')
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment