From 47654e98e0ae0ba91b7972cd113be364b7c9862f Mon Sep 17 00:00:00 2001 From: Richard Mathot Date: Thu, 2 Aug 2018 16:54:47 +0200 Subject: [PATCH] [FIX] stock: make orderpoints run in a deterministic order In Python 3.5, items() on a dictionary return keys in a randomized order. location_data can thus be processed in different orders, leading to different quantities in the MO's created by the procurement scheduler. This fix makes the output of the scheduler deterministic. (thanks to @odony for his help in troubleshooting this issue) opw-1865711 --- addons/stock/models/procurement.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/addons/stock/models/procurement.py b/addons/stock/models/procurement.py index 49f65a8f61c..ce6e16d58f4 100644 --- a/addons/stock/models/procurement.py +++ b/addons/stock/models/procurement.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- # Part of Odoo. See LICENSE file for full copyright and licensing details. -from collections import defaultdict +from collections import OrderedDict from datetime import datetime from dateutil.relativedelta import relativedelta from odoo.tools.misc import split_every @@ -328,9 +328,18 @@ class ProcurementGroup(models.Model): orderpoints_noprefetch = orderpoints_noprefetch[1000:] # Calculate groups that can be executed together - location_data = defaultdict(lambda: dict(products=self.env['product.product'], orderpoints=self.env['stock.warehouse.orderpoint'], groups=list())) + location_data = OrderedDict() + + def makedefault(): + return { + 'products': self.env['product.product'], + 'orderpoints': self.env['stock.warehouse.orderpoint'], + 'groups': [] + } + for orderpoint in orderpoints: key = self._procurement_from_orderpoint_get_grouping_key([orderpoint.id]) + location_data[key] = makedefault() location_data[key]['products'] += orderpoint.product_id location_data[key]['orderpoints'] += orderpoint location_data[key]['groups'] = self._procurement_from_orderpoint_get_groups([orderpoint.id])