From bd25f471b39c6fa7f63ad2ea51315ab9abe2ea76 Mon Sep 17 00:00:00 2001 From: Denis Roussel Date: Wed, 26 Jul 2023 11:57:13 +0200 Subject: [PATCH] [FIX] stock_location_product_restriction: Don't fetch if ids are void --- .../models/stock_location.py | 11 +++++++++-- .../tests/test_stock_location.py | 8 ++++++-- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/stock_location_product_restriction/models/stock_location.py b/stock_location_product_restriction/models/stock_location.py index 89371a1db..9224f0f96 100644 --- a/stock_location_product_restriction/models/stock_location.py +++ b/stock_location_product_restriction/models/stock_location.py @@ -86,8 +86,15 @@ class StockLocation(models.Model): stock_quant.location_id HAVING count(distinct(product_id)) > 1 """ - self.env.cr.execute(SQL, (tuple(records.ids),)) - product_ids_by_location_id = dict(self.env.cr.fetchall()) + # Browse only real record ids + ids = tuple( + [record.id for record in records if not isinstance(record.id, fields.NewId)] + ) + if not ids: + product_ids_by_location_id = dict() + else: + self.env.cr.execute(SQL, (ids,)) + product_ids_by_location_id = dict(self.env.cr.fetchall()) for record in self: record_id = record.id has_restriction_violation = False diff --git a/stock_location_product_restriction/tests/test_stock_location.py b/stock_location_product_restriction/tests/test_stock_location.py index a57eddcde..39e154191 100644 --- a/stock_location_product_restriction/tests/test_stock_location.py +++ b/stock_location_product_restriction/tests/test_stock_location.py @@ -1,7 +1,6 @@ # Copyright 2020 ACSONE SA/NV # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). - -from odoo.tests.common import TransactionCase +from odoo.tests.common import Form, TransactionCase class TestStockLocation(TransactionCase): @@ -258,3 +257,8 @@ class TestStockLocation(TransactionCase): self.loc_lvl_1_1_1.flush_recordset() self.assertTrue(self.loc_lvl_1_1_1.has_restriction_violation) self.assertTrue(self.loc_lvl_1_1_1.restriction_violation_message) + + def test_05(self): + # Check location creation + with Form(self.StockLocation) as location_form: + location_form.name = "Test"