diff options
| author | Pierre Masereel <pim@odoo.com> | 2018-11-08 15:26:07 +0000 |
|---|---|---|
| committer | Simon Lejeune <sle@openerp.com> | 2018-11-14 10:52:03 +0000 |
| commit | ee1ea10c8cc35c13439ef455a0eef454b7abaf85 (patch) | |
| tree | e3cda4c77adbf825eacebdb5992fe352bd8c84bb | |
| parent | 5df621f66550a2832ee69e4ef23a953b5ef4724e (diff) | |
[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
| -rw-r--r-- | addons/mrp/models/stock_warehouse.py | 4 | ||||
| -rw-r--r-- | addons/mrp/report/report_stock_rule.py | 2 | ||||
| -rw-r--r-- | addons/repair/data/repair_demo.xml | 6 | ||||
| -rw-r--r-- | addons/repair/tests/test_repair.py | 4 | ||||
| -rw-r--r-- | addons/stock/data/stock_data.xml | 14 | ||||
| -rw-r--r-- | addons/stock/models/res_company.py | 27 |
6 files changed, 37 insertions, 20 deletions
diff --git a/addons/mrp/models/stock_warehouse.py b/addons/mrp/models/stock_warehouse.py index 7496236882b..a03ab6ddc36 100644 --- a/addons/mrp/models/stock_warehouse.py +++ b/addons/mrp/models/stock_warehouse.py @@ -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 diff --git a/addons/mrp/report/report_stock_rule.py b/addons/mrp/report/report_stock_rule.py index d25960d1183..2f25ca6a6bd 100644 --- a/addons/mrp/report/report_stock_rule.py +++ b/addons/mrp/report/report_stock_rule.py @@ -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 diff --git a/addons/repair/data/repair_demo.xml b/addons/repair/data/repair_demo.xml index 60616df3fb2..173c86f863b 100644 --- a/addons/repair/data/repair_demo.xml +++ b/addons/repair/data/repair_demo.xml @@ -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, diff --git a/addons/repair/tests/test_repair.py b/addons/repair/tests/test_repair.py index 568ba8abce6..17b19f86f98 100644 --- a/addons/repair/tests/test_repair.py +++ b/addons/repair/tests/test_repair.py @@ -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. diff --git a/addons/stock/data/stock_data.xml b/addons/stock/data/stock_data.xml index ecb0e11d14b..e9bc83c9794 100644 --- a/addons/stock/data/stock_data.xml +++ b/addons/stock/data/stock_data.xml @@ -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> diff --git a/addons/stock/models/res_company.py b/addons/stock/models/res_company.py index d44d40b5ef0..37ba46bb10a 100644 --- a/addons/stock/models/res_company.py +++ b/addons/stock/models/res_company.py @@ -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 @@ -76,10 +93,20 @@ class Company(models.Model): 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 |
