Production BOM: Maximun recursion and validate

1. Incorrect validation BOM

Current check_bom_recursion [1] is not correct because it only recursively that the product is in the input but not to the ouput.

It does not contemplate a type possibility:

BOM: A
Input: X
Output: Y

BOM: B
Input: Y
Output Z

BOM: C
Input: Z
Output: X

2. Current check_bom_recursion is when validate a product.

In case the product cost is “average”, for each time do a check_bom_recursion. IMHO we do a validation in the ‘production.bom’ model instead of ‘product.product’.

[1] https://bitbucket.org/tryton/production/src/875add501209e9b5819abb29f537d8765c5f770e/product.py#lines-40

For me this is recursive as X is used to build Z, so it’s not possible to build X using Z. So an error should raised.

From your message I do not understand if this is the case or not

You did not say which boms are stored on which products?

As long as a bom is not defined on a product, it should not be used.

PS: Please avoid using bitbucket links now because they will disapear soon.

Yes. This example crash about recursion method because don’t check the outputs are in other BOM:

File "/trytond/modules/production/product.py", line 54, in check_bom_recursion
input_.product.check_bom_recursion(product=product)):
File "/trytond/modules/production/product.py", line 54, in check_bom_recursion
input_.product.check_bom_recursion(product=product)):
File "/trytond/modules/production/product.py", line 54, in check_bom_recursion
input_.product.check_bom_recursion(product=product)):

… and as long as update the cost price (average) (or other product fields not related with the production) is not necessary to check product booms.

For me, there are still not enough information to understand why there is a infinite loop.

The example in the first post creates an infinte loop:

BOM: A
Input: X
Output: Y

BOM: B
Input: Y
Output Z

BOM: C
Input: Z
Output: X

Because current implementation only checks that the products of the input are different from the products of the output. But does not guarantee that the recursivity does not exist when the loop is created by three recursive BOMs.

We’ll create an issue to bugs.tryton.org and create a codereview.

Another discussion is if putting that check in the validate of product.product is a good idea given that, for example, a write() on product.product is done each time a product cost changes.