[FIX] hr_expense: enable change account for no-access users
Steps to reproduce: - install Expense and Accounting - create 3 separate Expense categories ( this will create a related product of 'service' type) with a different Expense account and Vendor tax on it. - Configuring different Taxes are important to replicate the issue - Create a 'test' user who has no access to apps - login a 'test' user and create an expense for one of the categories and save it. - Update the expense to a different category and click 'submit to Manager' Issue: The account_id of the expense is not updated Reason: Multiple fields are computed using the same method `_compute_from_product_id_company_id`. The field being read-only=False https://github.com/odoo/odoo/blob/c38cf4c2038d15890d5d50ec05fd5cb4f9f379b1/addons/hr_expense/views/hr_expense_views.xml#L199 It is protected during the write; that is, considered as user input Solution: Duplicate the field is it will not be read-only and put it as invisible Split the compute method opw-3336796 X-original-commit: 6664ccba5230d7890964cfe372ca863314f2fad4 Part-of: odoo/odoo#127794
This commit is contained in:
committed by
Nshimiyimana Séna
parent
9bdcb596ce
commit
033c446084
@@ -80,7 +80,7 @@ class HrExpense(models.Model):
|
||||
company_id = fields.Many2one('res.company', string='Company', required=True, readonly=True, states={'draft': [('readonly', False)], 'refused': [('readonly', False)]}, default=lambda self: self.env.company)
|
||||
currency_id = fields.Many2one('res.currency', string='Currency', required=True, readonly=False, store=True, states={'reported': [('readonly', True)], 'approved': [('readonly', True)], 'done': [('readonly', True)]}, compute='_compute_currency_id', default=lambda self: self.env.company.currency_id)
|
||||
currency_rate = fields.Float(compute='_compute_currency_rate')
|
||||
account_id = fields.Many2one('account.account', compute='_compute_from_product_id_company_id', store=True, readonly=False, precompute=True, string='Account',
|
||||
account_id = fields.Many2one('account.account', compute='_compute_account_id_from_product_id_company_id', store=True, readonly=False, precompute=True, string='Account',
|
||||
domain="[('account_type', 'not in', ('asset_receivable','liability_payable','asset_cash','liability_credit_card')), ('company_id', '=', company_id)]", help="An expense account is expected")
|
||||
description = fields.Text('Internal Notes', readonly=True, states={'draft': [('readonly', False)], 'reported': [('readonly', False)], 'refused': [('readonly', False)]})
|
||||
payment_mode = fields.Selection([
|
||||
@@ -285,6 +285,10 @@ class HrExpense(models.Model):
|
||||
expense.name = expense.name or expense.product_id.display_name
|
||||
expense.product_uom_id = expense.product_id.uom_id
|
||||
expense.tax_ids = expense.product_id.supplier_taxes_id.filtered(lambda tax: tax.company_id == expense.company_id) # taxes only from the same company
|
||||
|
||||
@api.depends('product_id', 'company_id')
|
||||
def _compute_account_id_from_product_id_company_id(self):
|
||||
for expense in self:
|
||||
account = expense.product_id.product_tmpl_id._get_product_accounts()['expense']
|
||||
if account:
|
||||
expense.account_id = account
|
||||
|
||||
Reference in New Issue
Block a user