From 355056e8f49c201cca2e7da47b70ce3a00645787 Mon Sep 17 00:00:00 2001
From: Denis Ledoux <dle@odoo.com>
Date: Fri, 10 Sep 2021 14:30:41 +0000
Subject: [PATCH] [FIX] mrp: qty for bom kits with multiple boms with same
 sequence
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

When a product is configured with 2 different boms kit
using the same sequence,
the bom chosen could change randomly, therefore randomly
changing the available quantity.

This has been detected during an upgrade,
With the unit test checking the quantities
of the products doesn't change before and after the upgrade,
and in this case, the bom chosen before upgrade
was different than the bom chosen after upgrade,
therefore changing the available quantity of this product
before and after upgrade.

```
Traceback (most recent call last):
  File "/tmp/tmp659zn85u/migrations/testing.py", line 208, in test_check
    self.check(value)
  File "/tmp/tmp659zn85u/migrations/stock/tests/test_on_hand_quantity.py", line 20, in check
    self.assertEqual(before_results, self.convert_check(after_results), self.message)
AssertionError: Lists differ: [[262[3108 chars], '-107'], [3879, '-36'], [3983, '-39'], [3984[5666 chars]14']] != [[262[3108 chars], '-150'], [3879, '-36'], [3983, '-39'], [3984[5666 chars]14']]

First differing element 209:
[3878, '-107']
[3878, '-150']

Diff is 10670 characters long. Set self.maxDiff to None to see it. : Invariant check fail
```

upg-27353

closes odoo/odoo#76363

X-original-commit: 9e7d7fe86e4b6cc625974da7e2eb4b6044c13448
Signed-off-by: Rémy Voet <ryv-odoo@users.noreply.github.com>
Signed-off-by: Denis Ledoux (dle) <dle@odoo.com>
---
 addons/mrp/models/mrp_bom.py | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/addons/mrp/models/mrp_bom.py b/addons/mrp/models/mrp_bom.py
index 0475d415b732..c38880318574 100644
--- a/addons/mrp/models/mrp_bom.py
+++ b/addons/mrp/models/mrp_bom.py
@@ -205,12 +205,12 @@ class MrpBom(models.Model):
             domain += [('type', '=', bom_type)]
 
         if len(products) == 1:
-            bom = self.search(domain, order='sequence, product_id', limit=1)
+            bom = self.search(domain, order='sequence, product_id, id', limit=1)
             if bom:
                 bom_by_product[products] = bom
             return bom_by_product
 
-        boms = self.search(domain, order='sequence, product_id')
+        boms = self.search(domain, order='sequence, product_id, id')
 
         products_ids = set(products.ids)
         for bom in boms:
-- 
GitLab