Exemplo n.º 1
0
    def _get_teacher_payment_set_travel_allowance(self, tpc_row):
        """
        set db.teachers_payment_classes travel allowance
        """
        from os_class_schedule import ClassSchedule
        from os_teacher import Teacher

        db = current.db

        if tpc_row and not tpc_row.Status == 'processed':
            cs = ClassSchedule(
                self.date,
                filter_id_teacher=tpc_row.auth_teacher_id,
                filter_id_school_location=self.cls.school_locations_id)

            class_start = datetime.datetime(self.date.year, self.date.month,
                                            self.date.day,
                                            self.cls.Starttime.hour,
                                            self.cls.Starttime.minute)

            # Add travel allowance if no class is found that ended 30 minutes before start of this class
            class_found = False
            rows = cs.get_day_rows()
            for row in rows:
                if not int(row.classes.id) == int(self.clsID):
                    checked_class_start = datetime.datetime(
                        self.date.year, self.date.month, self.date.day,
                        row.classes.Endtime.hour, row.classes.Endtime.minute)

                    checked_class_end = datetime.datetime(
                        self.date.year, self.date.month, self.date.day,
                        row.classes.Endtime.hour, row.classes.Endtime.minute)

                    consecutive = (
                        (checked_class_end + datetime.timedelta(minutes=30)) >=
                        class_start and checked_class_end <= class_start)

                    if consecutive:
                        class_found = True

            if not class_found:
                # Add travel allowance, there is no class which ends within 30 min in same location
                teacher = Teacher(tpc_row.auth_teacher_id)

                travel_allowance = teacher.get_payment_travel_allowance_location(
                    self.cls.school_locations_id)
                if travel_allowance:
                    tpc_row.TravelAllowance = travel_allowance.TravelAllowance
                    tpc_row.tax_rates_id_travel_allowance = travel_allowance.tax_rates_id
                    tpc_row.update_record()
Exemplo n.º 2
0
    def get_upcoming_classes_formatted(self, days=3):
        """
            Returns upcoming classes for teacher
        """
        from os_gui import OsGui
        from os_class_schedule import ClassSchedule

        T = current.T
        db = current.db
        auth = current.auth
        os_gui = OsGui()
        DATE_FORMAT = current.DATE_FORMAT
        TODAY_LOCAL = current.globalenv['TODAY_LOCAL']

        attendance_permission = (auth.has_membership(group_id='Admins')
                                 or auth.has_permission(
                                     'update', 'classes_attendance'))

        date = TODAY_LOCAL
        delta = datetime.timedelta(days=1)

        header = THEAD(
            TR(
                TH(T('Class date')),
                TH(T('Time')),
                TH(T('Location')),
                TH(T('Class type')),
                TH(T('Teacher')),
                TH(T('Teacher2')),
                TH(),
            ))

        table = TABLE(header, _class='table table-hover')

        for day in range(0, days):
            cs = ClassSchedule(date, filter_id_teacher=self.id)

            rows = cs.get_day_rows()
            for i, row in enumerate(rows):
                if row.classes_otc.Status == 'cancelled' or row.school_holidays.id:
                    continue

                repr_row = list(rows[i:i + 1].render())[0]

                result = cs._get_day_row_teacher_roles(row, repr_row)

                teacher = result['teacher_role']
                teacher2 = result['teacher_role2']

                attendance = ''
                if attendance_permission:
                    attendance = os_gui.get_button(
                        'noicon',
                        URL('classes',
                            'attendance',
                            vars={
                                'clsID': row.classes.id,
                                'date': date.strftime(DATE_FORMAT)
                            }),
                        title=T('Attendance'),
                        _class=T('pull-right'))

                tr = TR(
                    TD(date.strftime(DATE_FORMAT),
                       _class='bold green' if day == 0 else ''),
                    TD(repr_row.classes.Starttime, ' - ',
                       repr_row.classes.Endtime),
                    TD(repr_row.classes.school_locations_id),
                    TD(repr_row.classes.school_classtypes_id), TD(teacher),
                    TD(teacher2), TD(attendance))

                table.append(tr)

            date += delta

        upcoming_classes = DIV(
            DIV(H3(T('My upcoming classes'), _class="box-title"),
                DIV(A(I(_class='fa fa-minus'),
                      _href='#',
                      _class='btn btn-box-tool',
                      _title=T("Collapse"),
                      **{'_data-widget': 'collapse'}),
                    _class='box-tools pull-right'),
                _class='box-header with-border'),
            DIV(table, _class='box-body'),
            self._get_teacher_upcoming_classes_formatted_footer(),
            _class='box box-primary')

        return upcoming_classes