Skip to content

Commit

Permalink
[FIX] hr_expense: default_expense_line_ids can be used multi time
Browse files Browse the repository at this point in the history
Create an expense
Click "Create report"
Save the report A (you can also submit, post inventory, ...)
Now click on Create (a new report B)

The expense in A are copied in B because default_expense_line_ids
are not cleared

Closes odoo#52457

opw-2271851

closes odoo#52830

Signed-off-by: Nicolas Martinelli (nim) <[email protected]>
  • Loading branch information
fmdl authored and nim-odoo committed Jun 11, 2020
1 parent 293ccca commit e8cee2d
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions addons/hr_expense/models/hr_expense.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ def action_view_sheet(self):
'res_id': self.sheet_id.id
}

def action_submit_expenses(self):
def _create_sheet_from_expenses(self):
if any(expense.state != 'draft' or expense.sheet_id for expense in self):
raise UserError(_("You cannot report twice the same line!"))
if len(self.mapped('employee_id')) != 1:
Expand All @@ -264,18 +264,24 @@ def action_submit_expenses(self):
raise UserError(_("You can not create report without product."))

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({
'company_id': self.company_id.id,
'employee_id': self[0].employee_id.id,
'name': todo[0].name if len(todo) == 1 else '',
'expense_line_ids': [(6, 0, todo.ids)]
})
sheet._onchange_employee_id()
return sheet

def action_submit_expenses(self):
sheet = self._create_sheet_from_expenses()
return {
'name': _('New Expense Report'),
'type': 'ir.actions.act_window',
'view_mode': 'form',
'res_model': 'hr.expense.sheet',
'target': 'current',
'context': {
'default_expense_line_ids': todo.ids,
'default_company_id': self.company_id.id,
'default_employee_id': self[0].employee_id.id,
'default_name': todo[0].name if len(todo) == 1 else ''
}
'res_id': sheet.id,
}

def action_get_attachment_view(self):
Expand Down

0 comments on commit e8cee2d

Please sign in to comment.