The problem is that when you archive a company and then install subcontracting, you get a traceback. Step to reproduce (in a multi-company environment): -install 'stock' -archive a company -install 'mrp_subcontracting' -->traceback Explanation: When installing the 'mrp_subcontracting', there's a search on all (active) companies in order to add a subcontracting location for each of them (this is is triggered by '/odoo/addons/mrp_subcontracting/data/mrp_subcontracting_data.xml'). But there is still a warehouse linked to the archived company. So when adding routes to all warehouses and looking for the subcontracting location of the archived company, it is set to False. Which is not intended and causes the traceback. Solution: Add '.with_context(active_test=False)' to the search for the companies in '_create_missing_subcontracting_location(self)', so the missing subcontracting location will be created for the archived companies too. Discussion: -The ability to archive companies is new to Odoo16 (implemented due to the new pricing). -Here I considered that we want to create a subcontracting location for an archived company instead of taking action on the warehouse linked to the archived company (like not considering it when creating routes). I did this because a company can be unarchived and with this fix, it will not cause issues. -I think other problems similar to this one (in any app), should appear in the future. opw-3039495 closes odoo/odoo#107168 X-original-commit: 1dcdbe9e3cc21af50ed580c032b1927e21c3c24b Signed-off-by: William Henrotin (whe) <whe@odoo.com>
39 lines
1.5 KiB
Python
39 lines
1.5 KiB
Python
# -*- coding: utf-8 -*-
|
|
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
|
|
|
from odoo import api, fields, models, _
|
|
|
|
|
|
class ResCompany(models.Model):
|
|
_inherit = 'res.company'
|
|
|
|
subcontracting_location_id = fields.Many2one('stock.location')
|
|
|
|
@api.model
|
|
def _create_missing_subcontracting_location(self):
|
|
company_without_subcontracting_loc = self.env['res.company'].with_context(active_test=False).search(
|
|
[('subcontracting_location_id', '=', False)])
|
|
company_without_subcontracting_loc._create_subcontracting_location()
|
|
|
|
def _create_per_company_locations(self):
|
|
super(ResCompany, self)._create_per_company_locations()
|
|
self._create_subcontracting_location()
|
|
|
|
def _create_subcontracting_location(self):
|
|
parent_location = self.env.ref('stock.stock_location_locations', raise_if_not_found=False)
|
|
for company in self:
|
|
subcontracting_location = self.env['stock.location'].create({
|
|
'name': _('Subcontracting Location'),
|
|
'usage': 'internal',
|
|
'location_id': parent_location.id,
|
|
'company_id': company.id,
|
|
'is_subcontracting_location': True,
|
|
})
|
|
self.env['ir.property']._set_default(
|
|
"property_stock_subcontractor",
|
|
"res.partner",
|
|
subcontracting_location,
|
|
company,
|
|
)
|
|
company.subcontracting_location_id = subcontracting_location
|