diff options
| author | svs-odoo <svs@odoo.com> | 2020-04-06 10:55:02 +0000 |
|---|---|---|
| committer | svs-odoo <svs@odoo.com> | 2020-05-25 11:08:04 +0000 |
| commit | 4b588cf9f21aeb0e63e61717e8f674f990ac2bc2 (patch) | |
| tree | 3543053fdac42a558670d916bb882228311c2c09 | |
| parent | 681306d4e76faeb119d363c263c54b287cb5c150 (diff) | |
[IMP] stock: domain on orderpoint product_id
When user creates a new order point, if he/she comes from a template or
variant product page, adds the product id or the product template id in
the `product_id` field domain in the `stock.warehouse.orderpoint` model.
task-2181611
| -rw-r--r-- | addons/stock/models/stock_orderpoint.py | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/addons/stock/models/stock_orderpoint.py b/addons/stock/models/stock_orderpoint.py index de4152fce0e..95de53d45db 100644 --- a/addons/stock/models/stock_orderpoint.py +++ b/addons/stock/models/stock_orderpoint.py @@ -36,6 +36,17 @@ class StockWarehouseOrderpoint(models.Model): res['location_id'] = warehouse.lot_stock_id.id return res + @api.model + def _domain_product_id(self): + domain = "('type', '=', 'product')" + if self.env.context.get('active_model') == 'product.template': + product_template_id = self.env.context.get('active_id', False) + domain = f"('product_tmpl_id', '=', {product_template_id})" + elif self.env.context.get('default_product_id', False): + product_id = self.env.context.get('default_product_id', False) + domain = f"('id', '=', {product_id})" + return f"[{domain}, '|', ('company_id', '=', False), ('company_id', '=', company_id)]" + name = fields.Char( 'Name', copy=False, required=True, readonly=True, default=lambda self: self.env['ir.sequence'].next_by_code('stock.orderpoint')) @@ -54,7 +65,8 @@ class StockWarehouseOrderpoint(models.Model): product_tmpl_id = fields.Many2one('product.template', related='product_id.product_tmpl_id') product_id = fields.Many2one( 'product.product', 'Product', index=True, - domain="[('type', '=', 'product'), '|', ('company_id', '=', False), ('company_id', '=', company_id)]", ondelete='cascade', required=True, check_company=True) + domain=lambda self: self._domain_product_id(), + ondelete='cascade', required=True, check_company=True) product_category_id = fields.Many2one('product.category', name='Product Category', related='product_id.categ_id', store=True) product_uom = fields.Many2one( 'uom.uom', 'Unit of Measure', related='product_id.uom_id') |
