Merge branch 'main' of https://gitea.ngodanguyen.tech/nngo/LT_Janitorial_Quality_Control
This commit is contained in:
@@ -730,6 +730,7 @@ def flag_issue(inspection_id):
|
||||
status = 'open',
|
||||
assigned_to = form.assigned_to.data or None,
|
||||
reported_at = now_eastern(),
|
||||
reported_by = current_user.id,
|
||||
)
|
||||
db.session.add(issue)
|
||||
|
||||
@@ -873,6 +874,24 @@ def flag_followup(inspection_id):
|
||||
inspection.follow_up_note = note
|
||||
db.session.commit()
|
||||
|
||||
# Notify the original inspector so they see it on the iPad
|
||||
inspector = db.session.get(User, inspection.inspector_id)
|
||||
if inspector and inspector.id != current_user.id:
|
||||
note_suffix = f' Note: {note}' if note else ''
|
||||
notify(
|
||||
recipient = inspector,
|
||||
title = f'Follow-Up Required: Inspection #{inspection_id}',
|
||||
body = (
|
||||
f'{current_user.username} has requested a follow-up re-inspection '
|
||||
f'of "{inspection.template.name}" at {inspection.facility.name}.{note_suffix}'
|
||||
),
|
||||
link = url_for('inspections.view', inspection_id=inspection_id),
|
||||
inspection_id = inspection_id,
|
||||
event_type = EVENT_INSPECTION_DONE,
|
||||
send_email = True,
|
||||
)
|
||||
db.session.commit()
|
||||
|
||||
current_app.logger.info(
|
||||
'INSPECTION FOLLOW-UP FLAGGED | id=%s | by=%s | note=%r',
|
||||
inspection_id, current_user.username, note,
|
||||
|
||||
+12
-7
@@ -70,12 +70,18 @@ class _SLAFilteredPage:
|
||||
@login_required
|
||||
def index():
|
||||
page = request.args.get('page', 1, type=int)
|
||||
q = Issue.query.order_by(Issue.reported_at.desc())
|
||||
# outerjoin Area once here so both the customer-scope filter and the
|
||||
# facility_filter block can reference Area.facility_id without a cartesian
|
||||
# product. Issues with no area_id get NULL for all Area columns (outer join).
|
||||
q = (
|
||||
Issue.query
|
||||
.outerjoin(Area, Issue.area_id == Area.id)
|
||||
.order_by(Issue.reported_at.desc())
|
||||
)
|
||||
|
||||
if current_user.role == 'inspector':
|
||||
q = q.filter(Issue.assigned_to == current_user.id)
|
||||
elif current_user.role == 'customer':
|
||||
from app.models.facility import Area
|
||||
customer_facility_ids = get_customer_scope(current_user)
|
||||
if not customer_facility_ids:
|
||||
q = q.filter(False)
|
||||
@@ -86,11 +92,10 @@ def index():
|
||||
Issue.facility_id.in_(customer_facility_ids),
|
||||
db.and_(
|
||||
Issue.area_id.isnot(None),
|
||||
Issue.area_id == Area.id,
|
||||
Area.facility_id.in_(customer_facility_ids)
|
||||
Area.facility_id.in_(customer_facility_ids),
|
||||
)
|
||||
)
|
||||
).outerjoin(Area, Issue.area_id == Area.id)
|
||||
)
|
||||
|
||||
severity_filter = request.args.get('severity', '')
|
||||
status_filter = request.args.get('status', '')
|
||||
@@ -106,8 +111,7 @@ def index():
|
||||
q = q.filter(
|
||||
db.or_(
|
||||
Issue.facility_id == fid,
|
||||
db.and_(Issue.area_id.isnot(None),
|
||||
Area.facility_id == fid)
|
||||
Area.facility_id == fid,
|
||||
)
|
||||
)
|
||||
# SLA filter — SLA status is computed in Python (not a DB column).
|
||||
@@ -447,6 +451,7 @@ def create():
|
||||
status = 'open',
|
||||
assigned_to = form.assigned_to.data or None,
|
||||
reported_at = now_eastern(),
|
||||
reported_by = current_user.id,
|
||||
)
|
||||
db.session.add(issue)
|
||||
db.session.commit()
|
||||
|
||||
Reference in New Issue
Block a user