From 721cb4625319bb5b1dbe02b16be7adb17435fdc0 Mon Sep 17 00:00:00 2001 From: Cristina Sangrador Date: Sat, 28 Dec 2024 14:00:38 +0100 Subject: [PATCH] Do not try to create periods when renewing a fiscal year without periods The computation of interval raises a ZeroDivisionError because the length of periods is 0. Closes #13671 (grafted from baf0a88808a8c5e85116ebbc7cf5f414b6bd95fc) --HG-- branch : 7.0 --- modules/account/fiscalyear.py | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/modules/account/fiscalyear.py b/modules/account/fiscalyear.py index 5443454fc2..34a54b74dc 100644 --- a/modules/account/fiscalyear.py +++ b/modules/account/fiscalyear.py @@ -678,15 +678,19 @@ class RenewFiscalYear(Wizard): fiscalyear, = FiscalYear.copy( [self.start.previous_fiscalyear], default=self.fiscalyear_defaults()) - periods = [p for p in self.start.previous_fiscalyear.periods + periods = [ + p for p in self.start.previous_fiscalyear.periods if p.type == 'standard'] - months = month_delta(fiscalyear.end_date, fiscalyear.start_date) + 1 - interval = months / len(periods) - end_day = max(p.end_date.day - for p in self.start.previous_fiscalyear.periods - if p.type == 'standard') - if interval.is_integer(): - FiscalYear.create_period([fiscalyear], interval, end_day) + if periods: + months = month_delta(fiscalyear.end_date, fiscalyear.start_date) + months += 1 + interval = months / len(periods) + end_day = max( + p.end_date.day + for p in self.start.previous_fiscalyear.periods + if p.type == 'standard') + if interval.is_integer(): + FiscalYear.create_period([fiscalyear], interval, end_day) return fiscalyear def do_create_(self, action):