[FIX] mrp_subcontracting: remove hook
The hook only generate a useless rule. It has been already generated in stock_warehouse.py. Also remove the hook method and add it in data file.
This commit is contained in:
@@ -1,25 +1,3 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
from . import models
|
||||
from odoo import api, SUPERUSER_ID
|
||||
|
||||
def _create_subcontracting_rules(cr, registry):
|
||||
""" This hook is used to add the default subcontracting rules on every warehouse/company. It is
|
||||
necessary if the mrp_subcontracting module is installed after some warehouses
|
||||
were already created.
|
||||
"""
|
||||
env = api.Environment(cr, SUPERUSER_ID, {})
|
||||
warehouse_ids = env['stock.warehouse'].search(['|', ('subcontracting_mto_pull_id', '=', False), ('subcontracting_pull_id', '=', False)])
|
||||
for warehouse_id in warehouse_ids:
|
||||
warehouse_id.write({'subcontracting_to_resupply': warehouse_id.subcontracting_to_resupply})
|
||||
company_ids = env['res.company'].search([('subcontracting_location_id', '!=', False)])
|
||||
for company_id in company_ids:
|
||||
wh = env['stock.warehouse'].search([('company_id', '=', company_id.id), ('active', '=', True)], limit=1)
|
||||
production_location = wh._get_production_location()
|
||||
rsoo_rule = env['stock.rule'].search([
|
||||
('location_src_id', '=', company_id.subcontracting_location_id.id),
|
||||
('location_id', '=', production_location.id),
|
||||
('picking_type_id', '=', wh.manu_type_id.id)
|
||||
])
|
||||
if not rsoo_rule:
|
||||
company_id._create_resupply_subcontractor_rules()
|
||||
|
||||
@@ -16,5 +16,4 @@
|
||||
'views/mrp_bom_views.xml',
|
||||
'views/res_partner_views.xml',
|
||||
],
|
||||
'post_init_hook': '_create_subcontracting_rules',
|
||||
}
|
||||
|
||||
@@ -7,6 +7,10 @@
|
||||
<field name="sequence">5</field>
|
||||
</record>
|
||||
<function model="res.company" name="create_missing_subcontracting_location" />
|
||||
<function model="stock.warehouse" name="write">
|
||||
<value model="stock.warehouse" eval="obj().env['stock.warehouse'].search([]).ids"/>
|
||||
<value eval="{'subcontracting_to_resupply': True}"/>
|
||||
</function>
|
||||
</data>
|
||||
</odoo>
|
||||
|
||||
|
||||
@@ -30,18 +30,3 @@ class ResCompany(models.Model):
|
||||
[('subcontracting_location_id', '=', False)])
|
||||
for company in company_without_subcontracting_loc:
|
||||
company._create_subcontracting_location()
|
||||
|
||||
def _create_resupply_subcontractor_rules(self):
|
||||
self.ensure_one()
|
||||
wh = self.env['stock.warehouse'].search([('company_id', '=', self.id), ('active', '=', True)], limit=1)
|
||||
subcontracting_location = self.subcontracting_location_id
|
||||
production_location = wh._get_production_location()
|
||||
resupply_route = wh._find_global_route('mrp_subcontracting.route_resupply_subcontractor_mto', _('Resupply Subcontractor on Order'))
|
||||
resupply_route.rule_ids = [(0, 0, {
|
||||
'name': '%s → %s' % (subcontracting_location.name, production_location.name),
|
||||
'action': 'pull',
|
||||
'picking_type_id': wh.subcontracting_type_id,
|
||||
'location_src_id': subcontracting_location,
|
||||
'location_id': production_location,
|
||||
})],
|
||||
|
||||
|
||||
Reference in New Issue
Block a user