[FIX] mrp_subcontracting: Allow subcontractor contacts to be used
**Steps to reproduce:** * Create a subcontractor. * Create a BoM of type Subcontracting and assign the subcontractor. * Create a children contact for the subcontractor. * Creat a purchase order (or a receipt picking) with the children contact of the subcontractor. * Confirm the document. **Current behavior:** Subcontractor documents are not created. **Expected result:** They should be created. **Cause:** The BoM search is not including possible parents of the partners. **Solution:** With the use of `parent_of` operator in the search, we cover both cases of the children and the parent as initiators of the subcontracting. closes odoo/odoo#46670 X-original-commit: 86726aba26f4ba8d7dadb29ed2415baf49fe54c0 Signed-off-by: Simon Lejeune (sle) <sle@openerp.com>
This commit is contained in:
@@ -13,7 +13,7 @@ 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 = AND([domain, [('subcontractor_ids', 'in', subcontractor.id)]])
|
||||
domain = AND([domain, [('subcontractor_ids', 'parent_of', subcontractor.ids)]])
|
||||
return self.search(domain, order='sequence, product_id', limit=1)
|
||||
else:
|
||||
return self.env['mrp.bom']
|
||||
|
||||
@@ -574,6 +574,28 @@ class TestSubcontractingFlows(TestMrpSubcontractingCommon):
|
||||
self.assertEqual(self.comp1.virtual_available, 0.0)
|
||||
self.assertEqual(self.comp1.virtual_available, 0.0)
|
||||
|
||||
def test_flow_10(self):
|
||||
"""Receipts from a children contact of a subcontractor are properly
|
||||
handled.
|
||||
"""
|
||||
# Create a children contact
|
||||
subcontractor_contact = self.env['res.partner'].create({
|
||||
'name': 'Test children subcontractor contact',
|
||||
'parent_id': self.subcontractor_partner1.id,
|
||||
})
|
||||
# Create a receipt picking from the subcontractor
|
||||
picking_form = Form(self.env['stock.picking'])
|
||||
picking_form.picking_type_id = self.env.ref('stock.picking_type_in')
|
||||
picking_form.partner_id = subcontractor_contact
|
||||
with picking_form.move_ids_without_package.new() as move:
|
||||
move.product_id = self.finished
|
||||
move.product_uom_qty = 1
|
||||
picking_receipt = picking_form.save()
|
||||
picking_receipt.action_confirm()
|
||||
# Check that a manufacturing order is created
|
||||
mo = self.env['mrp.production'].search([('bom_id', '=', self.bom.id)])
|
||||
self.assertEqual(len(mo), 1)
|
||||
|
||||
|
||||
class TestSubcontractingTracking(TransactionCase):
|
||||
def setUp(self):
|
||||
|
||||
Reference in New Issue
Block a user