[IMP] stock: transit location for each company

We have refactored the way transit locations are created to work as the
other company specific locations.

TASK-ID: 1882269
This commit is contained in:
Pierre Masereel
2018-11-14 10:52:03 +00:00
committed by Simon Lejeune
parent 46c2ac2fc9
commit b046f3ff6d
2 changed files with 13 additions and 7 deletions
+2 -2
View File
@@ -148,8 +148,8 @@
</function>
<!-- create the transit location for each company existing -->
<function model="res.company" name="create_transit_location">
<value model="res.company" eval="obj().search([('internal_transit_location_id', '=', False)]).ids"/>
<function model="res.company" name="create_missing_transit_location">
<value model="res.company" eval="obj()"/>
</function>
<function model="res.company" name="create_missing_warehouse">
<value model="res.company" eval="obj()"/>
+11 -5
View File
@@ -12,7 +12,7 @@ class Company(models.Model):
'stock.location', 'Internal Transit Location', on_delete="restrict",
help="Technical field used for resupply routes between warehouses that belong to this company")
def create_transit_location(self):
def _create_transit_location(self):
'''Create a transit location with company_id being the given company_id. This is needed
in case of resuply routes between warehouses belonging to the same company, because
we don't want to create accounting entries at that time.
@@ -23,12 +23,12 @@ class Company(models.Model):
'name': _('%s: Transit Location') % company.name,
'usage': 'transit',
'location_id': parent_location and parent_location.id or False,
'company_id': company.id,
})
location.sudo().write({'company_id': company.id})
company.write({'internal_transit_location_id': location.id})
warehouses = self.env['stock.warehouse'].search([('partner_id', '=', company.partner_id.id)])
warehouses.mapped('partner_id').with_context(force_company=company.id).write({
company.partner_id.with_context(force_company=company.id).write({
'property_stock_customer': location.id,
'property_stock_supplier': location.id,
})
@@ -94,6 +94,12 @@ class Company(models.Model):
'partner_id': company.partner_id.id,
})
@api.model
def create_missing_transit_location(self):
company_without_transit = self.env['res.company'].search([('internal_transit_location_id', '=', False)])
for company in company_without_transit:
company._create_transit_location()
@api.model
def create_missing_inventory_loss_location(self):
company_ids = self.env['res.company'].search([])
@@ -124,7 +130,7 @@ class Company(models.Model):
def create(self, vals):
company = super(Company, self).create(vals)
company.create_transit_location()
company.sudo()._create_transit_location()
company.sudo()._create_inventory_loss_location()
company.sudo()._create_production_location()
company.sudo()._create_scrap_location()