From c66514288a815c6693230c47a1ce9f21b7d054e1 Mon Sep 17 00:00:00 2001 From: paso-odoo <paso@odoo.com> Date: Thu, 15 Jun 2023 06:58:04 +0000 Subject: [PATCH] [FIX] mrp: create production location when type is not production If the user change a location type of the 'Production' from inventory locations and installs the 'MRP' module, the traceback will appear. Steps to produce: - Install Stock module. - Inventory > Configuration > Settings > enable the Storage Locations. - Inventory > Configuration > Locations > Remove the filter 'Internal'. - Open the 'Production' location and change the Location Type to 'View'. - Now install the 'Manufacturing' module. Error: A traceback appears: 'ParseError: while parsing /home/odoo/src/odoo/saas-16.2/addons/mrp/data/mrp_data.xml:17, somewhere inside' At the time of installing the MRP module, it will search for the production location using the location type as the production here - https://github.com/odoo/odoo/blob/f65a9bffe2cbc03b2efc969dc205c9ba01ee9ab5/addons/mrp/models/stock_warehouse.py#L65 If the production location is not found it will raise an userError. In this commit, the production location is created based on the company if not found. It will lead to the above traceback. sentry-4215564628 closes odoo/odoo#125885 X-original-commit: e8ce51dd0b5024820eee6d5e60a3a3017a0e36f6 Signed-off-by: William Henrotin (whe) <whe@odoo.com> Signed-off-by: Parth Solanki (paso) <paso@odoo.com> --- addons/mrp/models/stock_warehouse.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/addons/mrp/models/stock_warehouse.py b/addons/mrp/models/stock_warehouse.py index e37c4edb5384..962d1ab31e7d 100644 --- a/addons/mrp/models/stock_warehouse.py +++ b/addons/mrp/models/stock_warehouse.py @@ -274,6 +274,13 @@ class StockWarehouse(models.Model): }) return data + def _create_missing_locations(self, vals): + super()._create_missing_locations(vals) + for company_id in self.company_id: + location = self.env['stock.location'].search([('usage', '=', 'production'), ('company_id', '=', company_id.id)], limit=1) + if not location: + company_id._create_production_location() + def write(self, vals): if any(field in vals for field in ('manufacture_steps', 'manufacture_to_resupply')): for warehouse in self: -- GitLab