details:   https://code.tryton.org/tryton/commit/5da230f407ea
branch:    8.0
user:      Maxime Richez <[email protected]>
date:      Thu Nov 12 15:21:25 2026 +0100
description:
        Expand phantom BOM inputs in BOM tree

        Closes #15219
        (grafted from 0954ae806fc0426c93bf4a68568965e8c0749def)
diffstat:

 modules/production/bom.py                                    |  34 +++++++----
 modules/production/tests/scenario_production_phantom_bom.rst |  11 +++-
 2 files changed, 30 insertions(+), 15 deletions(-)

diffs (76 lines):

diff -r 039c7dad9a20 -r 5da230f407ea modules/production/bom.py
--- a/modules/production/bom.py Wed Nov 04 15:31:19 2026 +0100
+++ b/modules/production/bom.py Thu Nov 12 15:21:25 2026 +0100
@@ -376,6 +376,8 @@
     def tree(cls, product, quantity, unit, bom=None):
         Input = Pool().get('production.bom.input')
 
+        if not product and bom is None:
+            raise ValueError("'bom' must be provided if 'product' is empty")
         result = []
         if bom is None:
             pbom = product.get_bom()
@@ -386,20 +388,24 @@
         factor = bom.compute_factor(product, quantity, unit)
         for input_ in bom.inputs:
             quantity = Input.compute_quantity(input_, factor)
-            childs = cls.tree(input_.product, quantity, input_.unit)
-            values = {
-                'product': input_.product.id,
-                'product.': {
-                    'rec_name': input_.product.rec_name,
-                    },
-                'quantity': quantity,
-                'unit': input_.unit.id,
-                'unit.': {
-                    'rec_name': input_.unit.rec_name,
-                    },
-                'childs': childs,
-            }
-            result.append(values)
+            if input_.phantom_bom:
+                result.extend(cls.tree(
+                        None, quantity, input_.unit, bom=input_.phantom_bom))
+            else:
+                childs = cls.tree(input_.product, quantity, input_.unit)
+                values = {
+                    'product': input_.product.id,
+                    'product.': {
+                        'rec_name': input_.product.rec_name,
+                        },
+                    'quantity': quantity,
+                    'unit': input_.unit.id,
+                    'unit.': {
+                        'rec_name': input_.unit.rec_name,
+                        },
+                    'childs': childs,
+                }
+                result.append(values)
         return result
 
 
diff -r 039c7dad9a20 -r 5da230f407ea 
modules/production/tests/scenario_production_phantom_bom.rst
--- a/modules/production/tests/scenario_production_phantom_bom.rst      Wed Nov 
04 15:31:19 2026 +0100
+++ b/modules/production/tests/scenario_production_phantom_bom.rst      Thu Nov 
12 15:21:25 2026 +0100
@@ -6,7 +6,7 @@
 
     >>> from decimal import Decimal
 
-    >>> from proteus import Model
+    >>> from proteus import Model, Wizard
     >>> from trytond.modules.company.tests.tools import create_company, 
get_company
     >>> from trytond.tests.tools import activate_modules
 
@@ -147,3 +147,12 @@
 
     >>> table.boms.append(ProductBom(bom=bom))
     >>> table.save()
+
+Open the BOM tree of the product::
+
+    >>> bom_tree = Wizard('production.bom.tree.open', [table])
+    >>> bom_tree.form.quantity = 2
+    >>> bom_tree.execute('tree')
+    >>> table_tree, = bom_tree.form.bom_tree
+    >>> [(c.product.name, c.quantity) for c in table_tree.childs]
+    [('top', 2.0), ('leg', 8.0), ('foot', 8.0)]

Reply via email to