Skip to content
Permalink
Browse files

[IMP] account: Control Access: Journals that can be allowed by accounts

Task 2074811

Allow to specify on an account the journals that can be allowed

Example of use case :
    I create an IFRS journal and some specific IFRS accounts
    I want to make sure that the accounts I configured for the IFRS are only use to make entries in the IFRS journal
  • Loading branch information...
william-andre committed Oct 9, 2019
1 parent 9784236 commit 196acfca05ee2e097f34b66e99fa7a4ff0b25b7c
Showing with 22 additions and 12 deletions.
  1. +16 −3 addons/account/models/account.py
  2. +4 −5 addons/account/models/account_move.py
  3. +2 −4 addons/account/views/account_view.xml
@@ -228,6 +228,8 @@ def _check_user_type_id(self):
tag_ids = fields.Many2many('account.account.tag', 'account_account_account_tag', string='Tags', help="Optional tags you may want to assign for custom reporting")
group_id = fields.Many2one('account.group')
root_id = fields.Many2one('account.root', compute='_compute_account_root', store=True)
allowed_journal_ids = fields.Many2many('account.journal', string="Allowed Journals", help="Define in which journals this account can be used. If empty, can be used in all journals.")
# TODO WAN need to add it on account type too (with onchange)?

opening_debit = fields.Monetary(string="Opening debit", compute='_compute_opening_debit_credit', inverse='_set_opening_debit', help="Opening debit value for this account.")
opening_credit = fields.Monetary(string="Opening credit", compute='_compute_opening_debit_credit', inverse='_set_opening_credit', help="Opening credit value for this account.")
@@ -245,6 +247,20 @@ def _constrains_reconcile(self):
if record.tax_ids:
raise UserError(_('An Off-Balance account can not have taxes'))

@api.constrains('allowed_journal_ids')
def _constrains_allowed_journal_ids(self):
self.env['account.move.line'].flush(['account_id', 'journal_id'])
self.flush(['allowed_journal_ids'])
self._cr.execute("""
SELECT aml.id
FROM account_move_line aml
WHERE aml.account_id in (%s)
AND EXISTS (SELECT 1 FROM account_account_account_journal_rel WHERE account_account_id = aml.account_id)
AND NOT EXISTS(SELECT 1 FROM account_account_account_journal_rel WHERE account_account_id = aml.account_id AND account_journal_id = aml.journal_id)
""", tuple(self.ids))
if self._cr.fetchone():
raise ValidationError(_('Some lines already exist with this account but in other journals than the allowed ones.'))

@api.depends('code')
def _compute_account_root(self):
# this computes the first 2 digits of the account.
@@ -630,9 +646,6 @@ def _get_bank_statements_available_sources(self):
"Select 'Purchase' for vendor bills journals.\n"\
"Select 'Cash' or 'Bank' for journals that are used in customer or vendor payments.\n"\
"Select 'General' for miscellaneous operations journals.")
type_control_ids = fields.Many2many('account.account.type', 'account_journal_type_rel', 'journal_id', 'type_id', string='Account Types Allowed')
account_control_ids = fields.Many2many('account.account', 'account_account_type_rel', 'journal_id', 'account_id', string='Accounts Allowed',
domain="[('deprecated', '=', False), ('company_id', '=', company_id)]")
default_credit_account_id = fields.Many2one('account.account', string='Default Credit Account',
domain=[('deprecated', '=', False)], help="It acts as a default account for credit amount",
ondelete='restrict')
@@ -2982,7 +2982,7 @@ def _compute_tax_audit(self):
# CONSTRAINT METHODS
# -------------------------------------------------------------------------

@api.constrains('account_id')
@api.constrains('account_id', 'journal_id')
def _check_constrains_account_id(self):
for line in self:
account = line.account_id
@@ -2991,10 +2991,9 @@ def _check_constrains_account_id(self):
if account.deprecated:
raise UserError(_('The account %s (%s) is deprecated.') % (account.name, account.code))

control_type_failed = journal.type_control_ids and account.user_type_id not in journal.type_control_ids
control_account_failed = journal.account_control_ids and account not in journal.account_control_ids
if control_type_failed or control_account_failed:
raise UserError(_('You cannot use this general account in this journal, check the tab \'Entry Controls\' on the related journal.'))
control_account_failed = account.allowed_journal_ids and journal not in account.allowed_journal_ids
if control_account_failed:
raise UserError(_('You cannot use this account (%s) in this journal, check the field \'Allowed Journals\' on the related account.') % account.display_name)

@api.constrains('account_id', 'tax_ids', 'tax_line_id', 'reconciled')
def _check_off_balance(self):
@@ -19,6 +19,7 @@
<field name="tax_ids" widget="many2many_tags" domain="[('company_id','=',company_id)]" attrs="{'invisible': [('internal_group', '=', 'off_balance')]}"/>
<field name="tag_ids" widget="many2many_tags" domain="[('applicability', '!=', 'taxes')]" context="{'default_applicability': 'accounts'}" options="{'no_create_edit': True}"/>
<field name="group_id"/>
<field name="allowed_journal_ids" widget="many2many_tags" domain="[('company_id','=',company_id)]" options="{'no_create_edit': True}"/>
<field name="company_id" options="{'no_create': True}" groups="base.group_multi_company"/>
<field name="currency_id" options="{'no_create': True}" groups="base.group_multi_currency"/>
<field name="internal_type" invisible="1" readonly="1"/>
@@ -315,10 +316,7 @@
<field name="loss_account_id" options="{'no_create': True}" attrs="{'invisible': [('type', '!=', 'cash')]}"/>
<field name="post_at" widget="radio" attrs="{'invisible': [('type', 'not in', ['bank', 'cash'])]}"/>
</group>
<group string="Control-Access" groups="account.group_account_manager">
<div class="text-muted" colspan="2">Keep empty for no control</div>
<field name="type_control_ids" widget="many2many_tags"/>
<field name="account_control_ids" widget="many2many_tags"/>
<group string="Control-Access" groups="account.group_account_manager"> <!-- TODO WAN is control-access still the right label -->
<field name="restrict_mode_hash_table" groups="account.group_account_user"/>
</group>
<group string="Payment Method Types" attrs="{'invisible': [('type', 'not in', ['bank', 'cash'])]}">

0 comments on commit 196acfc

Please sign in to comment.
You can’t perform that action at this time.