Prevent creating fiscal year before closed one

issue4509
review385711006
This commit is contained in:
Cédric Krier committed 2022-04-12 10:26:25 +02:00
1 parent beb8d6fa3b
commit 74c2bfa9fd
4 files changed
+61 -2

No files matched your search

+1
View File
@@ -1,3 +1,4 @@
* Prevent creating fiscal year before closed one
* Add automatic reconciliation of suggestions
* Prevent to change the type of journal with posted moves
* Mute reconciled payable/receivable lines
+17 -2
View File
@@ -108,7 +108,7 @@ class FiscalYear(Workflow, ModelSQL, ModelView):
@classmethod
def check_dates(cls, fiscalyears, field_names=None):
if field_names and not (field_names & {
'start_date', 'end_date', 'company'}):
'start_date', 'end_date', 'state', 'company'}):
return
transaction = Transaction()
connection = transaction.connection
@@ -132,6 +132,20 @@ class FiscalYear(Workflow, ModelSQL, ModelView):
gettext('account.msg_fiscalyear_overlap',
first=year.rec_name,
second=second.rec_name))
if year.state == 'open':
fiscalyears = cls.search([
('start_date', '>=', year.end_date),
('state', 'in', ['close', 'locked']),
('company', '=', year.company.id),
],
limit=1,
order=[('start_date', 'ASC')])
if fiscalyears:
fiscalyear, = fiscalyears
raise FiscalYearDatesError(
gettext('account.msg_open_fiscalyear_earlier',
open=year.rec_name,
close=fiscalyear.rec_name))
@classmethod
def check_post_move_sequence(cls, fiscalyears, field_names=None):
@@ -277,7 +291,8 @@ class FiscalYear(Workflow, ModelSQL, ModelView):
Account = pool.get('account.account')
Deferral = pool.get('account.account.deferral')
# Lock period to be sure no new period will be created in between.
# Prevent create new fiscal year or period
cls.lock()
Period.lock()
deferrals = []
+3
View File
@@ -60,6 +60,9 @@ this repository contains the full copyright notices and license terms. -->
<record model="ir.message" id="msg_fiscalyear_overlap">
<field name="text">The fiscal years "%(first)s" and "%(second)s" overlap, you must use different dates.</field>
</record>
<record model="ir.message" id="msg_open_fiscalyear_earlier">
<field name="text">The open fiscal year "%(open)s" can not be before the close fiscal year "%(closed)s".</field>
</record>
<record model="ir.message" id="msg_fiscalyear_different_post_move_sequence">
<field name="text">The fiscal years "%(first)s" and "%(second)s" cannot have the same post move sequence, you must use different sequences.</field>
</record>
+40
View File
@@ -18,6 +18,8 @@ from trytond.tests.test_tryton import (
ModuleTestCase, doctest_checker, doctest_teardown, with_transaction)
from trytond.transaction import Transaction
from ..exceptions import FiscalYearDatesError
def create_chart(company, tax=False, chart='account.account_template_root_en'):
pool = Pool()
@@ -274,6 +276,44 @@ class AccountTestCase(
for p1, p2 in zip(
fiscalyear.periods[:-1], fiscalyear.periods[1:])))
@with_transaction()
def test_open_fiscalyear_before_open(self):
"Test create open fiscal year before an open one"
company = create_company()
with set_company(company):
create_chart(company)
fiscalyear = get_fiscalyear(
company,
start_date=datetime.date(2022, 1, 1),
end_date=datetime.date(2022, 12, 31))
fiscalyear.save()
earlier_fiscalyear = get_fiscalyear(
company,
start_date=datetime.date(2021, 1, 1),
end_date=datetime.date(2021, 12, 31))
earlier_fiscalyear.save()
@with_transaction()
def test_open_fiscalyear_before_close(self):
"Test create open fiscal year before a close one"
company = create_company()
with set_company(company):
create_chart(company)
fiscalyear = get_fiscalyear(
company,
start_date=datetime.date(2022, 1, 1),
end_date=datetime.date(2022, 12, 31))
fiscalyear.save()
close_fiscalyear(fiscalyear)
earlier_fiscalyear = get_fiscalyear(
company,
start_date=datetime.date(2021, 1, 1),
end_date=datetime.date(2021, 12, 31))
with self.assertRaises(FiscalYearDatesError):
earlier_fiscalyear.save()
@with_transaction()
def test_account_debit_credit(self):
'Test account debit/credit'