Cédric Krier pushed to branch branch/default at Tryton / Tryton
Commits:
b43c4abc by Cédric Krier at 2023-05-17T14:46:52+02:00
Allow only normal account on analytic line
Closes #4030
- - - - -
41ce903f by Cédric Krier at 2023-05-17T15:03:35+02:00
Always enforce company for account of analytic line
- - - - -
4c88fc43 by Cédric Krier at 2023-05-17T15:19:37+02:00
Ensure analytic line domain is still valid after account modification
Analytic account can not be changed from normal to any of the root, view or
distribution.
- - - - -
3 changed files:
- modules/analytic_account/account.py
- modules/analytic_account/line.py
- modules/analytic_account/message.xml
Changes:
=====================================
modules/analytic_account/account.py
=====================================
@@ -126,6 +126,7 @@
def validate_fields(cls, accounts, field_names):
super().validate_fields(accounts, field_names)
cls.check_distribution(accounts, field_names)
+ cls.check_move_domain(accounts, field_names)
@classmethod
def check_distribution(cls, accounts, field_names=None):
@@ -139,6 +140,25 @@
gettext('analytic_account.msg_invalid_distribution',
account=account.rec_name))
+ @classmethod
+ def check_move_domain(cls, accounts, field_names):
+ pool = Pool()
+ Line = pool.get('account.move.line')
+ if field_names and 'type' not in field_names:
+ return
+ accounts = [
+ a for a in accounts if a.type in {'root', 'view', 'distribution'}]
+ for sub_accounts in grouped_slice(accounts):
+ sub_accounts = list(sub_accounts)
+ lines = Line.search([
+ ('account', 'in', [a.id for a in sub_accounts]),
+ ], order=[], limit=1)
+ if lines:
+ line, = lines
+ raise AccountValidationError(gettext(
+ 'analytic_account.msg_account_wrong_type_line',
+ account=line.account.rec_name))
+
@fields.depends('company')
def on_change_with_currency(self, name=None):
return self.company.currency if self.company else None
=====================================
modules/analytic_account/line.py
=====================================
@@ -29,11 +29,8 @@
account = fields.Many2One(
'analytic_account.account', "Account", required=True,
domain=[
- ('type', 'not in', ['view', 'distribution']),
- ['OR',
- ('company', '=', None),
- ('company', '=', Eval('company', -1)),
- ],
+ ('type', '=', 'normal'),
+ ('company', '=', Eval('company', -1)),
])
move_line = fields.Many2One('account.move.line', 'Account Move Line',
ondelete='CASCADE', required=True)
=====================================
modules/analytic_account/message.xml
=====================================
@@ -6,6 +6,9 @@
<record model="ir.message" id="msg_invalid_distribution">
<field name="text">To save account "%(account)s" the sum of their
distributions must be 100%%.</field>
</record>
+ <record model="ir.message" id="msg_account_wrong_type_line">
+ <field name="text">You cannot change the type of account
"%(account)s" because it has move lines.</field>
+ </record>
<record model="ir.message" id="msg_root_origin_unique">
<field name="text">Only one account is allowed by analytic root
and origin.</field>
</record>
View it on Heptapod:
https://foss.heptapod.net/tryton/tryton/-/compare/0a4e13728c0a9bb24536cb1033d95ca6749a2b9d...4c88fc43ec0a49f7d4fff4470ab80c751239fb23
--
View it on Heptapod:
https://foss.heptapod.net/tryton/tryton/-/compare/0a4e13728c0a9bb24536cb1033d95ca6749a2b9d...4c88fc43ec0a49f7d4fff4470ab80c751239fb23
You're receiving this email because of your account on foss.heptapod.net.