Skip to content

Commit

Permalink
[ADD] hr_expense_operating_unit: test for onchange function
Browse files Browse the repository at this point in the history
  • Loading branch information
hbrunn committed Aug 8, 2024
1 parent dfe3663 commit e6136cd
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
2 changes: 1 addition & 1 deletion hr_expense_operating_unit/models/hr_expense.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ class HrExpenseSheet(models.Model):
@api.onchange("operating_unit_id")
def _onchange_operating_unit_id(self):
if self.operating_unit_id:
self.expense_line_ids.write(
self.expense_line_ids.update(
{"operating_unit_id": self.operating_unit_id.id}
)

Expand Down
23 changes: 23 additions & 0 deletions hr_expense_operating_unit/tests/test_hr_expense_operating_unit.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,3 +195,26 @@ def test_constrains_error(self):

with self.assertRaises(ValidationError):
self.hr_expense3.action_submit_expenses()

def test_onchange(self):
"""Test that onchange works as expected"""
hr_expense_dict1 = self.hr_expense1.action_submit_expenses()
sheet_context = hr_expense_dict1.get("context")
sheet_dict = {
"name": sheet_context.get("default_name", ""),
"employee_id": sheet_context.get("default_employee_id", False),
"company_id": sheet_context.get("default_company_id", False),
"state": sheet_context.get("default_state", ""),
"expense_line_ids": sheet_context.get("default_expense_line_ids", []),
}
sheet = self.hr_expense_sheet_model.create(sheet_dict)
self.assertEqual(sheet.operating_unit_id, self.ou1)
self.assertEqual(sheet.expense_line_ids.operating_unit_id, self.ou1)
sheet.operating_unit_id = self.env["operating.unit"]
sheet.env.flush_all()
self.assertEqual(sheet.expense_line_ids.operating_unit_id, self.ou1)
sheet.expense_line_ids.operating_unit_id = self.env["operating.unit"]
sheet.env.flush_all()
sheet.operating_unit_id = self.b2c
sheet._onchange_operating_unit_id()
self.assertEqual(sheet.expense_line_ids.operating_unit_id, self.b2c)

0 comments on commit e6136cd

Please sign in to comment.