[IMP] stock, mrp, repair: production location for each company
Each company should have its own production location to allow specific account on it. TASK-ID: 1882269
This commit is contained in:
committed by
Simon Lejeune
parent
5df621f665
commit
ee1ea10c8c
@@ -59,9 +59,7 @@ class StockWarehouse(models.Model):
|
||||
|
||||
@api.model
|
||||
def _get_production_location(self):
|
||||
location = self.env.ref('stock.location_production', raise_if_not_found=False)
|
||||
if not location:
|
||||
location = self.env['stock.location'].search([('usage', '=', 'production')], limit=1)
|
||||
location = self.env['stock.location'].with_context(force_company=self.company_id.id).search([('usage', '=', 'production'), ('company_id', '=', self.company_id.id)], limit=1)
|
||||
if not location:
|
||||
raise UserError(_('Can\'t find any production location.'))
|
||||
return location
|
||||
|
||||
@@ -13,5 +13,5 @@ class ReportStockRule(models.AbstractModel):
|
||||
"""
|
||||
res = super(ReportStockRule, self)._get_rule_loc(rule, product_id)
|
||||
if rule.action == 'manufacture':
|
||||
res['source'] = product_id.property_stock_production or self.env.ref('stock.location_production')
|
||||
res['source'] = product_id.property_stock_production
|
||||
return res
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
<field name="partner_invoice_id" ref="base.res_partner_address_1"/>
|
||||
<field name="location_id" ref="stock.stock_location_stock"/>
|
||||
<field name="operations" model="repair.line" eval="[(5, 0, 0), (0, 0, {
|
||||
'location_dest_id': obj().env.ref('stock.location_production').id,
|
||||
'location_dest_id': obj().env.ref('product.product_product_11').property_stock_production.id,
|
||||
'location_id': obj().env.ref('stock.stock_location_stock').id,
|
||||
'name': '[M-Las] Mouse, Laser',
|
||||
'product_id': obj().env.ref('product.product_product_11').id,
|
||||
@@ -38,7 +38,7 @@
|
||||
<field name="partner_invoice_id" ref="base.res_partner_address_1"/>
|
||||
<field name="location_id" ref="stock.stock_location_stock"/>
|
||||
<field name="operations" model="repair.line" eval="[(5, 0, 0), (0, 0, {
|
||||
'location_dest_id': obj().env.ref('stock.location_production').id,
|
||||
'location_dest_id': obj().env.ref('product.product_product_12').property_stock_production.id,
|
||||
'location_id': obj().env.ref('stock.stock_location_stock').id,
|
||||
'name': '[M-Wir] Mouse, Wireless',
|
||||
'price_unit': 50.0,
|
||||
@@ -67,7 +67,7 @@
|
||||
<field name="partner_invoice_id" ref="base.res_partner_address_1"/>
|
||||
<field name="location_id" ref="stock.stock_location_14"/>
|
||||
<field name="operations" model="repair.line" eval="[(5, 0, 0), (0, 0, {
|
||||
'location_dest_id': obj().env.ref('stock.location_production').id,
|
||||
'location_dest_id': obj().env.ref('product.product_product_13').property_stock_production.id,
|
||||
'location_id': obj().env.ref('stock.stock_location_stock').id,
|
||||
'name': '[RAM-SR5] RAM DDR SR5',
|
||||
'price_unit': 50.0,
|
||||
|
||||
@@ -59,7 +59,7 @@ class TestRepair(AccountingTestCase):
|
||||
'price_unit': price_unit,
|
||||
'repair_id': repair_id,
|
||||
'location_id': self.env.ref('stock.stock_location_stock').id,
|
||||
'location_dest_id': self.env.ref('stock.location_production').id,
|
||||
'location_dest_id': product_to_add.property_stock_production.id,
|
||||
})
|
||||
|
||||
def _create_simple_fee(self, repair_id=False, qty=0.0, price_unit=0.0):
|
||||
@@ -145,7 +145,7 @@ class TestRepair(AccountingTestCase):
|
||||
'Repaired product went to the wrong location')
|
||||
self.assertEqual(repair.operations.move_id.location_id.id, self.env.ref('stock.stock_location_stock').id,
|
||||
'Consumed product was taken in the wrong location')
|
||||
self.assertEqual(repair.operations.move_id.location_dest_id.id, self.env.ref('stock.location_production').id,
|
||||
self.assertEqual(repair.operations.move_id.location_dest_id.id, self.env.ref('product.product_product_5').property_stock_production.id,
|
||||
'Consumed product went to the wrong location')
|
||||
|
||||
# I define Invoice Method 'No Invoice' option in this repair order.
|
||||
|
||||
@@ -45,12 +45,6 @@
|
||||
<field name="usage">procurement</field>
|
||||
<field name="company_id"></field>
|
||||
</record>
|
||||
<record id="location_production" model="stock.location">
|
||||
<field name="name">Production</field>
|
||||
<field name="location_id" ref="stock_location_locations_virtual"/>
|
||||
<field name="usage">production</field>
|
||||
<field name="company_id"></field>
|
||||
</record>
|
||||
<record id="stock_location_suppliers" model="stock.location">
|
||||
<field name="name">Vendors</field>
|
||||
<field name="location_id" ref="stock_location_locations_partner"/>
|
||||
@@ -97,11 +91,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_production" model="ir.property">
|
||||
<field name="name">property_stock_production</field>
|
||||
<field name="fields_id" search="[('model','=','product.template'),('name','=','property_stock_production')]"/>
|
||||
<field eval="'stock.location,'+str(location_production)" name="value"/>
|
||||
</record>
|
||||
|
||||
|
||||
<!--
|
||||
@@ -175,5 +164,8 @@
|
||||
<function model="res.company" name="create_missing_inventory_loss_location">
|
||||
<value model="res.company" eval="obj()"/>
|
||||
</function>
|
||||
<function model="res.company" name="create_missing_production_location">
|
||||
<value model="res.company" eval="obj()"/>
|
||||
</function>
|
||||
</data>
|
||||
</odoo>
|
||||
|
||||
@@ -50,6 +50,23 @@ class Company(models.Model):
|
||||
'value': 'stock.location,%d' % inventory_loss_location.id,
|
||||
})
|
||||
|
||||
def _create_production_location(self):
|
||||
parent_location = self.env.ref('stock.stock_location_locations_virtual', raise_if_not_found=False)
|
||||
production_product_template_field = self.env['ir.model.fields'].search([('model','=','product.template'),('name','=','property_stock_production')])
|
||||
for company in self:
|
||||
production_location = self.env['stock.location'].create({
|
||||
'name': '%s: Production' % company.name,
|
||||
'usage': 'production',
|
||||
'location_id': parent_location.id,
|
||||
'company_id': company.id,
|
||||
})
|
||||
self.env['ir.property'].create({
|
||||
'name': 'property_stock_inventory_%s' % company.name,
|
||||
'fields_id': production_product_template_field.id,
|
||||
'company_id': company.id,
|
||||
'value': 'stock.location,%d' % production_location.id,
|
||||
})
|
||||
|
||||
@api.model
|
||||
def create_missing_warehouse(self):
|
||||
""" This hook is used to add a warehouse on existing companies
|
||||
@@ -75,11 +92,21 @@ class Company(models.Model):
|
||||
for company in company_without_property:
|
||||
company._create_inventory_loss_location()
|
||||
|
||||
@api.model
|
||||
def create_missing_production_location(self):
|
||||
company_ids = self.env['res.company'].search([])
|
||||
production_product_template_field = self.env['ir.model.fields'].search([('model','=','product.template'),('name','=','property_stock_production')])
|
||||
companies_having_property = self.env['ir.property'].search([('fields_id', '=', production_product_template_field.id)]).mapped('company_id')
|
||||
company_without_property = company_ids - companies_having_property
|
||||
for company in company_without_property:
|
||||
company._create_production_location()
|
||||
|
||||
@api.model
|
||||
def create(self, vals):
|
||||
company = super(Company, self).create(vals)
|
||||
|
||||
company.create_transit_location()
|
||||
company.sudo()._create_inventory_loss_location()
|
||||
company.sudo()._create_production_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
|
||||
|
||||
Reference in New Issue
Block a user