Fix dynamic tax year fallback in models and upload endpoints
This commit is contained in:
@@ -63,7 +63,7 @@ class PersonalDocument(Base):
|
||||
deleted_at = Column(DateTime(timezone=True), nullable=True, default=None)
|
||||
review_status = Column(String(20), default="draft", nullable=False)
|
||||
review_note = Column(String(500), nullable=True)
|
||||
tax_year = Column(Integer, default=2025, nullable=False)
|
||||
tax_year = Column(Integer, default=lambda: __import__("datetime").datetime.now().year, nullable=False)
|
||||
extracted_data = Column(JSON, nullable=True)
|
||||
file_hash = Column(String(64), nullable=True, index=True) # SHA-256 for dedup
|
||||
|
||||
@@ -91,7 +91,7 @@ class BusinessDocument(Base):
|
||||
deleted_at = Column(DateTime(timezone=True), nullable=True, default=None)
|
||||
review_status = Column(String(20), default="draft", nullable=False)
|
||||
review_note = Column(String(500), nullable=True)
|
||||
tax_year = Column(Integer, default=2025, nullable=False)
|
||||
tax_year = Column(Integer, default=lambda: __import__("datetime").datetime.now().year, nullable=False)
|
||||
extracted_data = Column(JSON, nullable=True)
|
||||
file_hash = Column(String(64), nullable=True, index=True) # SHA-256 for dedup
|
||||
|
||||
|
||||
@@ -462,10 +462,13 @@ async def upload_personal_document(
|
||||
background: BackgroundTasks,
|
||||
file: UploadFile = File(...),
|
||||
doc_type: str = Form(...),
|
||||
tax_year: int = Form(2025),
|
||||
tax_year: int = Form(None),
|
||||
db: Session = Depends(get_db),
|
||||
current_user=Depends(get_current_user),
|
||||
):
|
||||
if tax_year is None:
|
||||
tax_year = datetime.now().year
|
||||
|
||||
if not current_user.engagement_acknowledged_at:
|
||||
raise HTTPException(status_code=403, detail="You must acknowledge the engagement letter before uploading.")
|
||||
|
||||
@@ -632,10 +635,13 @@ async def upload_business_document(
|
||||
background: BackgroundTasks,
|
||||
file: UploadFile = File(...),
|
||||
doc_type: str = Form(...),
|
||||
tax_year: int = Form(2025),
|
||||
tax_year: int = Form(None),
|
||||
db: Session = Depends(get_db),
|
||||
current_user=Depends(get_current_user),
|
||||
):
|
||||
if tax_year is None:
|
||||
tax_year = datetime.now().year
|
||||
|
||||
if not current_user.engagement_acknowledged_at:
|
||||
raise HTTPException(status_code=403, detail="You must acknowledge the engagement letter before uploading.")
|
||||
|
||||
@@ -1570,3 +1576,4 @@ def remove_bookmark(
|
||||
db.commit()
|
||||
|
||||
return {"status": "ok", "bookmarked": False}
|
||||
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
import sys
|
||||
sys.path.append('.')
|
||||
from app.db import SessionLocal
|
||||
from app.models import PersonalDocument
|
||||
|
||||
db = SessionLocal()
|
||||
docs = db.query(PersonalDocument).filter(PersonalDocument.tax_year == 2026, PersonalDocument.review_status == 'pending').all()
|
||||
print("2026 pending docs:")
|
||||
for d in docs:
|
||||
print(f"ID {d.id} deleted_at: {d.deleted_at}")
|
||||
@@ -0,0 +1,23 @@
|
||||
import sys
|
||||
import json
|
||||
sys.path.append('.')
|
||||
from app.db import SessionLocal
|
||||
from app.models import RequiredDocumentTemplate, PersonalDocument, BusinessDocument
|
||||
|
||||
db = SessionLocal()
|
||||
templates = db.query(RequiredDocumentTemplate).all()
|
||||
pdocs = db.query(PersonalDocument).all()
|
||||
bdocs = db.query(BusinessDocument).all()
|
||||
|
||||
print("--- TEMPLATES ---")
|
||||
for t in templates:
|
||||
print(f"[{t.category.upper()}] TY {t.tax_year} | {t.name}")
|
||||
|
||||
print("\n--- PERSONAL DOCS ---")
|
||||
for d in pdocs:
|
||||
print(f"ID {d.id} | User {d.user_id} | TY {d.tax_year} | {d.doc_type} | {d.review_status}")
|
||||
|
||||
print("\n--- BUSINESS DOCS ---")
|
||||
for d in bdocs:
|
||||
print(f"ID {d.id} | User {d.user_id} | TY {d.tax_year} | {d.business_type} | {d.review_status}")
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
import sys
|
||||
sys.path.append('.')
|
||||
from app.db import SessionLocal
|
||||
from app.models import PersonalDocument, BusinessDocument
|
||||
|
||||
db = SessionLocal()
|
||||
|
||||
# Global count (like admin-status)
|
||||
global_p = db.query(PersonalDocument).filter(
|
||||
PersonalDocument.review_status == "pending",
|
||||
PersonalDocument.deleted_at.is_(None),
|
||||
PersonalDocument.tax_year == 2026
|
||||
).count()
|
||||
|
||||
# User-level count (like security.py)
|
||||
from sqlalchemy import func as sqlfunc
|
||||
users_p_q = db.query(PersonalDocument.user_id, sqlfunc.count(PersonalDocument.id)).filter(
|
||||
PersonalDocument.review_status == "pending",
|
||||
PersonalDocument.deleted_at.is_(None),
|
||||
PersonalDocument.tax_year == 2026
|
||||
).group_by(PersonalDocument.user_id).all()
|
||||
|
||||
sum_user_p = sum(count for _, count in users_p_q)
|
||||
|
||||
print(f"Global: {global_p}, Sum of users: {sum_user_p}")
|
||||
@@ -0,0 +1,16 @@
|
||||
import sys
|
||||
sys.path.append('.')
|
||||
from app.db import SessionLocal
|
||||
from app.models import PersonalDocument
|
||||
|
||||
db = SessionLocal()
|
||||
pq_none = db.query(PersonalDocument).filter(PersonalDocument.review_status == "pending", PersonalDocument.deleted_at == None).filter(PersonalDocument.tax_year == 2025)
|
||||
pq_is_none = db.query(PersonalDocument).filter(PersonalDocument.review_status == "pending", PersonalDocument.deleted_at.is_(None)).filter(PersonalDocument.tax_year == 2025)
|
||||
|
||||
print("With == None:", pq_none.count())
|
||||
print("With is_(None):", pq_is_none.count())
|
||||
|
||||
docs = db.query(PersonalDocument).filter(PersonalDocument.tax_year == 2025).all()
|
||||
print("All 2025 docs count:", len(docs))
|
||||
for d in docs:
|
||||
print(f"ID {d.id} deleted_at: {d.deleted_at}")
|
||||
@@ -0,0 +1,14 @@
|
||||
import sys
|
||||
sys.path.append('.')
|
||||
from app.db import SessionLocal
|
||||
from app.models import PersonalDocument, BusinessDocument
|
||||
|
||||
db = SessionLocal()
|
||||
pq = db.query(PersonalDocument).filter(PersonalDocument.review_status == "pending", PersonalDocument.deleted_at == None).filter(PersonalDocument.tax_year == 2025)
|
||||
print("Pending personal docs for 2025:", pq.count())
|
||||
|
||||
bq = db.query(BusinessDocument).filter(BusinessDocument.review_status == "pending", BusinessDocument.deleted_at == None).filter(BusinessDocument.tax_year == 2025)
|
||||
print("Pending business docs for 2025:", bq.count())
|
||||
|
||||
p26 = db.query(PersonalDocument).filter(PersonalDocument.review_status == "pending", PersonalDocument.deleted_at == None).filter(PersonalDocument.tax_year == 2026)
|
||||
print("Pending personal docs for 2026:", p26.count())
|
||||
@@ -0,0 +1,30 @@
|
||||
import requests
|
||||
|
||||
# 1. Login as User 2
|
||||
res = requests.post("http://localhost:8000/api/auth/login", data={"username": "user@example.com", "password": "password"})
|
||||
user_token = res.json()["access_token"]
|
||||
print("User token:", user_token[:10])
|
||||
|
||||
# 2. Upload a personal document for TY 2026
|
||||
files = {'file': ('test.pdf', b'fake pdf content', 'application/pdf')}
|
||||
data = {'doc_type': 'test_doc', 'tax_year': 2026}
|
||||
res = requests.post(
|
||||
"http://localhost:8000/api/upload/personal-documents",
|
||||
headers={"Authorization": f"Bearer {user_token}"},
|
||||
files=files,
|
||||
data=data
|
||||
)
|
||||
print("Upload status:", res.status_code)
|
||||
|
||||
# 3. Login as Admin
|
||||
res = requests.post("http://localhost:8000/api/auth/login", data={"username": "admin@example.com", "password": "password"})
|
||||
admin_token = res.json()["access_token"]
|
||||
|
||||
# 4. Check admin status for TY 2026
|
||||
res = requests.get("http://localhost:8000/api/chatbot/admin-status?tax_year=2026", headers={"Authorization": f"Bearer {admin_token}"})
|
||||
print("Admin status 2026:", res.json().get("pending_personal"))
|
||||
|
||||
# 5. Check admin status for TY 2025
|
||||
res = requests.get("http://localhost:8000/api/chatbot/admin-status?tax_year=2025", headers={"Authorization": f"Bearer {admin_token}"})
|
||||
print("Admin status 2025:", res.json().get("pending_personal"))
|
||||
|
||||
Reference in New Issue
Block a user