mirror of
https://github.com/OCA/manufacture.git
synced 2025-01-28 16:37:15 +02:00
[IMP] mrp_production_hierarchy: Track the root production order on each generated sub-production orders + Display root order and direct parent order on the form
This commit is contained in:
@@ -11,9 +11,12 @@ class MrpProduction(models.Model):
|
||||
_parent_store = True
|
||||
_parent_order = 'name'
|
||||
|
||||
root_id = fields.Many2one(
|
||||
'mrp.production', u"Root order",
|
||||
index=True, ondelete='restrict', readonly=True)
|
||||
parent_id = fields.Many2one(
|
||||
'mrp.production', u"Parent order",
|
||||
index=True, ondelete='restrict')
|
||||
index=True, ondelete='restrict', readonly=True)
|
||||
child_ids = fields.One2many(
|
||||
'mrp.production', 'parent_id', u"Child orders")
|
||||
parent_left = fields.Integer('Left Parent', index=True)
|
||||
@@ -25,6 +28,10 @@ class MrpProduction(models.Model):
|
||||
It will be used by the 'procurement_order.make_mo()' overload to
|
||||
set the parent relation between production orders.
|
||||
"""
|
||||
# Set the initial root production order ID
|
||||
if not self.env.context.get('root_mrp_production_id'):
|
||||
self = self.with_context(root_mrp_production_id=self.id)
|
||||
# Set the parent production order ID
|
||||
self = self.with_context(parent_mrp_production_id=self.id)
|
||||
return super(MrpProduction, self)._generate_moves()
|
||||
|
||||
|
||||
@@ -10,12 +10,18 @@ class ProcurementOrder(models.Model):
|
||||
|
||||
@api.multi
|
||||
def make_mo(self):
|
||||
"""Overload to set the parent production order ID to its childs."""
|
||||
"""Overload to set the root and parent production order ID to the
|
||||
children production orders.
|
||||
"""
|
||||
res = super(ProcurementOrder, self).make_mo()
|
||||
production_ids = res.values()
|
||||
production_ids = [id_ for id_ in res.values() if id_]
|
||||
productions = self.env['mrp.production'].browse(production_ids)
|
||||
for production in productions:
|
||||
if self.env.context.get('parent_mrp_production_id'):
|
||||
parent_id = self.env.context['parent_mrp_production_id']
|
||||
production.parent_id = parent_id
|
||||
root_id = self.env.context['root_mrp_production_id']
|
||||
production.write({
|
||||
'parent_id': parent_id,
|
||||
'root_id': root_id,
|
||||
})
|
||||
return res
|
||||
|
||||
@@ -26,5 +26,9 @@ class TestMrpProductionHierarchy(TestMrpCommon):
|
||||
self.assertEqual(len(man_order.child_ids), 2)
|
||||
for child in man_order.child_ids:
|
||||
self.assertIn(child.product_id, [self.product_5, self.product_4])
|
||||
self.assertEqual(child.root_id, man_order)
|
||||
self.assertEqual(child.parent_id, man_order)
|
||||
for child2 in child.child_ids:
|
||||
self.assertIn(child2.product_id, [self.product_4])
|
||||
self.assertEqual(child2.root_id, man_order)
|
||||
self.assertEqual(child2.parent_id, child)
|
||||
|
||||
@@ -13,6 +13,10 @@
|
||||
icon="fa-sitemap"
|
||||
attrs="{'invisible': [('child_ids', '=', [])]}"/>
|
||||
</div>
|
||||
<field name="origin" position="after">
|
||||
<field name="root_id"/>
|
||||
<field name="parent_id"/>
|
||||
</field>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user