Journaling for all flights
This commit is contained in:
@@ -98,11 +98,22 @@ class CRUDPPR:
|
||||
return db_obj
|
||||
|
||||
def update(self, db: Session, db_obj: PPRRecord, obj_in: PPRUpdate, user: str = "system", user_ip: str = "127.0.0.1") -> PPRRecord:
|
||||
from datetime import datetime as dt
|
||||
|
||||
update_data = obj_in.dict(exclude_unset=True)
|
||||
changes = []
|
||||
|
||||
for field, value in update_data.items():
|
||||
old_value = getattr(db_obj, field)
|
||||
|
||||
# Normalize datetime values for comparison (ignore timezone differences)
|
||||
if isinstance(old_value, dt) and isinstance(value, dt):
|
||||
# Compare only the date and time, ignoring timezone
|
||||
old_normalized = old_value.replace(tzinfo=None) if old_value.tzinfo else old_value
|
||||
new_normalized = value.replace(tzinfo=None) if value.tzinfo else value
|
||||
if old_normalized == new_normalized:
|
||||
continue # Skip if datetimes are the same
|
||||
|
||||
if old_value != value:
|
||||
changes.append(f"{field} changed from '{old_value}' to '{value}'")
|
||||
setattr(db_obj, field, value)
|
||||
@@ -114,7 +125,7 @@ class CRUDPPR:
|
||||
|
||||
# Log changes in journal
|
||||
for change in changes:
|
||||
crud_journal.log_change(db, db_obj.id, change, user, user_ip)
|
||||
crud_journal.log_ppr_change(db, db_obj.id, change, user, user_ip)
|
||||
|
||||
return db_obj
|
||||
|
||||
@@ -146,7 +157,7 @@ class CRUDPPR:
|
||||
db.refresh(db_obj)
|
||||
|
||||
# Log status change in journal
|
||||
crud_journal.log_change(
|
||||
crud_journal.log_ppr_change(
|
||||
db,
|
||||
db_obj.id,
|
||||
f"Status changed from {old_status.value} to {status.value}",
|
||||
|
||||
Reference in New Issue
Block a user