[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#126514

X-original-commit: e8ce51dd0b5024820eee6d5e60a3a3017a0e36f6
Signed-off-by: William Henrotin (whe) <whe@odoo.com>
Signed-off-by: Parth Solanki (paso) <paso@odoo.com>
This commit is contained in:
paso-odoo
2023-06-27 13:44:30 +02:00
parent 7b5f1df3d1
commit d2dc732fbc
+7
View File
@@ -275,6 +275,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: