[FIX] stock: empty warehouse when company is not set.

When the user do not set a company on a route and check warehouse selectable
then it's impossible to select a warehouse. It happens due to the
check_company domain ['|', ('company_id', '=', company_id)('company_id','=',False)]

closes odoo/odoo#37404

Signed-off-by: Arnold Moyaux <amoyaux@users.noreply.github.com>
This commit is contained in:
Arnold Moyaux
2019-09-25 13:17:05 +00:00
parent 618d67b131
commit e7bdf82f59
2 changed files with 14 additions and 1 deletions
+13 -1
View File
@@ -187,9 +187,21 @@ class Route(models.Model):
'product.template', 'stock_route_product', 'route_id', 'product_id',
'Products', copy=False, check_company=True)
categ_ids = fields.Many2many('product.category', 'stock_location_route_categ', 'route_id', 'categ_id', 'Product Categories', copy=False)
warehouse_domain_ids = fields.One2many('stock.warehouse', compute='_compute_warehouses')
warehouse_ids = fields.Many2many(
'stock.warehouse', 'stock_route_warehouse', 'route_id', 'warehouse_id',
'Warehouses', copy=False, check_company=True)
'Warehouses', copy=False, domain="[('id', 'in', warehouse_domain_ids)]")
@api.depends('company_id')
def _compute_warehouses(self):
for loc in self:
domain = [('company_id', '=', loc.company_id.id)] if loc.company_id else []
loc.warehouse_domain_ids = self.env['stock.warehouse'].search(domain)
@api.onchange('company_id')
def _onchange_company(self):
if self.company_id:
self.warehouse_ids = self.warehouse_ids.filtered(lambda w: w.company_id == self.company_id)
@api.onchange('warehouse_selectable')
def _onchange_warehouse_selectable(self):
@@ -184,6 +184,7 @@
</group>
<group>
<field name="warehouse_selectable" string="Warehouses"/>
<field name="warehouse_domain_ids" invisible="1"/>
<field name="warehouse_ids" widget="many2many_tags" nolabel="1"
attrs="{'invisible': [('warehouse_selectable', '=', False)]}"/>
</group>