Skip to content
Snippets Groups Projects
Commit 883c03a0 authored by alsh-odoo's avatar alsh-odoo
Browse files

[FIX] hr_expense: raise exception if multiple company records selected

This traceback arises when the user selects multi
company records and click on the 'create report' button.

To reproduce this issue:

1) Install 'hr_expense'
2) Create a new company for example 'test'
3) Enable the 'test' company on the right corner
4) Now open 'employees' and change the company of the current user(Mitchel Admin)
   to the 'test'.
5) Open 'Expenses', create a new record, and change the company to 'test'.
6) Fill the required field values and save the record.
7) Now click 'My Expenses/My Expenses to report' and select all the records (Make sure
   'My Expenses' filter is applied)
8) Click on the 'Create Record' button

Error:- "ValueError: Expected singleton: res.company(2, 1)"

On the '_create_sheet_from_expenses' method, the value of 'company_id' is getting
through 'self.company_id.id'.
See:-
https://github.com/odoo/odoo/blob/f910987cb4af84c1e7afabf67f05d4eebc31e765/addons/hr_expense/models/hr_expense.py#L324-L335



But when user selects multi company recordsets
'self.company_id' has multi recordsets.

When 'company_id' is getting value through 'self.company_id.id', because of
'self.company_id' has multiple records, which leads
to the above traceback.

By applying this commit will resolve the issue by raising an exception,
when user selected multi company records to create report.

sentry-4465422743

closes odoo/odoo#135035

Signed-off-by: default avatarde Wouters de Bouchout Jean-Benoît (jbw) <jbw@odoo.com>
parent 10c4091f
No related branches found
No related tags found
No related merge requests found
...@@ -1802,6 +1802,12 @@ msgstr "" ...@@ -1802,6 +1802,12 @@ msgstr ""
msgid "You cannot refuse your own expenses" msgid "You cannot refuse your own expenses"
msgstr "" msgstr ""
#. module: hr_expense
#: code:addons/hr_expense/models/hr_expense.py:0
#, python-format
msgid "You cannot report expenses for different companies in the same report."
msgstr ""
#. module: hr_expense #. module: hr_expense
#: code:addons/hr_expense/models/hr_expense.py:0 #: code:addons/hr_expense/models/hr_expense.py:0
#, python-format #, python-format
......
...@@ -328,6 +328,8 @@ Or send your receipts at <a href="mailto:%(email)s?subject=Lunch%%20with%%20cust ...@@ -328,6 +328,8 @@ Or send your receipts at <a href="mailto:%(email)s?subject=Lunch%%20with%%20cust
raise UserError(_("You cannot report expenses for different employees in the same report.")) raise UserError(_("You cannot report expenses for different employees in the same report."))
if any(not expense.product_id for expense in self): if any(not expense.product_id for expense in self):
raise UserError(_("You can not create report without product.")) raise UserError(_("You can not create report without product."))
if len(self.company_id) != 1:
raise UserError(_("You cannot report expenses for different companies in the same report."))
todo = self.filtered(lambda x: x.payment_mode=='own_account') or self.filtered(lambda x: x.payment_mode=='company_account') todo = self.filtered(lambda x: x.payment_mode=='own_account') or self.filtered(lambda x: x.payment_mode=='company_account')
sheet = self.env['hr.expense.sheet'].create({ sheet = self.env['hr.expense.sheet'].create({
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment