Ensure move line domain is still valid after account modification
We can not close or remove the type of an account if it has move lines. issue10300 review376321002
This commit is contained in:
1 parent
56732a7c3a
commit
fefa168782
3 files changed
+40
-2
No files matched your search
+29
-1
@@ -26,7 +26,8 @@ from trytond.wizard import (
|
||||
Button, StateAction, StateTransition, StateView, Wizard)
|
||||
|
||||
from .common import ActivePeriodMixin, PeriodMixin
|
||||
from .exceptions import ChartWarning, SecondCurrencyError
|
||||
from .exceptions import (
|
||||
AccountValidationError, ChartWarning, SecondCurrencyError)
|
||||
|
||||
|
||||
def inactive_records(func):
|
||||
@@ -912,6 +913,7 @@ class Account(AccountMixin(), ActivePeriodMixin, tree(), ModelSQL, ModelView):
|
||||
def validate(cls, accounts):
|
||||
super(Account, cls).validate(accounts)
|
||||
cls.check_second_currency(accounts)
|
||||
cls.check_move_domain(accounts)
|
||||
|
||||
@staticmethod
|
||||
def default_left():
|
||||
@@ -1137,6 +1139,32 @@ class Account(AccountMixin(), ActivePeriodMixin, tree(), ModelSQL, ModelView):
|
||||
currency=account.second_currency.rec_name,
|
||||
account=account.rec_name))
|
||||
|
||||
@classmethod
|
||||
def check_move_domain(cls, accounts):
|
||||
pool = Pool()
|
||||
Line = pool.get('account.move.line')
|
||||
accounts = [a for a in accounts if a.closed or not a.type]
|
||||
for sub_accounts in grouped_slice(accounts):
|
||||
sub_accounts = list(sub_accounts)
|
||||
if Line.search([
|
||||
('account', 'in', [a.id for a in sub_accounts]),
|
||||
], order=[], limit=1):
|
||||
for account in sub_accounts:
|
||||
if not account.closed:
|
||||
continue
|
||||
lines = Line.search([
|
||||
('account', '=', account.id),
|
||||
], order=[], limit=1)
|
||||
if lines:
|
||||
if account.closed:
|
||||
raise AccountValidationError(gettext(
|
||||
'account.msg_account_closed_lines',
|
||||
account=account.rec_name))
|
||||
elif account.type:
|
||||
raise AccountValidationError(gettext(
|
||||
'account.msg_account_no_type_lines',
|
||||
account=account.rec_name))
|
||||
|
||||
@classmethod
|
||||
def copy(cls, accounts, default=None):
|
||||
if default is None:
|
||||
|
||||
+5
-1
@@ -53,7 +53,11 @@ class AccountMissing(UserError):
|
||||
pass
|
||||
|
||||
|
||||
class SecondCurrencyError(ValidationError):
|
||||
class AccountValidationError(ValidationError):
|
||||
pass
|
||||
|
||||
|
||||
class SecondCurrencyError(AccountValidationError):
|
||||
pass
|
||||
|
||||
|
||||
|
||||
@@ -95,6 +95,12 @@ this repository contains the full copyright notices and license terms. -->
|
||||
<record model="ir.message" id="msg_account_invalid_lines_second_currency">
|
||||
<field name="text">To set a second currency for account "%(account)s", its lines must have the same second currency "%(currency)s".</field>
|
||||
</record>
|
||||
<record model="ir.message" id="msg_account_closed_lines">
|
||||
<field name="text">You cannot close account "%(account)s" because it has move lines.</field>
|
||||
</record>
|
||||
<record model="ir.message" id="msg_account_no_type_lines">
|
||||
<field name="text">You cannot remove type of account "%(account)s" because it has move lines.</field>
|
||||
</record>
|
||||
|
||||
<record model="ir.message" id="msg_deferral_unique">
|
||||
<field name="text">Deferral must be unique by account and fiscal year.</field>
|
||||
|
||||
Reference in new issue
Block a user