From 21e30ca209798c4265fad1fee0ce825d4402bbbe Mon Sep 17 00:00:00 2001 From: william-andre Date: Mon, 2 Aug 2021 09:11:10 +0000 Subject: [PATCH] [FIX] account: automatic entry rights for non db admins MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The non readonly computed field with inverse on the company was raising an access error for users that have accounting rights but not admin rights to write on the company. opw-2446242 closes odoo/odoo#74643 X-original-commit: 0b2fa7b0e5d826b1ba08cd7723a3f40b792e82ba Signed-off-by: Laurent Smet Signed-off-by: William André (wan) --- .../wizard/account_automatic_entry_wizard.py | 38 +++++++++++++++++-- 1 file changed, 35 insertions(+), 3 deletions(-) diff --git a/addons/account/wizard/account_automatic_entry_wizard.py b/addons/account/wizard/account_automatic_entry_wizard.py index 4c572db723c..b0089c07d4b 100644 --- a/addons/account/wizard/account_automatic_entry_wizard.py +++ b/addons/account/wizard/account_automatic_entry_wizard.py @@ -23,7 +23,8 @@ class AutomaticEntryWizard(models.TransientModel): total_amount = fields.Monetary(compute='_compute_total_amount', store=True, readonly=False, currency_field='company_currency_id', help="Total amount impacted by the automatic entry.") journal_id = fields.Many2one('account.journal', required=True, readonly=False, string="Journal", domain="[('company_id', '=', company_id), ('type', '=', 'general')]", - related="company_id.automatic_entry_default_journal_id", + compute="_compute_journal_id", + inverse="_inverse_journal_id", help="Journal where to create the entry.") # change period @@ -32,18 +33,49 @@ class AutomaticEntryWizard(models.TransientModel): domain="[('company_id', '=', company_id)," "('internal_type', 'not in', ('receivable', 'payable'))," "('is_off_balance', '=', False)]", - related="company_id.expense_accrual_account_id") + compute="_compute_expense_accrual_account", + inverse="_inverse_expense_accrual_account", + ) revenue_accrual_account = fields.Many2one('account.account', readonly=False, domain="[('company_id', '=', company_id)," "('internal_type', 'not in', ('receivable', 'payable'))," "('is_off_balance', '=', False)]", - related="company_id.revenue_accrual_account_id") + compute="_compute_revenue_accrual_account", + inverse="_inverse_revenue_accrual_account", + ) # change account destination_account_id = fields.Many2one(string="To", comodel_name='account.account', help="Account to transfer to.") display_currency_helper = fields.Boolean(string="Currency Conversion Helper", compute='_compute_display_currency_helper', help="Technical field. Used to indicate whether or not to display the currency conversion tooltip. The tooltip informs a currency conversion will be performed with the transfer.") + @api.depends('company_id') + def _compute_expense_accrual_account(self): + for record in self: + record.expense_accrual_account = record.company_id.expense_accrual_account_id + + def _inverse_expense_accrual_account(self): + for record in self: + record.company_id.sudo().expense_accrual_account_id = record.expense_accrual_account + + @api.depends('company_id') + def _compute_revenue_accrual_account(self): + for record in self: + record.revenue_accrual_account = record.company_id.revenue_accrual_account_id + + def _inverse_revenue_accrual_account(self): + for record in self: + record.company_id.sudo().revenue_accrual_account_id = record.revenue_accrual_account + + @api.depends('company_id') + def _compute_journal_id(self): + for record in self: + record.journal_id = record.company_id.automatic_entry_default_journal_id + + def _inverse_journal_id(self): + for record in self: + record.company_id.sudo().automatic_entry_default_journal_id = record.journal_id + @api.constrains('percentage', 'action') def _constraint_percentage(self): for record in self: