From 8e52c36a56fba47fd4e3f37e860e822c048abc76 Mon Sep 17 00:00:00 2001 From: Prakash Prajapati Date: Wed, 16 Mar 2022 11:11:08 +0000 Subject: [PATCH] [ADD] hr_timesheet_attendance: add test for timesheet/attendance report task-2727561 Part-of: odoo/odoo#86914 --- .../hr_timesheet_attendance/tests/__init__.py | 4 +++ .../tests/test_timesheet_attendance.py | 35 +++++++++++++++++++ 2 files changed, 39 insertions(+) create mode 100644 addons/hr_timesheet_attendance/tests/__init__.py create mode 100644 addons/hr_timesheet_attendance/tests/test_timesheet_attendance.py diff --git a/addons/hr_timesheet_attendance/tests/__init__.py b/addons/hr_timesheet_attendance/tests/__init__.py new file mode 100644 index 00000000000..d306e07cf5c --- /dev/null +++ b/addons/hr_timesheet_attendance/tests/__init__.py @@ -0,0 +1,4 @@ +# -*- coding: utf-8 -*- +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +from . import test_timesheet_attendance diff --git a/addons/hr_timesheet_attendance/tests/test_timesheet_attendance.py b/addons/hr_timesheet_attendance/tests/test_timesheet_attendance.py new file mode 100644 index 00000000000..775edb5b603 --- /dev/null +++ b/addons/hr_timesheet_attendance/tests/test_timesheet_attendance.py @@ -0,0 +1,35 @@ +# -*- coding: utf-8 -*- +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +from datetime import datetime + +from odoo.tests import tagged +from odoo.addons.hr_timesheet.tests.test_timesheet import TestCommonTimesheet + +@tagged('post_install', '-at_install') +class TestTimesheetAttendance(TestCommonTimesheet): + @classmethod + def setUpClass(cls): + super().setUpClass() + cls.env['hr.attendance'].create({ + 'employee_id': cls.empl_employee.id, + 'check_in': datetime(2022, 2, 9, 8, 0), # Wednesday + 'check_out': datetime(2022, 2, 9, 16, 0), + }) + + def test_timesheet_attendance_report(self): + self.env['account.analytic.line'].with_user(self.user_employee).create({ + 'name': 'Test timesheet 1', + 'project_id': self.project_customer.id, + 'unit_amount': 6.0, + 'date': datetime(2022, 2, 9), + }) + report_data = self.env['hr.timesheet.attendance.report']._read_group( + [('user_id', '=', self.user_employee.id), + ('date', '>=', datetime(2022, 2, 9, 8, 0)), ('date', '<=', datetime(2022, 2, 9, 16, 0))], + ['total_timesheet', 'total_attendance', 'total_difference'], + ['user_id'], + )[0] + self.assertEqual(report_data['total_timesheet'], 6.0, "Total timesheet in report should be 4.0") + self.assertEqual(report_data['total_attendance'], 8.0, "Total attendance in report should be 8.0") + self.assertEqual(report_data['total_attendance'] - report_data['total_timesheet'], 2)