Permalink
Browse files

[REF] stock: missing warehouse creation

We move the code from the 'post_init_hook' into a function tag, to be
consistent with the way we populate missing data when stock module is
installed.
  • Loading branch information...
pimodoo committed Nov 8, 2018
1 parent 507b4e0 commit d945e7aeabe37c2a5038cdfa1eda4fa4f83f9a9f
Showing with 20 additions and 18 deletions.
  1. +0 −17 addons/stock/__init__.py
  2. +0 −1 addons/stock/__manifest__.py
  3. +3 −0 addons/stock/data/stock_data.xml
  4. +17 −0 addons/stock/models/res_company.py
View
@@ -17,20 +17,3 @@ def pre_init_hook(cr):
('model', 'like', '%stock%'),
('module', '=', 'stock')
]).unlink()
def _create_warehouse(cr, registry):
""" This hook is used to add a warehouse on existing companies
when module stock is installed.
"""
env = api.Environment(cr, SUPERUSER_ID, {})
company_ids = env['res.company'].search([])
company_with_warehouse = env['stock.warehouse'].search([]).mapped('company_id')
company_without_warehouse = company_ids - company_with_warehouse
for company in company_without_warehouse:
company.create_transit_location()
env['stock.warehouse'].create({
'name': company.name,
'code': company.name[:5],
'company_id': company.id,
'partner_id': company.partner_id.id
})
@@ -78,5 +78,4 @@
'application': True,
'auto_install': False,
'pre_init_hook': 'pre_init_hook',
'post_init_hook': '_create_warehouse',
}
@@ -169,6 +169,9 @@
<function model="res.company" name="create_transit_location">
<value model="res.company" eval="obj().search([('internal_transit_location_id', '=', False)]).ids"/>
</function>
<function model="res.company" name="create_missing_warehouse">
<value model="res.company" eval="obj()"/>
</function>
<function model="res.company" name="create_missing_inventory_loss_location">
<value model="res.company" eval="obj()"/>
</function>
@@ -51,6 +51,23 @@ def _create_inventory_loss_location(self):
'value': 'stock.location,%d' % inventory_loss_location.id,
})
@api.model
def create_missing_warehouse(self):
""" This hook is used to add a warehouse on existing companies
when module stock is installed.
"""
company_ids = self.env['res.company'].search([])
company_with_warehouse = self.env['stock.warehouse'].search([]).mapped('company_id')
company_without_warehouse = company_ids - company_with_warehouse
for company in company_without_warehouse:
company.create_transit_location()
env['stock.warehouse'].create({
'name': company.name,
'code': company.name[:5],
'company_id': company.id,
'partner_id': company.partner_id.id
})
@api.model
def create_missing_inventory_loss_location(self):
company_ids = self.env['res.company'].search([])

0 comments on commit d945e7a

Please sign in to comment.