Skip to content
Permalink
Browse files

[IMP] stock: Improvement code.

Task:1941639

closes #31316
  • Loading branch information...
ppr-odoo committed Feb 22, 2019
1 parent 9c70457 commit ed9d644e50f1df18d48e766f58d6a877afad555c
Showing with 20 additions and 26 deletions.
  1. +20 −26 addons/stock/models/product.py
@@ -165,37 +165,31 @@ def _get_domain_locations(self):
[('location_id.company_id', '=', company_id), ('location_dest_id.company_id', '=', False),
])
location_ids = []
wids = []
def _search_ids(model, value, name_field, force_company_id):
ids = []
domain = []
if isinstance(value, int):
ids = [value]
else:
if isinstance(value, str):
domain += [(name_field, 'ilike', value)]
elif isinstance(value, list):
for item in value:
domain += [(name_field, 'ilike', item)]
if force_company_id:
domain += [('company_id', '=', force_company_id)]
ids = self.env[model].search(domain).ids
return ids

location = self.env.context.get('location', False)
force_company = self.env.context.get('force_company', False)
if location:
if isinstance(location, int):
location_ids = [location]
else:
domain = []
if isinstance(location, str):
domain += [('complete_name', 'ilike', location)]
elif isinstance(location, list):
for location in location:
domain += [('complete_name', 'ilike', location)]
if self.env.context.get('force_company', False):
domain += [('company_id', '=', self.env.context['force_company'])]
location_ids = self.env['stock.location'].search(domain).ids
location_ids = _search_ids('stock.location', location, 'complete_name', force_company)
else:
warehouse = self.env.context.get('warehouse', False)
if warehouse:
if isinstance(warehouse, int):
wids = [warehouse]
else:
domain = []
if isinstance(warehouse, str):
domain += [('name', 'ilike', warehouse)]
elif isinstance(warehouse, list):
for warehouse in warehouse:
domain += [('name', 'ilike', warehouse)]
else:
wids = warehouse
if self.env.context.get('force_company', False):
domain += [('company_id', '=', self.env.context['force_company'])]
wids = Warehouse.search(domain).ids
wids = _search_ids('stock.warehouse', warehouse, 'name', force_company)
else:
wids = Warehouse.search([]).ids

0 comments on commit ed9d644

Please sign in to comment.
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.