Skip to content
Snippets Groups Projects
Commit 36757cde authored by svs-odoo's avatar svs-odoo
Browse files

[FIX] stock: domain on quant lot_id


Adds a domain on quant `lot_id` when user changes quantity on hand of a
specific product, so user can select lot only for this product (or its
product variants if user come from a product template).

closes odoo/odoo#36467

Signed-off-by: default avatarSimon Lejeune (sle) <sle@openerp.com>
parent 454a05a0
No related branches found
No related tags found
No related merge requests found
......@@ -23,6 +23,22 @@ class StockQuant(models.Model):
return
return [('usage', 'in', ['internal', 'transit'])]
def _domain_lot_id(self):
if not self._is_inventory_mode():
return
domain = [
"'|'",
"('company_id', '=', company_id)",
"('company_id', '=', False)"
]
if self.env.context.get('active_model') == 'product.product':
domain.insert(0, "('product_id', '=', %s)" % self.env.context.get('active_id'))
if self.env.context.get('active_model') == 'product.template':
product_template = self.env['product.template'].browse(self.env.context.get('active_id'))
if product_template.exists():
domain.insert(0, "('product_id', 'in', %s)" % product_template.product_variant_ids.ids)
return '[' + ', '.join(domain) + ']'
def _domain_product_id(self):
if not self._is_inventory_mode():
return
......@@ -50,7 +66,8 @@ class StockQuant(models.Model):
auto_join=True, ondelete='restrict', readonly=True, required=True, check_company=True)
lot_id = fields.Many2one(
'stock.production.lot', 'Lot/Serial Number',
ondelete='restrict', readonly=True, check_company=True)
ondelete='restrict', readonly=True, check_company=True,
domain=lambda self: self._domain_lot_id())
package_id = fields.Many2one(
'stock.quant.package', 'Package',
domain="[('location_id', '=', location_id)]",
......
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