changeset 53bc1131c00c in modules/account:default
details: https://hg.tryton.org/modules/account?cmd=changeset&node=53bc1131c00c
description:
Validate that all inactive accounts have no balance when closing periods
issue10292
review349721003
diffstat:
CHANGELOG | 2 ++
message.xml | 3 +++
period.py | 17 +++++++++++++++++
3 files changed, 22 insertions(+), 0 deletions(-)
diffs (55 lines):
diff -r c93c6a55b0cc -r 53bc1131c00c CHANGELOG
--- a/CHANGELOG Mon Jul 12 23:11:01 2021 +0200
+++ b/CHANGELOG Wed Jul 14 08:28:38 2021 +0200
@@ -1,3 +1,5 @@
+* Validate that all inactive accounts have no balance when closing periods
+
Version 6.0.0 - 2021-05-03
* Bug fixes (see mercurial logs for details)
* Add check to mark types as debt
diff -r c93c6a55b0cc -r 53bc1131c00c message.xml
--- a/message.xml Mon Jul 12 23:11:01 2021 +0200
+++ b/message.xml Wed Jul 14 08:28:38 2021 +0200
@@ -196,5 +196,8 @@
<record model="ir.message" id="msg_company_change_currency">
<field name="text">You cannot change the currency of a company
which is associated with account moves.</field>
</record>
+ <record model="ir.message" id="msg_close_period_inactive_accounts">
+ <field name="text">To close period "%(period)s", you must balance
the inactive account "%(account)s".</field>
+ </record>
</data>
</tryton>
diff -r c93c6a55b0cc -r 53bc1131c00c period.py
--- a/period.py Mon Jul 12 23:11:01 2021 +0200
+++ b/period.py Wed Jul 14 08:28:38 2021 +0200
@@ -298,6 +298,7 @@
pool = Pool()
JournalPeriod = pool.get('account.journal.period')
Move = pool.get('account.move')
+ Account = pool.get('account.account')
transaction = Transaction()
database = transaction.database
connection = transaction.connection
@@ -305,6 +306,22 @@
# Lock period to be sure no new period will be created in between.
database.lock(connection, JournalPeriod._table)
+ for period in periods:
+ with transaction.set_context(
+ fiscalyear=period.fiscalyear.id, date=period.end_date,
+ cumulate=True, journal=None):
+ for account in Account.search([
+ ('company', '=', period.company.id),
+ ('end_date', '>=', period.start_date),
+ ('end_date', '<=', period.end_date),
+ ]):
+ if account.balance:
+ raise ClosePeriodError(
+ gettext('account.'
+ 'msg_close_period_inactive_accounts',
+ account=account.rec_name,
+ period=period.rec_name))
+
unposted_moves = Move.search([
('period', 'in', [p.id for p in periods]),
('state', '!=', 'posted'),