Skip to content

Commit

Permalink
Merge pull request #3706 from ONE-F-M/staging
Browse files Browse the repository at this point in the history
feat: Attendance ONEFM
  • Loading branch information
pjamsheer authored Oct 13, 2024
2 parents a43bc66 + 2fe40a1 commit 19a38ea
Show file tree
Hide file tree
Showing 64 changed files with 6,907 additions and 4,774 deletions.
36 changes: 36 additions & 0 deletions .github/workflows/attendance.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: Deploy CI/CD to Attendance

on:
push: # tells github to run this on any push to the repository
branches:
- attendance

# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
# This workflow contains a single job called "build"
build:
# The type of runner that the job will run on
runs-on: ubuntu-latest
timeout-minutes: 90

# Steps represent a sequence of tasks that will be executed as part of the job
steps:
- name: Deploy to Attendance
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.STAGING_HOST }}
username: ${{ secrets.USERNAME }}
key: ${{ secrets.STAGING_KEY }}
port: 22
script: |
cd /home/frappe/attendance-bench/apps/one_fm # we move into our app's folder
# git pull upstream attendance # we pull any changes from git
git pull
cd /home/frappe
pip3 install --upgrade attendance-bench
cd /home/frappe/attendance-bench
bench setup requirements one_fm
bench migrate # sync database
bench restart #${{secrets.PASSKEY}}
# we remove any unused dependencies
bench doctor
1 change: 0 additions & 1 deletion one_fm/api/doc_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
from frappe import _
from frappe.utils import cstr, cint, get_datetime, getdate, add_to_date
from frappe.core.doctype.version.version import get_diff
from one_fm.utils import get_current_shift
from one_fm.operations.doctype.operations_site.operations_site import create_notification_log
import datetime
from frappe.permissions import remove_user_permission
Expand Down
1 change: 0 additions & 1 deletion one_fm/api/mobile/Leave_application.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import base64, json
from one_fm.api.v1.utils import response, validate_date
from frappe.utils import cint, cstr, getdate
from one_fm.utils import get_current_shift
from one_fm.api.tasks import get_action_user
from one_fm.api.api import push_notification_rest_api_for_leave_application
from one_fm.processor import sendemail
Expand Down
15 changes: 9 additions & 6 deletions one_fm/api/mobile/face_recognition.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,17 @@

# setup channel for face recognition
face_recognition_service_url = frappe.local.conf.face_recognition_service_url
channels = [
grpc.secure_channel(i, grpc.ssl_channel_credentials()) for i in face_recognition_service_url
]
# channels = [
# grpc.secure_channel(i, grpc.ssl_channel_credentials()) for i in face_recognition_service_url
# ]

# setup stub for face recognition
stubs = [
facial_recognition_pb2_grpc.FaceRecognitionServiceStub(i) for i in channels
]
# stubs = [
# facial_recognition_pb2_grpc.FaceRecognitionServiceStub(i) for i in channels
# ]

stubs = list()



@frappe.whitelist()
Expand Down
127 changes: 68 additions & 59 deletions one_fm/api/tasks.py

Large diffs are not rendered by default.

31 changes: 18 additions & 13 deletions one_fm/api/v1/employee_checkin_issue.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,18 @@
from one_fm.api.notification import create_notification_log
from one_fm.api.v1.utils import response, validate_date, validate_time
from one_fm.operations.doctype.employee_checkin_issue.employee_checkin_issue import fetch_approver
from frappe.model.workflow import apply_workflow
from frappe.utils import getdate

@frappe.whitelist()
def create_employee_checkin_issue(employee_id: str = None, log_type: str = None, issue_type: str = None, date: str = None,
issue_details: str = None, latitude: str = None, longitude: str = None) -> dict:
def create_employee_checkin_issue(employee_id: str = None, log_type: str = None, issue_type: str = None,
issue_details: str = None, latitude: float = None, longitude: float = None) -> dict:
"""This method creates a employee checkin issue for a given employee.
Args:
employee (str): employee id
log_type (str): type of log(IN/OUT).
issue_type (str): type of issue requested.
date (str): yyyy-mm-dd
issue_details (str): reason to create a employee checkin issue
latitude (float, optional): Latitude od user.
longitude (float, optional): Longitude od user.
Expand All @@ -29,6 +30,7 @@ def create_employee_checkin_issue(employee_id: str = None, log_type: str = None,
}
"""
try:
date = getdate()
if not employee_id:
return response("Bad Request", 400, None, "employee_id required.")

Expand All @@ -38,8 +40,6 @@ def create_employee_checkin_issue(employee_id: str = None, log_type: str = None,
if not issue_type:
return response("Bad Request", 400, None, "issue_type required.")

if not date:
return response("Bad Request", 400, None, "date required.")

if issue_type == "Other":
if not issue_details:
Expand All @@ -65,22 +65,20 @@ def create_employee_checkin_issue(employee_id: str = None, log_type: str = None,
except:
return response("Bad Request", 400, None, "Latitude and longitude must be float.")

if not isinstance(date, str):
return response("Bad Request", 400, None, "date must be of type str.")

if not validate_date(date):
return response("Bad Request", 400, None, "date must be of type yyyy-mm-dd.")

employee = frappe.db.get_value("Employee", {"employee_id": employee_id})

if not employee:
return response("Resource Not Found", 404, None, "No employee found with {employee_id}"
.format(employee_id=employee_id))

shift_details = get_shift_details(employee)
shift_details = fetch_approver(employee)

if shift_details.found:
shift, shift_type, shift_assignment, shift_supervisor = shift_details.data
if shift_details:
shift_assignment = shift_details['assigned_shift']
shift_supervisor = shift_details['shift_supervisor']
shift = shift_details['shift']
shift_type = shift_details['shift_type']
else:
return response("Resource Not Found", 404, None, "shift not found in employee schedule for {employee}"
.format(employee=employee))
Expand All @@ -96,6 +94,10 @@ def create_employee_checkin_issue(employee_id: str = None, log_type: str = None,
if not shift_supervisor:
return response("Resource Not Found", 404, None, "shift supervisor not found for {employee}"
.format(employee=employee_id))

if frappe.db.exists("Attendance", {"shift_assignment": shift_assignment}):
return response("Attendance Exists", 400, None, f"Attendance already marked for {date}")


if not frappe.db.exists("Employee Checkin Issue", {"employee": employee, "date": date,
"assigned_shift": shift_assignment, "log_type": log_type, "issue_type": issue_type}):
Expand All @@ -112,7 +114,10 @@ def create_employee_checkin_issue(employee_id: str = None, log_type: str = None,
employee_checkin_issue_doc.shift_supervisor = shift_supervisor
employee_checkin_issue_doc.shift = shift
employee_checkin_issue_doc.shift_type = shift_type
employee_checkin_issue_doc.flags.ignore_permissions = 1
employee_checkin_issue_doc.save()
apply_workflow(employee_checkin_issue_doc, "Submit for Approval")

frappe.db.commit()
return response("Success", 201, employee_checkin_issue_doc.as_dict())

Expand Down
Loading

0 comments on commit 19a38ea

Please sign in to comment.