[IMP] stock: scrap location for each company

Each company should have its own scrap location to allow specific
account on it.

TASK-ID: 1882269
This commit is contained in:
Pierre Masereel
2018-11-14 10:52:03 +00:00
committed by Simon Lejeune
parent ee1ea10c8c
commit 46c2ac2fc9
2 changed files with 23 additions and 7 deletions
+3 -7
View File
@@ -31,13 +31,6 @@
<field name="posz">1</field>
<field name="company_id"></field>
</record>
<record id="stock_location_scrapped" model="stock.location">
<field name="name">Scrapped</field>
<field name="location_id" ref="stock_location_locations_virtual"/>
<field name="scrap_location">True</field>
<field name="usage">inventory</field>
<field name="company_id"></field>
</record>
<record id="location_procurement" model="stock.location">
<field name="name">Procurements</field>
@@ -167,5 +160,8 @@
<function model="res.company" name="create_missing_production_location">
<value model="res.company" eval="obj()"/>
</function>
<function model="res.company" name="create_missing_scrap_location">
<value model="res.company" eval="obj()"/>
</function>
</data>
</odoo>
+20
View File
@@ -67,6 +67,17 @@ class Company(models.Model):
'value': 'stock.location,%d' % production_location.id,
})
def _create_scrap_location(self):
for company in self:
parent_location = self.env.ref('stock.stock_location_locations_virtual', raise_if_not_found=False)
scrap_location = self.env['stock.location'].create({
'name': '%s: Scrap' % company.name,
'usage': 'inventory',
'location_id': parent_location.id,
'company_id': company.id,
'scrap_location': True,
})
@api.model
def create_missing_warehouse(self):
""" This hook is used to add a warehouse on existing companies
@@ -101,6 +112,14 @@ class Company(models.Model):
for company in company_without_property:
company._create_production_location()
@api.model
def create_missing_scrap_location(self):
company_ids = self.env['res.company'].search([])
companies_having_scrap_loc = self.env['stock.location'].search([('scrap_location', '=', True)]).mapped('company_id')
company_without_property = company_ids - companies_having_scrap_loc
for company in company_without_property:
company._create_scrap_location()
@api.model
def create(self, vals):
company = super(Company, self).create(vals)
@@ -108,5 +127,6 @@ class Company(models.Model):
company.create_transit_location()
company.sudo()._create_inventory_loss_location()
company.sudo()._create_production_location()
company.sudo()._create_scrap_location()
self.env['stock.warehouse'].sudo().create({'name': company.name, 'code': company.name[:5], 'company_id': company.id, 'partner_id': company.partner_id.id})
return company