From 1d00daf235b654018162138efac09efb56aa7c98 Mon Sep 17 00:00:00 2001 From: "Julien CHEVREAU (JCU)" Date: Tue, 24 Nov 2020 13:42:25 +0000 Subject: [PATCH] [IMP] account_reconcile_model: added company based domains on One2many and Many2many properties From now on, users will not be able to select journals, accounts or taxes pertaining to a company other than the one the reconciliation model is set up for. Up until now, when in superuser mode, and in a multi company environment, users could reference taxes, journals and accounts from all the companies. This allowed for misconfiguration ending in errors when using the reconciliation widget. Ticket #2375446 closes odoo/odoo#62636 X-original-commit: a3ce6c22d7a54fc89b7b7c8107ea31bec62f8705 Signed-off-by: oco-odoo Signed-off-by: Julien CHEVREAU --- addons/account/models/account_reconcile_model.py | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/addons/account/models/account_reconcile_model.py b/addons/account/models/account_reconcile_model.py index 638146de2f3fd..671f8710e27b9 100644 --- a/addons/account/models/account_reconcile_model.py +++ b/addons/account/models/account_reconcile_model.py @@ -29,7 +29,7 @@ class AccountReconcileModel(models.Model): # ===== Conditions ===== match_journal_ids = fields.Many2many('account.journal', string='Journals', - domain="[('type', 'in', ('bank', 'cash'))]", + domain="[('type', 'in', ('bank', 'cash')), ('company_id', '=', company_id)]", help='The reconciliation model will only be available from the selected journals.') match_nature = fields.Selection(selection=[ ('amount_received', 'Amount Received'), @@ -90,8 +90,8 @@ class AccountReconcileModel(models.Model): # ===== Write-Off ===== # First part fields. - account_id = fields.Many2one('account.account', string='Account', ondelete='cascade', domain=[('deprecated', '=', False)]) - journal_id = fields.Many2one('account.journal', string='Journal', ondelete='cascade', help="This field is ignored in a bank statement reconciliation.") + account_id = fields.Many2one('account.account', string='Account', ondelete='cascade', domain="[('deprecated', '=', False), ('company_id', '=', company_id)]") + journal_id = fields.Many2one('account.journal', string='Journal', ondelete='cascade', help="This field is ignored in a bank statement reconciliation.", domain="[('company_id', '=', company_id)]") label = fields.Char(string='Journal Item Label') amount_type = fields.Selection([ ('fixed', 'Fixed'), @@ -106,13 +106,12 @@ class AccountReconcileModel(models.Model): decimal_separator = fields.Char(default=lambda self: self.env['res.lang']._lang_get(self.env.user.lang).decimal_point, help="Every character that is nor a digit nor this separator will be removed from the matching string") tax_ids = fields.Many2many('account.tax', string='Taxes', ondelete='restrict') analytic_account_id = fields.Many2one('account.analytic.account', string='Analytic Account', ondelete='set null') - analytic_tag_ids = fields.Many2many('account.analytic.tag', string='Analytic Tags', + analytic_tag_ids = fields.Many2many('account.analytic.tag', string='Analytic Tags', domain="[('company_id', '=', company_id)]", relation='account_reconcile_model_analytic_tag_rel') - # Second part fields. has_second_line = fields.Boolean(string='Add a second line', default=False) - second_account_id = fields.Many2one('account.account', string='Second Account', ondelete='cascade', domain=[('deprecated', '=', False)]) - second_journal_id = fields.Many2one('account.journal', string='Second Journal', ondelete='cascade', help="This field is ignored in a bank statement reconciliation.") + second_account_id = fields.Many2one('account.account', string='Second Account', ondelete='cascade', domain="[('deprecated', '=', False), ('company_id', '=', company_id)]") + second_journal_id = fields.Many2one('account.journal', string='Second Journal', ondelete='cascade', help="This field is ignored in a bank statement reconciliation.", domain="[('company_id', '=', company_id)]") second_label = fields.Char(string='Second Journal Item Label') second_amount_type = fields.Selection([ ('fixed', 'Fixed'), @@ -126,7 +125,7 @@ class AccountReconcileModel(models.Model): second_amount_from_label_regex = fields.Char(string="Second Amount from Label (regex)", default=r"([\d\.,]+)") second_tax_ids = fields.Many2many('account.tax', relation='account_reconcile_model_account_tax_bis_rel', string='Second Taxes', ondelete='restrict') second_analytic_account_id = fields.Many2one('account.analytic.account', string='Second Analytic Account', ondelete='set null') - second_analytic_tag_ids = fields.Many2many('account.analytic.tag', string='Second Analytic Tags', + second_analytic_tag_ids = fields.Many2many('account.analytic.tag', string='Second Analytic Tags', domain="[('company_id', '=', company_id)]", relation='account_reconcile_model_second_analytic_tag_rel') number_entries = fields.Integer(string='Number of entries related to this model', compute='_compute_number_entries')