From 7354da69232bcd03d50cb1232e0bec802bd1ef7e Mon Sep 17 00:00:00 2001 From: "Nicolas (vin)" Date: Thu, 16 Jul 2020 08:50:27 +0000 Subject: [PATCH] [IMP] account: Accounts m2o behavior There are inconsistencies in the m2o accounts create & edit behavior. New off-balance account type was not correctly filtered This change correct those two issues Task ID: #2288757 closes odoo/odoo#54626 Related: odoo/enterprise#11920 Signed-off-by: Cedric Snauwaert (csn) --- addons/account/models/account_account.py | 9 ++++++++- addons/account/models/account_journal.py | 6 +++--- addons/account/models/account_move.py | 2 +- .../account/models/account_reconcile_model.py | 2 +- addons/account/models/product.py | 2 +- .../tests/test_templates_consistency.py | 2 +- .../account/views/account_journal_views.xml | 20 +++++++++---------- addons/account/views/account_move_views.xml | 3 ++- addons/account/views/account_payment_view.xml | 1 + .../account/wizard/wizard_tax_adjustments.py | 6 ++++-- .../wizard/wizard_tax_adjustments_view.xml | 4 ++-- odoo/addons/base/models/res_bank.py | 2 +- 12 files changed, 35 insertions(+), 24 deletions(-) diff --git a/addons/account/models/account_account.py b/addons/account/models/account_account.py index e6a540a9167..6dc128dc316 100644 --- a/addons/account/models/account_account.py +++ b/addons/account/models/account_account.py @@ -35,7 +35,7 @@ class AccountAccountType(models.Model): class AccountAccount(models.Model): _name = "account.account" _description = "Account" - _order = "code, company_id" + _order = "is_off_balance, code, company_id" _check_company_auto = True @api.constrains('internal_type', 'reconcile') @@ -84,6 +84,8 @@ class AccountAccount(models.Model): opening_credit = fields.Monetary(string="Opening Credit", compute='_compute_opening_debit_credit', inverse='_set_opening_credit', help="Opening credit value for this account.") opening_balance = fields.Monetary(string="Opening Balance", compute='_compute_opening_debit_credit', help="Opening balance value for this account.") + is_off_balance = fields.Boolean(compute='_compute_is_off_balance', default=False, store=True, readonly=True) + _sql_constraints = [ ('code_company_uniq', 'unique (code,company_id)', 'The code of the account must be unique per company !') ] @@ -242,6 +244,11 @@ class AccountAccount(models.Model): record.opening_credit = res['credit'] record.opening_balance = res['balance'] + @api.depends('internal_group') + def _compute_is_off_balance(self): + for account in self: + account.is_off_balance = account.internal_group == "off_balance" + def _set_opening_debit(self): self._set_opening_debit_credit(self.opening_debit, 'debit') diff --git a/addons/account/models/account_journal.py b/addons/account/models/account_journal.py index 35929adb61d..2a389ff33a9 100644 --- a/addons/account/models/account_journal.py +++ b/addons/account/models/account_journal.py @@ -53,10 +53,10 @@ class AccountJournal(models.Model): "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', 'journal_account_type_control_rel', 'journal_id', 'type_id', string='Account Types Allowed') - account_control_ids = fields.Many2many('account.account', 'journal_account_control_rel', 'journal_id', 'account_id', string='Accounts Allowed', + type_control_ids = fields.Many2many('account.account.type', 'journal_account_type_control_rel', 'journal_id', 'type_id', string='Allowed account types') + account_control_ids = fields.Many2many('account.account', 'journal_account_control_rel', 'journal_id', 'account_id', string='Allowed accounts', check_company=True, - domain="[('deprecated', '=', False), ('company_id', '=', company_id)]") + domain="[('deprecated', '=', False), ('company_id', '=', company_id), ('is_off_balance', '=', False)]") default_account_type = fields.Many2one('account.account.type', compute="_compute_default_account_type") default_account_id = fields.Many2one( comodel_name='account.account', check_company=True, copy=False, ondelete='restrict', diff --git a/addons/account/models/account_move.py b/addons/account/models/account_move.py index 53b017c6b68..f917ae40c55 100644 --- a/addons/account/models/account_move.py +++ b/addons/account/models/account_move.py @@ -2699,7 +2699,7 @@ class AccountMoveLine(models.Model): country_id = fields.Many2one(comodel_name='res.country', related='move_id.company_id.country_id') account_id = fields.Many2one('account.account', string='Account', index=True, ondelete="cascade", - domain="[('deprecated', '=', False), ('company_id', '=', company_id)]", + domain="[('deprecated', '=', False), ('company_id', '=', 'company_id'),('is_off_balance', '=', False)]", check_company=True, tracking=True) account_internal_type = fields.Selection(related='account_id.user_type_id.type', string="Internal Type", readonly=True) diff --git a/addons/account/models/account_reconcile_model.py b/addons/account/models/account_reconcile_model.py index 6f840f25eb4..d4eca545eeb 100644 --- a/addons/account/models/account_reconcile_model.py +++ b/addons/account/models/account_reconcile_model.py @@ -38,7 +38,7 @@ class AccountReconcileModelLine(models.Model): company_id = fields.Many2one(related='model_id.company_id', store=True, default=lambda self: self.env.company) sequence = fields.Integer(required=True, default=10) account_id = fields.Many2one('account.account', string='Account', ondelete='cascade', - domain="[('deprecated', '=', False), ('company_id', '=', company_id)]", + domain="[('deprecated', '=', False), ('company_id', '=', company_id), ('is_off_balance', '=', False)]", required=True, check_company=True) journal_id = fields.Many2one('account.journal', string='Journal', ondelete='cascade', domain="[('type', '=', 'general'), ('company_id', '=', company_id)]", diff --git a/addons/account/models/product.py b/addons/account/models/product.py index eb9256d7a36..14db12e45a4 100644 --- a/addons/account/models/product.py +++ b/addons/account/models/product.py @@ -2,7 +2,7 @@ from odoo import api, fields, models, _ -ACCOUNT_DOMAIN = "['&', '&', ('deprecated', '=', False), ('internal_type','=','other'), ('company_id', '=', current_company_id)]" +ACCOUNT_DOMAIN = "['&', '&', '&', ('deprecated', '=', False), ('internal_type','=','other'), ('company_id', '=', current_company_id), ('is_off_balance', '=', False)]" class ProductCategory(models.Model): _inherit = "product.category" diff --git a/addons/account/tests/test_templates_consistency.py b/addons/account/tests/test_templates_consistency.py index aabf0f2d765..656f2d1bf6b 100644 --- a/addons/account/tests/test_templates_consistency.py +++ b/addons/account/tests/test_templates_consistency.py @@ -34,7 +34,7 @@ class AccountingTestTemplConsistency(TransactionCase): self.check_fields_consistency( 'account.account.template', 'account.account', exceptions=['chart_template_id', 'nocreate']) self.check_fields_consistency( - 'account.account', 'account.account.template', exceptions=['company_id', 'deprecated', 'opening_debit', 'opening_credit', 'allowed_journal_ids', 'group_id', 'root_id']) + 'account.account', 'account.account.template', exceptions=['company_id', 'deprecated', 'opening_debit', 'opening_credit', 'allowed_journal_ids', 'group_id', 'root_id', 'is_off_balance']) def test_account_tax_fields(self): '''Test fields consistency for ('account.tax', 'account.tax.template') diff --git a/addons/account/views/account_journal_views.xml b/addons/account/views/account_journal_views.xml index 3f20fe92429..2567bf53215 100644 --- a/addons/account/views/account_journal_views.xml +++ b/addons/account/views/account_journal_views.xml @@ -44,25 +44,25 @@ - - - - - + + - - @@ -79,14 +79,14 @@ - - diff --git a/addons/account/views/account_move_views.xml b/addons/account/views/account_move_views.xml index 92ab0e8f727..aed046689f0 100644 --- a/addons/account/views/account_move_views.xml +++ b/addons/account/views/account_move_views.xml @@ -715,7 +715,8 @@ diff --git a/addons/account/wizard/wizard_tax_adjustments.py b/addons/account/wizard/wizard_tax_adjustments.py index c771d838044..9d011daf837 100644 --- a/addons/account/wizard/wizard_tax_adjustments.py +++ b/addons/account/wizard/wizard_tax_adjustments.py @@ -14,8 +14,10 @@ class TaxAdjustments(models.TransientModel): reason = fields.Char(string='Justification', required=True) journal_id = fields.Many2one('account.journal', string='Journal', required=True, default=_get_default_journal, domain=[('type', '=', 'general')]) date = fields.Date(required=True, default=fields.Date.context_today) - debit_account_id = fields.Many2one('account.account', string='Debit account', required=True, domain=[('deprecated', '=', False)]) - credit_account_id = fields.Many2one('account.account', string='Credit account', required=True, domain=[('deprecated', '=', False)]) + debit_account_id = fields.Many2one('account.account', string='Debit account', required=True, + domain="[('deprecated', '=', False), ('is_off_balance', '=', False)]") + credit_account_id = fields.Many2one('account.account', string='Credit account', required=True, + domain="[('deprecated', '=', False), ('is_off_balance', '=', False)]") amount = fields.Monetary(currency_field='company_currency_id', required=True) adjustment_type = fields.Selection([('debit', 'Applied on debit journal item'), ('credit', 'Applied on credit journal item')], string="Adjustment Type", required=True) tax_report_line_id = fields.Many2one(string="Report Line", comodel_name='account.tax.report.line', required=True, help="The report line to make an adjustment for.") diff --git a/addons/account/wizard/wizard_tax_adjustments_view.xml b/addons/account/wizard/wizard_tax_adjustments_view.xml index 564eec16c22..a2ea4a65248 100644 --- a/addons/account/wizard/wizard_tax_adjustments_view.xml +++ b/addons/account/wizard/wizard_tax_adjustments_view.xml @@ -21,8 +21,8 @@ - - + + diff --git a/odoo/addons/base/models/res_bank.py b/odoo/addons/base/models/res_bank.py index 284a995645d..268a6668e44 100644 --- a/odoo/addons/base/models/res_bank.py +++ b/odoo/addons/base/models/res_bank.py @@ -87,7 +87,7 @@ class ResPartnerBank(models.Model): bank_bic = fields.Char(related='bank_id.bic', readonly=False) sequence = fields.Integer(default=10) currency_id = fields.Many2one('res.currency', string='Currency') - company_id = fields.Many2one('res.company', 'Company', default=lambda self: self.env.company, ondelete='cascade') + company_id = fields.Many2one('res.company', 'Company', default=lambda self: self.env.company, ondelete='cascade', readonly=True) _sql_constraints = [ ('unique_number', 'unique(sanitized_acc_number, company_id)', 'Account Number must be unique'),