Permalink
Browse files

[IMP] stock: inventory loss location for each company

Each company should have its own inventory location to allow specific
account on it
  • Loading branch information...
pimodoo committed Nov 7, 2018
1 parent 6141df1 commit 507b4e033d065e6220c3a084187dc76e62586a83
@@ -39,12 +39,6 @@
<field name="company_id"></field>
</record>
<record id="location_inventory" model="stock.location">
<field name="name">Inventory adjustment</field>
<field name="location_id" ref="stock_location_locations_virtual"/>
<field name="usage">inventory</field>
<field name="company_id"></field>
</record>
<record id="location_procurement" model="stock.location">
<field name="name">Procurements</field>
<field name="location_id" ref="stock_location_locations_virtual"/>
@@ -103,11 +97,6 @@
<field name="fields_id" search="[('model','=','res.partner'),('name','=','property_stock_customer')]"/>
<field eval="'stock.location,'+str(stock_location_customers)" name="value"/>
</record>
<record forcecreate="True" id="property_stock_inventory" model="ir.property">
<field name="name">property_stock_inventory</field>
<field name="fields_id" search="[('model','=','product.template'),('name','=','property_stock_inventory')]"/>
<field eval="'stock.location,'+str(location_inventory)" name="value"/>
</record>
<record forcecreate="True" id="property_stock_production" model="ir.property">
<field name="name">property_stock_production</field>
<field name="fields_id" search="[('model','=','product.template'),('name','=','property_stock_production')]"/>
@@ -180,5 +169,8 @@
<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_inventory_loss_location">
<value model="res.company" eval="obj()"/>
</function>
</data>
</odoo>
@@ -34,7 +34,6 @@
<field name="tracking">lot</field>
<field name="uom_id" ref="uom.product_uom_kgm"/>
<field name="uom_po_id" ref="uom.product_uom_kgm"/>
<field name="property_stock_inventory" ref="stock.location_inventory"/>
<field name="image" type="base64" file="stock/static/img/cable_management.png"/>
</record>
@@ -17,7 +17,6 @@ def create_transit_location(self):
in case of resuply routes between warehouses belonging to the same company, because
we don't want to create accounting entries at that time.
'''
# TDE FIXME: called in data - should be done in init ??
parent_location = self.env.ref('stock.stock_location_locations', raise_if_not_found=False)
for company in self:
location = self.env['stock.location'].create({
@@ -34,11 +33,39 @@ def create_transit_location(self):
'property_stock_supplier': location.id,
})
def _create_inventory_loss_location(self):
parent_location = self.env.ref('stock.stock_location_locations_virtual', raise_if_not_found=False)
inventory_loss_product_template_field = self.env['ir.model.fields'].search([('model','=','product.template'),('name','=','property_stock_inventory')])
self = self.sudo()
for company in self:
inventory_loss_location = self.env['stock.location'].create({
'name': '%s: Inventory adjustment' % company.name,
'usage': 'inventory',
'location_id': parent_location.id,
'company_id': company.id,
})
self.env['ir.property'].create({
'name': 'property_stock_inventory_%s' % company.name,
'fields_id': inventory_loss_product_template_field.id,
'company_id': company.id,
'value': 'stock.location,%d' % inventory_loss_location.id,
})
@api.model
def create_missing_inventory_loss_location(self):
company_ids = self.env['res.company'].search([])
inventory_loss_product_template_field = self.env['ir.model.fields'].search([('model','=','product.template'),('name','=','property_stock_inventory')])
companies_having_property = self.env['ir.property'].search([('fields_id', '=', inventory_loss_product_template_field.id)]).mapped('company_id')
company_without_property = company_ids - companies_having_property
for company in company_without_property:
company._create_inventory_loss_location()
@api.model
def create(self, vals):
company = super(Company, self).create(vals)
company.create_transit_location()
company._create_inventory_loss_location()
# mutli-company rules prevents creating warehouse and sub-locations
self.env['stock.warehouse'].check_access_rights('create')
self.env['stock.warehouse'].sudo().create({'name': company.name, 'code': company.name[:5], 'company_id': company.id, 'partner_id': company.partner_id.id})
@@ -34,9 +34,9 @@ def test_inventory_product(self):
self.assertIn(inventory.name, inventory.move_ids.name)
self.assertEqual(inventory.move_ids.product_qty, 15.0)
self.assertEqual(inventory.move_ids.location_id, self.warehouse_1.lot_stock_id)
self.assertEqual(inventory.move_ids.location_dest_id, self.env.ref('stock.location_inventory')) # Inventory loss
self.assertEqual(inventory.move_ids.location_dest_id, self.product_1.property_stock_inventory) # Inventory loss
self.assertEqual(inventory.move_ids.state, 'done')
quants = self.env['stock.quant']._gather(self.product_1, self.env.ref('stock.location_inventory'))
quants = self.env['stock.quant']._gather(self.product_1, self.product_1.property_stock_inventory)
self.assertEqual(len(quants), 1) # One quant created for inventory loss
# Check quantity of product in various locations: current, its parent, brother and other
@@ -176,7 +176,7 @@ def test_inventory_adjustment_and_negative_quants_2(self):
productA = self.env['product.product'].create({'name': 'Product A', 'type': 'product'})
stock_location = self.env.ref('stock.stock_location_stock')
customer_location = self.env.ref('stock.stock_location_customers')
location_loss = self.env.ref('stock.location_inventory')
location_loss = productA.property_stock_inventory
# Create a picking out and force availability
picking_out = self.env['stock.picking'].create({

0 comments on commit 507b4e0

Please sign in to comment.