Exemplo n.º 1
0
    def test_mark_attendance_and_link_log(self):
        employee = make_employee(
            "*****@*****.**")
        logs = make_n_checkins(employee, 3)
        mark_attendance_and_link_log(logs, 'Skip', nowdate())
        log_names = [log.name for log in logs]
        logs_count = frappe.db.count('Employee Checkin', {
            'name': ['in', log_names],
            'skip_auto_attendance': 1
        })
        self.assertEqual(logs_count, 3)

        logs = make_n_checkins(employee, 4, 2)
        now_date = nowdate()
        frappe.db.delete('Attendance', {'employee': employee})
        attendance = mark_attendance_and_link_log(logs, 'Present', now_date,
                                                  8.2)
        log_names = [log.name for log in logs]
        logs_count = frappe.db.count('Employee Checkin', {
            'name': ['in', log_names],
            'attendance': attendance.name
        })
        self.assertEqual(logs_count, 4)
        attendance_count = frappe.db.count(
            'Attendance', {
                'status': 'Present',
                'working_hours': 8.2,
                'employee': employee,
                'attendance_date': now_date
            })
        self.assertEqual(attendance_count, 1)
Exemplo n.º 2
0
    def test_mark_attendance_and_link_log(self):
        employee = make_employee(
            "*****@*****.**")
        logs = make_n_checkins(employee, 3)
        mark_attendance_and_link_log(logs, "Skip", nowdate())
        log_names = [log.name for log in logs]
        logs_count = frappe.db.count("Employee Checkin", {
            "name": ["in", log_names],
            "skip_auto_attendance": 1
        })
        self.assertEqual(logs_count, 3)

        logs = make_n_checkins(employee, 4, 2)
        now_date = nowdate()
        frappe.db.delete("Attendance", {"employee": employee})
        attendance = mark_attendance_and_link_log(logs, "Present", now_date,
                                                  8.2)
        log_names = [log.name for log in logs]
        logs_count = frappe.db.count("Employee Checkin", {
            "name": ["in", log_names],
            "attendance": attendance.name
        })
        self.assertEqual(logs_count, 4)
        attendance_count = frappe.db.count(
            "Attendance",
            {
                "status": "Present",
                "working_hours": 8.2,
                "employee": employee,
                "attendance_date": now_date
            },
        )
        self.assertEqual(attendance_count, 1)
Exemplo n.º 3
0
 def process_auto_attendance(self):
     if not cint(
             self.enable_auto_attendance
     ) or not self.process_attendance_after or not self.last_sync_of_checkin:
         return
     filters = {
         'skip_auto_attendance': '0',
         'attendance': ('is', 'not set'),
         'time': ('>=', self.process_attendance_after),
         'shift_actual_end': ('<', self.last_sync_of_checkin),
         'shift': self.name
     }
     logs = frappe.db.get_list('Employee Checkin',
                               fields="*",
                               filters=filters,
                               order_by="employee,time")
     for key, group in itertools.groupby(
             logs, key=lambda x: (x['employee'], x['shift_actual_start'])):
         single_shift_logs = list(group)
         attendance_status, working_hours, late_entry, early_exit = self.get_attendance(
             single_shift_logs)
         mark_attendance_and_link_log(single_shift_logs, attendance_status,
                                      key[1].date(), working_hours,
                                      late_entry, early_exit, self.name)
     for employee in self.get_assigned_employee(
             self.process_attendance_after, True):
         self.mark_absent_for_dates_with_no_attendance(employee)
Exemplo n.º 4
0
    def process_auto_attendance(self):
        if (not cint(self.enable_auto_attendance)
                or not self.process_attendance_after
                or not self.last_sync_of_checkin):
            return

        filters = {
            "skip_auto_attendance": 0,
            "attendance": ("is", "not set"),
            "time": (">=", self.process_attendance_after),
            "shift_actual_end": ("<", self.last_sync_of_checkin),
            "shift": self.name,
        }
        logs = frappe.db.get_list("Employee Checkin",
                                  fields="*",
                                  filters=filters,
                                  order_by="employee,time")

        for key, group in itertools.groupby(
                logs, key=lambda x: (x["employee"], x["shift_actual_start"])):
            single_shift_logs = list(group)
            (
                attendance_status,
                working_hours,
                late_entry,
                early_exit,
                in_time,
                out_time,
            ) = self.get_attendance(single_shift_logs)

            mark_attendance_and_link_log(
                single_shift_logs,
                attendance_status,
                key[1].date(),
                working_hours,
                late_entry,
                early_exit,
                in_time,
                out_time,
                self.name,
            )

        for employee in self.get_assigned_employee(
                self.process_attendance_after, True):
            self.mark_absent_for_dates_with_no_attendance(employee)
Exemplo n.º 5
0
    def test_unlink_attendance_on_cancellation(self):
        employee = make_employee(
            "*****@*****.**")
        logs = make_n_checkins(employee, 3)

        frappe.db.delete("Attendance", {"employee": employee})
        attendance = mark_attendance_and_link_log(logs, "Present", nowdate(),
                                                  8.2)
        attendance.cancel()

        linked_logs = frappe.db.get_all("Employee Checkin",
                                        {"attendance": attendance.name})
        self.assertEquals(len(linked_logs), 0)