Build [v1.5.0] - Box Management & Label Printing
This commit is contained in:
@@ -3,6 +3,7 @@ from typing import List
|
||||
from sqlalchemy.orm import Session
|
||||
from .. import models, schemas, auth
|
||||
from ..database import get_db
|
||||
import json
|
||||
|
||||
router = APIRouter(
|
||||
prefix="/operations",
|
||||
@@ -27,10 +28,21 @@ def check_in_item(
|
||||
item.quantity += op.quantity
|
||||
|
||||
# Create Mandatory Audit Log — [M-02] user_id from token
|
||||
item_snapshot = {
|
||||
"barcode": item.barcode,
|
||||
"name": item.name,
|
||||
"category": item.category,
|
||||
"part_number": item.part_number
|
||||
}
|
||||
|
||||
audit = models.AuditLog(
|
||||
user_id=current_user.sub,
|
||||
action="CHECK_IN",
|
||||
target_item_id=item.id,
|
||||
target_item_name=item.name,
|
||||
target_item_pn=item.part_number,
|
||||
target_item_barcode=item.barcode,
|
||||
target_snapshot=json.dumps(item_snapshot),
|
||||
quantity_change=op.quantity
|
||||
)
|
||||
|
||||
@@ -60,10 +72,21 @@ def check_out_item(
|
||||
item.quantity -= op.quantity
|
||||
|
||||
# Create Mandatory Audit Log
|
||||
item_snapshot = {
|
||||
"barcode": item.barcode,
|
||||
"name": item.name,
|
||||
"category": item.category,
|
||||
"part_number": item.part_number
|
||||
}
|
||||
|
||||
audit = models.AuditLog(
|
||||
user_id=current_user.sub,
|
||||
action="CHECK_OUT",
|
||||
target_item_id=item.id,
|
||||
target_item_name=item.name,
|
||||
target_item_pn=item.part_number,
|
||||
target_item_barcode=item.barcode,
|
||||
target_snapshot=json.dumps(item_snapshot),
|
||||
quantity_change=-op.quantity
|
||||
)
|
||||
|
||||
@@ -93,10 +116,21 @@ def trash_item(
|
||||
item.quantity -= op.quantity
|
||||
|
||||
# Create Mandatory Audit Log with TRASH action and reason in details
|
||||
item_snapshot = {
|
||||
"barcode": item.barcode,
|
||||
"name": item.name,
|
||||
"category": item.category,
|
||||
"part_number": item.part_number
|
||||
}
|
||||
|
||||
audit = models.AuditLog(
|
||||
user_id=current_user.sub,
|
||||
action="TRASH",
|
||||
target_item_id=item.id,
|
||||
target_item_name=item.name,
|
||||
target_item_pn=item.part_number,
|
||||
target_item_barcode=item.barcode,
|
||||
target_snapshot=json.dumps(item_snapshot),
|
||||
quantity_change=-op.quantity,
|
||||
details=op.reason
|
||||
)
|
||||
@@ -130,10 +164,21 @@ def bulk_check_out(
|
||||
item.quantity -= op.quantity
|
||||
|
||||
# Log individual audit for this item
|
||||
item_snapshot = {
|
||||
"barcode": item.barcode,
|
||||
"name": item.name,
|
||||
"category": item.category,
|
||||
"part_number": item.part_number
|
||||
}
|
||||
|
||||
audit = models.AuditLog(
|
||||
user_id=current_user.sub,
|
||||
action="BULK_CHECK_OUT",
|
||||
target_item_id=item.id,
|
||||
target_item_name=item.name,
|
||||
target_item_pn=item.part_number,
|
||||
target_item_barcode=item.barcode,
|
||||
target_snapshot=json.dumps(item_snapshot),
|
||||
quantity_change=-op.quantity
|
||||
)
|
||||
db.add(audit)
|
||||
@@ -182,10 +227,21 @@ def bulk_sync(
|
||||
continue
|
||||
|
||||
# Log audit with original offline timestamp and UUID
|
||||
item_snapshot = {
|
||||
"barcode": item.barcode,
|
||||
"name": item.name,
|
||||
"category": item.category,
|
||||
"part_number": item.part_number
|
||||
}
|
||||
|
||||
audit = models.AuditLog(
|
||||
user_id=current_user.sub,
|
||||
action=op.type,
|
||||
target_item_id=item.id,
|
||||
target_item_name=item.name,
|
||||
target_item_pn=item.part_number,
|
||||
target_item_barcode=item.barcode,
|
||||
target_snapshot=json.dumps(item_snapshot),
|
||||
quantity_change=change,
|
||||
timestamp=op.timestamp,
|
||||
uuid=op.uuid,
|
||||
@@ -215,6 +271,10 @@ def get_logs(
|
||||
models.User.username,
|
||||
models.AuditLog.action,
|
||||
models.AuditLog.target_item_id,
|
||||
models.AuditLog.target_item_name,
|
||||
models.AuditLog.target_item_pn,
|
||||
models.AuditLog.target_item_barcode,
|
||||
models.AuditLog.target_snapshot,
|
||||
models.AuditLog.quantity_change,
|
||||
models.AuditLog.details
|
||||
).join(models.User, models.AuditLog.user_id == models.User.id).order_by(models.AuditLog.timestamp.desc()).limit(limit).all()
|
||||
@@ -228,6 +288,10 @@ def get_logs(
|
||||
"username": l.username,
|
||||
"action": l.action,
|
||||
"target_item_id": l.target_item_id,
|
||||
"target_item_name": l.target_item_name,
|
||||
"target_item_pn": l.target_item_pn,
|
||||
"target_item_barcode": l.target_item_barcode,
|
||||
"target_snapshot": l.target_snapshot,
|
||||
"quantity_change": l.quantity_change,
|
||||
"details": l.details
|
||||
} for l in logs_with_users
|
||||
|
||||
Reference in New Issue
Block a user