From 2e5b1f009110c0ff9440f4e3ad14e2507560cd47 Mon Sep 17 00:00:00 2001 From: ArnauCForgeFlow Date: Tue, 25 Jun 2024 15:40:25 +0200 Subject: [PATCH] [FIX] stock_cycle_count: prevent creating infinte cycle counts --- stock_cycle_count/models/stock_warehouse.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/stock_cycle_count/models/stock_warehouse.py b/stock_cycle_count/models/stock_warehouse.py index db84413d1..8585dfc1c 100644 --- a/stock_cycle_count/models/stock_warehouse.py +++ b/stock_cycle_count/models/stock_warehouse.py @@ -106,12 +106,17 @@ class StockWarehouse(models.Model): cycle_count_proposed = next( filter(lambda x: x["date"] == earliest_date, proposed_for_loc) ) - self._handle_existing_cycle_counts(loc, cycle_count_proposed) + existing_cycle_counts = self._handle_existing_cycle_counts( + loc, cycle_count_proposed + ) delta = ( fields.Datetime.from_string(cycle_count_proposed["date"]) - datetime.today() ) - if delta.days < self.cycle_count_planning_horizon: + if ( + not existing_cycle_counts + and delta.days < self.cycle_count_planning_horizon + ): cc_vals = self._prepare_cycle_count(cycle_count_proposed) cc_vals_list.append(cc_vals) return cc_vals_list @@ -137,6 +142,7 @@ class StockWarehouse(models.Model): "cycle_count_rule_id": cycle_count_proposed["rule_type"].id, } ) + return existing_cycle_counts @api.model def cron_cycle_count(self):