diff --git a/addons/account/data/data_account_type.xml b/addons/account/data/data_account_type.xml index 05f4a76bf36..ca4676f05f0 100644 --- a/addons/account/data/data_account_type.xml +++ b/addons/account/data/data_account_type.xml @@ -96,6 +96,10 @@ other expense + + Off-Balance Sheet + other + off_balance + - diff --git a/addons/account/models/account.py b/addons/account/models/account.py index 8968ce5a40a..92a94fab82c 100644 --- a/addons/account/models/account.py +++ b/addons/account/models/account.py @@ -39,6 +39,7 @@ class AccountAccountType(models.Model): ('liability', 'Liability'), ('income', 'Income'), ('expense', 'Expense'), + ('off_balance', 'Off Balance'), ], string="Internal Group", help="The 'Internal Group' is used to filter accounts based on the internal group set on the account type.") note = fields.Text(string='Description') @@ -231,6 +232,15 @@ class AccountAccount(models.Model): ('code_company_uniq', 'unique (code,company_id)', 'The code of the account must be unique per company !') ] + @api.constrains('reconcile', 'internal_group', 'tax_ids') + def _constrains_reconcile(self): + for record in self: + if record.internal_group == 'off_balance': + if record.reconcile: + raise UserError(_('An Off-Balance account can not be reconcilable')) + if record.tax_ids: + raise UserError(_('An Off-Balance account can not have taxes')) + @api.model def _search_new_account_code(self, company, digits, prefix): for num in range(1, 10000): @@ -330,12 +340,16 @@ class AccountAccount(models.Model): account_ids = self._search(expression.AND([domain, args]), limit=limit, access_rights_uid=name_get_uid) return self.browse(account_ids).name_get() - @api.onchange('internal_type') - def onchange_internal_type(self): + @api.onchange('user_type_id') + def _onchange_user_type_id(self): self.reconcile = self.internal_type in ('receivable', 'payable') if self.internal_type == 'liquidity': self.reconcile = False + if self.internal_group == 'off_balance': + self.reconcile = False + self.tax_ids = False + @api.onchange('code') def onchange_code(self): AccountGroup = self.env['account.group'] diff --git a/addons/account/models/account_move.py b/addons/account/models/account_move.py index 647043e8d81..9fb8b0a5cd4 100644 --- a/addons/account/models/account_move.py +++ b/addons/account/models/account_move.py @@ -2727,6 +2727,17 @@ class AccountMoveLine(models.Model): 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.')) + @api.constrains('account_id', 'tax_ids', 'tax_line_id', 'reconciled') + def _check_off_balance(self): + for line in self: + if line.account_id.internal_group == 'off_balance': + if any(a.internal_group != line.account_id.internal_group for a in line.move_id.line_ids.account_id): + raise UserError(_('If you want to use "Off-Balance Sheet" accounts, all the accounts of the journal entry must be of this type')) + if line.tax_ids or line.tax_line_id: + raise UserError(_('You cannot use taxes on lines with an Off-Balance account')) + if line.reconciled: + raise UserError(_('Lines from "Off-Balance Sheet" accounts cannot be reconciled')) + @api.constrains('tax_ids', 'tax_line_id') def _check_tax_lock_date1(self): for line in self: diff --git a/addons/account/views/account_view.xml b/addons/account/views/account_view.xml index 767d6779c79..0fec57c4c87 100644 --- a/addons/account/views/account_view.xml +++ b/addons/account/views/account_view.xml @@ -16,14 +16,15 @@ - + -