[IMP] hr_expense: avoid adding wrong expense_line_ids

You cannot validate and expense report having expense_line_ids of
different payment mode.
But so far, it was possible to select these lines, and it would
be blocked upon saving.

We will improve this behavior by extending the domain on the
expense_line_ids field and disallowing to add lines that would lead to
an error later in the process.

It will also correctly handle the creation of new line via the expense
report form view, and add the paid by field as optional hidden in the
view in order to allow to find more easily the expense line that are
causing issues.

task id # 3221780

closes odoo/odoo#116077

X-original-commit: ec18bd414c831a9af67802dcd5d7181ef8d43049
Signed-off-by: Florian Gilbert (flg) <flg@odoo.com>
Signed-off-by: Nicolas Viseur (vin) <vin@odoo.com>
This commit is contained in:
Nicolas (vin)
2023-03-23 08:01:08 +01:00
parent 7f2e9b852a
commit 783733cf33
2 changed files with 14 additions and 3 deletions
+1 -1
View File
@@ -1005,7 +1005,7 @@ class HrExpenseSheet(models.Model):
for sheet in self:
expense_lines = sheet.mapped('expense_line_ids')
if expense_lines and any(expense.payment_mode != expense_lines[0].payment_mode for expense in expense_lines):
raise ValidationError(_("Expenses must have the same To Reimburse status."))
raise ValidationError(_("All expenses in an expense report must have the same \"paid by\" criteria."))
@api.depends('expense_line_ids')
def _compute_product_ids(self):
+13 -2
View File
@@ -761,9 +761,20 @@
nolabel="1"
widget="many2many"
mode="tree,kanban"
domain="[('state', '=', 'draft'), ('employee_id', '=', employee_id), ('company_id', '=', company_id)]"
domain="[
('state', '=', 'draft'),
('employee_id', '=', employee_id),
('company_id', '=', company_id),
('payment_mode', '=?', payment_mode),
]"
options="{'reload_on_button': True}"
context="{'form_view_ref' : 'hr_expense.hr_expense_view_form_without_header', 'default_company_id': company_id, 'default_employee_id': employee_id}"
context="{
'form_view_ref' : 'hr_expense.hr_expense_view_form_without_header',
'default_company_id': company_id,
'default_employee_id': employee_id,
'default_sheet_id': active_id,
'default_payment_mode': payment_mode,
}"
attrs="{'readonly': [('is_editable', '=', False)]}"
force_save="1">
<tree editable="bottom" class="o_expense_line_list">