[IMP] mrp_subcontracting: subcontractors required

Force to set subcontractors on subcontracting BoM since
it's always used in order to determine if a subcontracting
should be apply on a receipt or not. Also there is not magical
behavior has 'if there is no subcontractor on the BoM then it
means all partners...'
This commit is contained in:
Arnold Moyaux
2019-08-19 15:03:59 +00:00
parent 39c5d0f35e
commit a684372fdd
4 changed files with 5 additions and 5 deletions
+2 -4
View File
@@ -2,7 +2,7 @@
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from odoo import fields, models
from odoo.osv.expression import AND
class MrpBom(models.Model):
_inherit = 'mrp.bom'
@@ -13,7 +13,5 @@ class MrpBom(models.Model):
def _bom_subcontract_find(self, product_tmpl=None, product=None, picking_type=None, company_id=False, bom_type='subcontract', subcontractor=False):
domain = self._bom_find_domain(product_tmpl=product_tmpl, product=product, picking_type=picking_type, company_id=company_id, bom_type=bom_type)
if subcontractor:
domain += ['|', ('subcontractor_ids', 'in', subcontractor.id), ('subcontractor_ids', '=', False)]
else:
domain += [('subcontractor_ids', '=', False)]
domain = AND([domain, [('subcontractor_ids', 'in', subcontractor.id)]])
return self.search(domain, order='subcontractor_ids, sequence, product_id', limit=1)
@@ -35,6 +35,7 @@ class TestMrpSubcontractingCommon(SavepointCase):
bom_form = Form(cls.env['mrp.bom'])
bom_form.type = 'subcontract'
bom_form.product_tmpl_id = cls.finished.product_tmpl_id
bom_form.subcontractor_ids.add(cls.subcontractor_partner1)
with bom_form.bom_line_ids.new() as bom_line:
bom_line.product_id = cls.comp1
bom_line.product_qty = 1
@@ -530,6 +530,7 @@ class TestSubcontractingTracking(TransactionCase):
})
bom_form = Form(self.env['mrp.bom'])
bom_form.type = 'subcontract'
bom_form.subcontractor_ids.add(self.subcontractor_partner1)
bom_form.product_tmpl_id = self.finished_lot.product_tmpl_id
with bom_form.bom_line_ids.new() as bom_line:
bom_line.product_id = self.comp1_sn
@@ -6,7 +6,7 @@
<field name="inherit_id" ref="mrp.mrp_bom_form_view" />
<field name="arch" type="xml">
<xpath expr="//field[@name='type']" position="after">
<field name="subcontractor_ids" widget="many2many_tags" context="{'default_type': 'subcontractor'}" attrs="{'invisible': [('type', '!=', 'subcontract')]}"/>
<field name="subcontractor_ids" widget="many2many_tags" context="{'default_type': 'subcontractor'}" attrs="{'invisible': [('type', '!=', 'subcontract')], 'required': [('type', '=', 'subcontract')]}"/>
</xpath>
</field>
</record>