From c3da7bb303f66f93ddb85b91cebaebbd9d55eedb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Sat, 30 Oct 2021 02:27:19 +0200 Subject: [PATCH] Limit size of grouping_filter ids The list of ids in grouping_filter are used inside an IN-clause so we must limit the size. issue10589 review379471002 --- inventory.py | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/inventory.py b/inventory.py index 575a0fff84..bab0ed29b8 100644 --- a/inventory.py +++ b/inventory.py @@ -1,11 +1,14 @@ # This file is part of Tryton. The COPYRIGHT file at the top level of # this repository contains the full copyright notices and license terms. +from collections import defaultdict + from sql import Null from trytond.i18n import gettext from trytond.model import Workflow, Model, ModelView, ModelSQL, fields, Check from trytond.model.exceptions import AccessError from trytond.pyson import Eval, Bool, If +from trytond.tools import grouped_slice from trytond.transaction import Transaction from trytond.pool import Pool from trytond.wizard import Wizard, StateView, StateTransition, Button @@ -257,15 +260,19 @@ class Inventory(Workflow, ModelSQL, ModelView): if inventory.state == 'done': continue # Compute product quantities - if fill: - product_ids = None - else: - product_ids = [l.product.id for l in inventory.lines] with Transaction().set_context(stock_date_end=inventory.date): - pbl = Product.products_by_location( - [inventory.location.id], - grouping=grouping, - grouping_filter=(product_ids,)) + if fill: + pbl = Product.products_by_location( + [inventory.location.id], + grouping=grouping) + else: + product_ids = [l.product.id for l in inventory.lines] + pbl = defaultdict(int) + for product_ids in grouped_slice(product_ids): + pbl.update(Product.products_by_location( + [inventory.location.id], + grouping=grouping, + grouping_filter=(list(product_ids),))) # Index some data product2type = {}