示例#1
0
def can_add_appraisal_score(employee):
    # only his own line manager can chanage manager's rating
    user_role = get_user_role()
    if (user_role == ADMINISTRATOR or user_role == HR_MANAGER):
        return True
    if (get_employee_code() == get_report_to(employee)):
        if (user_role == LINE_MANAGER and type(employee) != "undefined"
                and employee != get_employee_code()):
            return True
    else:
        return False
示例#2
0
def calculate_penalty_widgets():
    result = {}
    userid = get_employee_code()
    date = datetime.datetime.today().strftime('%Y-%m-%d')
    now = datetime.datetime.now()
    if (now.day > MONTHLY_ATTENDANCE_DATE):
        date = datetime.datetime.today() + relativedelta(months=1)
        date = date.strftime('%Y-%m-%d')
    date_range = getPenaltyDateRange(date)
    start = date_range['month_start_date']
    end = date_range['month_end_date']
    # if attendance data exists it returns array
    attendancepolicies = AttendancePolicies(False)
    if not userid:
        userid = "Administrator"
    records = attendancepolicies.get_employee_policies(start, end, [userid])
    # get policy applied to user and 0 multiplier rule
    if not records:
        records = attendancepolicies.get_user_policies(userid)
        if not records:
            records = [{}]
            records[0]['policy_multiplier'] = None
            records[0]['policy_unit_value_to'] = None
        records[0]['total_late_instance'] = 0
        records[0]['total_late_arrival'] = 0
    result['attendance_penalties'] = records
    return result
示例#3
0
def get_action_input(id, shift_start_time, shift_end_time, employee,
                     attendance_status, attendance_date):

    att_req_btn = """<a  href="#Form/Attendance%20Request/New%20Attendance%20Request%201?employee={0}&attendance_date={1}" target="_blank" title="Attendance Request"><i class="fa fa-calendar-check-o"></i></a>""".format(
        employee, attendance_date)
    if employee is not None:
        if employee == get_employee_code():
            if (EmployeeRoster.is_cutoff_passed(attendance_date) == False):
                return att_req_btn
            return '-'
    editBtn = '-'
    AuthRole = frappe.get_roles(frappe.session.user)
    today_date = str(datetime.strftime(datetime.today(), '%Y-%m-%d'))

    allowed_roles = [
        ATTENDANCE_MANAGER, HR_MANAGER, ADMINISTRATOR, LINE_MANAGER, HR_USER
    ]

    if ATTENDANCE_MANAGER in AuthRole:
        editBtn = """<a  href="#Form/Attendance/{0}" target="_blank"><i class="fa fa-edit"></i></a>
                    """.format(id)
    elif len(list(set(allowed_roles)
                  & set(AuthRole))) > 0 and EmployeeRoster.is_cutoff_passed(
                      attendance_date) == False:
        editBtn = """<a href="javascript:;" onclick="attendance_report_action(this, '{0}', '{1}', '{2}', '{3}')"><i class="fa fa-edit"></i></a>
                            """.format(id, shift_start_time, shift_end_time,
                                       attendance_status)

    if (EmployeeRoster.is_cutoff_passed(attendance_date) == False):
        if editBtn == '-':
            editBtn = ''
        editBtn = """{0} {1}""".format(editBtn, att_req_btn)
    return editBtn
示例#4
0
def update_actions(id, shift_start_time, shift_end_time, employee,
                   attendance_status, attendance_date):

    action_disabled = "<input type='checkbox' class='individual' name='emp_action_check' " + 'disabled' + "  value=" + id + "  id=" + employee + ">"

    if employee is not None:
        if employee == get_employee_code():
            return action_disabled
    editBtn = action_disabled
    AuthRole = frappe.get_roles(frappe.session.user)
    today_date = str(datetime.strftime(datetime.today(), '%Y-%m-%d'))

    allowed_roles = [
        ATTENDANCE_MANAGER, HR_MANAGER, ADMINISTRATOR, LINE_MANAGER, HR_USER
    ]

    if ATTENDANCE_MANAGER in AuthRole:
        editBtn = "<input type='checkbox' class='individual' name='emp_action_check[]'  value=" + id + "  id=" + employee + ">"
    elif len(list(set(allowed_roles)
                  & set(AuthRole))) > 0 and EmployeeRoster.is_cutoff_passed(
                      attendance_date) == False:
        editBtn = "<input type='checkbox' class='individual' name='emp_action_check[]' value=" + id + "  id=" + employee + ">"
    else:
        editBtn = action_disabled

    return editBtn
 def profile_score(self):
     if len(self.widget_data) == 0:
         if _globals.ADMINISTRATOR in frappe.get_roles():
             self.widget_data.append({
                 'profile_score': 0,
                 'employee_name': '#List/Employee/List'
             })
         else:
             self.widget_data.append({
                 'profile_score':
                 0,
                 'employee_name':
                 '#Form/Employee/{0}'.format(get_employee_code())
             })
     else:
         self.widget_data[0]['employee_name'] = '#Form/Employee/{0}'.format(
             get_employee_code())
示例#6
0
def before_save_attendance(doc, event):

    if doc.attendance_status == ROSTER_STATUS_HOLIDAY and doc.flags.ignore_permissions == False:
        frappe.throw(_("You cannot manually update roster status to holiday"))

    calculate_late_arrivals(doc)

    doc.shift_start_time = doc.shift_start_time if doc.shift_start_time != None else get_config_by_name("default_shift_start_time", "09:00:00")
    doc.shift_end_time = doc.shift_end_time if doc.shift_end_time != None else get_config_by_name("default_shift_end_time", "18:00:00")

    user_id = frappe.session.user
    auth_role = frappe.get_roles(user_id)


    emp_attendance = []
    if doc.amended_from is not None:
        emp_attendance = frappe.db.get_value("Attendance", {"name": doc.amended_from}, "*")

    if ADMINISTRATOR != user_id:
        # if(emp_attendance):
        #     emp_attendance.attendance_date = emp_attendance.attendance_date.strftime('%Y-%m-%d')
        #     # Only employee with advanced privilege can update privious date attendance for roster
        #     today_date = datetime.strftime(datetime.today(), '%Y-%m-%d')
        #     if emp_attendance.attendance_date < today_date and check_advance_privilege_by_name(get_config_by_name('CAN_UPDATE_PREVIOUS_DAY_ROSTER')) == False:
        #         frappe.throw(_("You cannot update previous date roster"))

        # Validate not to update attendance except AttendanceManager
        if ATTENDANCE_MANAGER not in auth_role and doc.flags.ignore_permissions == False:
            if emp_attendance:

            # validate for attendance_date
                if doc.attendance_date is not None:
                    if str(doc.attendance_date) != str(emp_attendance.attendance_date):
                        frappe.throw(_("You cannot update attendance date"))
            # validate for check_in
                if doc.check_in is not None:
                    if str(doc.check_in) != str(emp_attendance.check_in):
                        frappe.throw(_("You cannot update attendance check in time"))

            # validate for check_out
                if doc.check_out is not None:
                    if str(doc.check_out) != str(emp_attendance.check_out):
                        frappe.throw(_("You cannot update attendance check out time"))
            # validate for employee_id
                if doc.employee is not None:
                    if doc.employee != emp_attendance.employee:
                        frappe.throw(_("You cannot update employee code"))


        # Restrict self update for Attendance
        if doc.employee is not None:
            if doc.employee == get_employee_code():
                frappe.throw(_("You cannot update your attendance"))
def get_leave_status_list(islocal,employee=None):

    # Check User with Special Privillige or not
    if(check_advance_privilege_by_name(get_config_by_name('ADVANCE_PRIV_AUTO_APPROVE_LEAVE'))):
        return [LEAVE_STATUS_OPEN, LEAVE_STATUS_APPROVED, LEAVE_STATUS_REJECTED, LEAVE_STATUS_CANCELLED]
    
    if(any(x in frappe.get_roles() for x in [HR_MANAGER, HR_USER, LINE_MANAGER,ADMINISTRATOR]) and islocal != "new" ):
        if (employee is not None and employee == get_employee_code()):
            return [LEAVE_STATUS_OPEN, LEAVE_STATUS_CANCELLED]

        return [LEAVE_STATUS_OPEN, LEAVE_STATUS_APPROVED, LEAVE_STATUS_REJECTED, LEAVE_STATUS_CANCELLED]
    
    if(islocal=="new"):
        return [LEAVE_STATUS_OPEN]
    else:
        return [LEAVE_STATUS_OPEN, LEAVE_STATUS_CANCELLED]
    def reward_inner_box_bookmark(self):

        self.template = "column_inner_box_bookmark"

        working_hours = get_employee_shift_working_hours(
            get_employee_code())  # Calculate working hours
        reward_conversion = convert_reward(
            self.widget_data[0]['reward'],
            int(working_hours))  # Convert Reward

        for key in reward_conversion:
            self.widget_data_rows.append({
                "title": key,
                "value": reward_conversion[key]
            })

        self.widget_data = [{"total": datetime.datetime.now().year}]
示例#9
0
def check_is_edit(employee=""):
    login_empcode = get_employee_code()
    if not (any(x in frappe.get_roles()
                for x in [HR_MANAGER, HR_USER, ADMINISTRATOR])):
        team_ids = get_auth_team_ids(True)
        try:
            team_ids.remove(login_empcode)
        except ValueError:
            pass
        if employee in team_ids:
            response = {"disabled": True}
        else:
            response = {"disabled": False}
    else:
        response = {"disabled": False}
    if employee == login_empcode:
        response = {"disabled": True, "shift_type": True}

    return response
def validate_leave_approver(doctype):

    reports_to = None
    if(check_advance_privilege_by_name(get_config_by_name('ADVANCE_PRIV_AUTO_APPROVE_LEAVE')) == False):
        # reports_to = ''
        reports_to_code = frappe.get_value("Employee", doctype.employee, "reports_to")
        if(reports_to_code):
            reports_to = frappe.get_value("Employee", reports_to_code, "user_id")
        dept_leave_approver = frappe.db.get_value('Department Approver', {'parent': doctype.department,'parentfield': 'leave_approvers','approver':doctype.leave_approver}, 'approver')
        hr_role = None
        if HR_MANAGER in frappe.get_roles(frappe.session.user) or HR_USER in frappe.get_roles(frappe.session.user):
            hr_role = True
        ''' Also validating HR User and HR Manager can approve leaves'''
        if(doctype.status in [LEAVE_STATUS_APPROVED, LEAVE_STATUS_REJECTED] and doctype.employee == get_employee_code()):
            frappe.throw(_("You cannot approve/reject your own leaves"))
        elif (doctype.status in [LEAVE_STATUS_APPROVED, LEAVE_STATUS_REJECTED] and doctype.employee not in get_auth_team_ids(True) and hr_role is None):
            frappe.throw(_("You cannot approve/reject this leaves"))
示例#11
0
def get_data_and_bookmark(widget_template, widget_data):
    # REPLACE BOOKMARKS WHICH IS USED IN HTML TEMPLATE
    bookmark = widget_type = ''
    if (widget_template.find('@LeaveInnerBoxBookmark@') != -1):
        widget_data_rows = widget_data['data']
        bookmark = "LeaveInnerBoxBookmark"
    elif (widget_template.find('@RewardInnerBoxBookmark@') != -1):
        working_hours = get_employee_shift_working_hours(
            get_employee_code())  # Calculate working hours
        reward = widget_data['data'][0]['reward']
        reward_conversion = convert_reward(
            reward, int(working_hours))  # Convert Reward
        widgets = {'data': {}}
        year = datetime.datetime.now().year  # Current Year
        widgets['data'][0] = reward_conversion
        widget_data['data'][0] = reward_conversion
        widget_data['data'][0]['year'] = year
        widget_data_rows = sorted(widgets['data'][0].keys())
        bookmark = "RewardInnerBoxBookmark"
    elif (widget_template.find('@PenaltyInnerBoxBookmark@') != -1):
        result = render_penalty_widget_data()
        widget_data_rows = {}
        widget_data_rows['minutes'] = result['minutes']
        widget_data_rows['instances'] = result['instances']
        widget_data['data'][0] = result
        bookmark = "PenaltyInnerBoxBookmark"
    elif (widget_template.find('@MyHolidayCalendarBookmark@') != -1):
        widget_data_rows = widget_data['data']
        bookmark = "MyHolidayCalendarBookmark"
        widget_type = 'rightSide'
    elif (widget_template.find('@BirthdayBookmark@') != -1):
        widget_data_rows = widget_data['data']
        bookmark = "BirthdayBookmark"
        widget_type = 'rightSide'
    elif (widget_template.find('@AnnouncementsBookmark@') != -1):
        widget_data_rows = widget_data['data']
        bookmark = "AnnouncementsBookmark"
        widget_type = 'rightSide'
    elif (widget_template.find('@DailyShiftBookmark@') != -1):
        widget_data_rows = widget_data['data']
        bookmark = "DailyShiftBookmark"
    elif (widget_template.find('@ColumnInnerBoxBookmark@') != -1):
        widget_data_rows = widget_data['data'][0].keys()
        bookmark = "ColumnInnerBoxBookmark"
    elif (widget_template.find('@EmpMonthlyTurnoverData@') != -1):
        widget_data_rows = widget_data['data']
        bookmark = "EmpMonthlyTurnoverData"
    elif (widget_template.find('@PieChartBookmark@') != -1):
        widget_data_rows = widget_data['data']
        bookmark = "PieChartBookmark"
    elif (widget_template.find('@TaskListBookmark@') != -1):
        widget_data_rows = widget_data['data']
        bookmark = "TaskListBookmark"
    elif (widget_template.find('@TeamHolidayAndLeave@') != -1):
        widget_data_rows = widget_data['data']
        bookmark = "TeamHolidayAndLeave"
    elif (widget_template.find('@AnnualLeaveBookmark@') != -1):
        widget_data_rows = widget_data['data']
        bookmark = "AnnualLeaveBookmark"
    else:
        if (widget_template.find('@profile_score@') != -1):
            if len(widget_data['data']) == 0:
                if ADMINISTRATOR in frappe.get_roles():
                    widget_data['data'].append({
                        'profile_score':
                        0,
                        'employee_name':
                        '#List/Employee/List'
                    })
                else:
                    widget_data['data'].append({
                        'profile_score':
                        0,
                        'employee_name':
                        '#Form/Employee/{0}'.format(get_employee_code())
                    })
            else:
                widget_data['data'][0][
                    'employee_name'] = '#Form/Employee/{0}'.format(
                        get_employee_code())
        if len(widget_data['data']) == 0:
            widget_data['data'].append({'sum': 0})
        widget_data_rows = widget_data['data'][0].keys()

    return {
        'widget_data_rows': widget_data_rows,
        'bookmark': bookmark,
        'widget_type': widget_type,
        'widget_data': widget_data
    }
 def get_employee_code(self, *args):
     return get_employee_code()
示例#13
0
def isEmployeeAllowed(employee):
    if (type(employee) != "undefined" and employee == get_employee_code()):
        return False
    else:
        return True
示例#14
0
def my_reporting_manager(employee):
    if (get_employee_code() == get_report_to(employee)):
        return True
    return False