Skip to content
Snippets Groups Projects
Commit 2c39f6cb 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#135912

X-original-commit: d3808a5d
Signed-off-by: default avatarWilliam Henrotin (whe) <whe@odoo.com>
Signed-off-by: default avatarDjamel Touati (otd) <otd@odoo.com>
parent 05e38f11
No related branches found
No related tags found
No related merge requests found
...@@ -668,7 +668,10 @@ class ProductTemplate(models.Model): ...@@ -668,7 +668,10 @@ class ProductTemplate(models.Model):
tracking = fields.Selection([ tracking = fields.Selection([
('serial', 'By Unique Serial Number'), ('serial', 'By Unique Serial Number'),
('lot', 'By Lots'), ('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_picking = fields.Text('Description on Picking', translate=True)
description_pickingout = fields.Text('Description on Delivery Orders', translate=True) description_pickingout = fields.Text('Description on Delivery Orders', translate=True)
description_pickingin = fields.Text('Description on Receptions', translate=True) description_pickingin = fields.Text('Description on Receptions', translate=True)
...@@ -782,6 +785,12 @@ class ProductTemplate(models.Model): ...@@ -782,6 +785,12 @@ class ProductTemplate(models.Model):
template.nbr_moves_in = int(res[template.id]['moves_in']) template.nbr_moves_in = int(res[template.id]['moves_in'])
template.nbr_moves_out = int(res[template.id]['moves_out']) template.nbr_moves_out = int(res[template.id]['moves_out'])
@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 @api.model
def _get_action_view_related_putaway_rules(self, domain): def _get_action_view_related_putaway_rules(self, domain):
return { return {
...@@ -846,8 +855,6 @@ class ProductTemplate(models.Model): ...@@ -846,8 +855,6 @@ class ProductTemplate(models.Model):
@api.onchange('type') @api.onchange('type')
def _onchange_type(self): def _onchange_type(self):
res = super(ProductTemplate, self)._onchange_type() or {} 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 # 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([ if self.ids and self.product_variant_ids.ids and self.env['stock.move.line'].sudo().search_count([
......
...@@ -321,3 +321,22 @@ class TestVirtualAvailable(TestStockCommon): ...@@ -321,3 +321,22 @@ class TestVirtualAvailable(TestStockCommon):
]: ]:
product_qty = self.product_3.with_context(warehouse=wh, location=loc).qty_available product_qty = self.product_3.with_context(warehouse=wh, location=loc).qty_available
self.assertEqual(product_qty, expected) 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.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