Check dates of periods when changing fiscal year dates

Closes #12667
This commit is contained in:
Cédric Krier
2023-11-06 16:19:33 +01:00
parent fac8bb3e18
commit 91f4c6b2b8
2 changed files with 33 additions and 1 deletions
+10
View File
@@ -115,6 +115,7 @@ class FiscalYear(Workflow, ModelSQL, ModelView):
super().validate_fields(fiscalyears, field_names)
cls.check_dates(fiscalyears, field_names)
cls.check_post_move_sequence(fiscalyears, field_names)
cls.check_period_dates(fiscalyears, field_names)
@classmethod
def check_dates(cls, fiscalyears, field_names=None):
@@ -174,6 +175,15 @@ class FiscalYear(Workflow, ModelSQL, ModelView):
first=fiscalyear.rec_name,
second=years[0].rec_name))
@classmethod
def check_period_dates(cls, fiscalyears, field_names=None):
pool = Pool()
Period = pool.get('account.period')
if field_names and not (field_names & {'start_date', 'end_date'}):
return
periods = [p for f in fiscalyears for p in f.periods]
Period.check_fiscalyear_dates(periods, field_names={'fiscalyear'})
@classmethod
def create(cls, vlist):
fiscalyears = super().create(vlist)
+23 -1
View File
@@ -7,7 +7,8 @@ from decimal import Decimal
from dateutil.relativedelta import relativedelta
from trytond.exceptions import UserError
from trytond.modules.account.exceptions import FiscalYearDatesError
from trytond.modules.account.exceptions import (
FiscalYearDatesError, PeriodDatesError)
from trytond.modules.account.tax import TaxableMixin
from trytond.modules.company.tests import (
CompanyTestMixin, PartyCompanyCheckEraseMixin, create_company, set_company)
@@ -310,6 +311,27 @@ class AccountTestCase(
with self.assertRaises(FiscalYearDatesError):
earlier_fiscalyear.save()
@with_transaction()
def test_change_fiscalyear_dates_with_periods(self):
"Test change fiscal year dates"
company = create_company()
with set_company(company):
fiscalyear = get_fiscalyear(
company,
start_date=datetime.date(2023, 1, 1),
end_date=datetime.date(2023, 12, 31))
fiscalyear.save()
fiscalyear.create_period([fiscalyear])
# Extend
fiscalyear.end_date = datetime.date(2024, 5, 31)
fiscalyear.save()
# Shorten
with self.assertRaises(PeriodDatesError):
fiscalyear.end_date = datetime.date(2023, 5, 31)
fiscalyear.save()
@with_transaction()
def test_account_debit_credit(self):
'Test account debit/credit'