Skip to content

Commit

Permalink
[FIX] hr_expense: enable change account for no-access users
Browse files Browse the repository at this point in the history
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: 6664ccb
Part-of: odoo#127794
  • Loading branch information
yosa-odoo authored and ushyme committed Jul 7, 2023
1 parent 9bdcb59 commit 033c446
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion addons/hr_expense/models/hr_expense.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def _get_employee_id_domain(self):
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([
Expand Down Expand Up @@ -285,6 +285,10 @@ def _compute_from_product_id_company_id(self):
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
Expand Down

0 comments on commit 033c446

Please sign in to comment.