File: test_timesheet_attendance.py

package info (click to toggle)
odoo 18.0.0%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 878,716 kB
  • sloc: javascript: 927,937; python: 685,670; xml: 388,524; sh: 1,033; sql: 415; makefile: 26
file content (34 lines) | stat: -rw-r--r-- 1,520 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# -*- 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),
        })
        total_timesheet, total_attendance = self.env['hr.timesheet.attendance.report']._read_group(
            [('employee_id', '=', self.empl_employee.id),
            ('date', '>=', datetime(2022, 2, 9, 8, 0)), ('date', '<=', datetime(2022, 2, 9, 16, 0))],
            aggregates=['total_timesheet:sum', 'total_attendance:sum'],
        )[0]
        self.assertEqual(total_timesheet, 6.0, "Total timesheet in report should be 4.0")
        self.assertEqual(total_attendance, 7.0, "Total attendance in report should be 8.0")
        self.assertEqual(total_attendance - total_timesheet, 1)