diff options
| author | svs-odoo <svs@odoo.com> | 2019-09-05 10:05:22 +0000 |
|---|---|---|
| committer | svs-odoo <svs@odoo.com> | 2019-09-05 12:07:57 +0000 |
| commit | 36757cde6d00a9e9059ce0bfb73d768c26743ab8 (patch) | |
| tree | 19b89a029e37ed30f42ecf56557b1f6bcfc16083 /addons | |
| parent | 454a05a0da2111719dc9b91f493fa02247965ea2 (diff) | |
[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: Simon Lejeune (sle) <sle@openerp.com>
Diffstat (limited to 'addons')
| -rw-r--r-- | addons/stock/models/stock_quant.py | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/addons/stock/models/stock_quant.py b/addons/stock/models/stock_quant.py index 0adc8e4f7dd..ea7e26eec2f 100644 --- a/addons/stock/models/stock_quant.py +++ b/addons/stock/models/stock_quant.py @@ -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)]", |
