feat: complete platform overhaul, bugfixes, and verified production release
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
Document type classifier for the "other_*" catch-all upload bucket.
|
||||
|
||||
When a user uploads via the "Additional Documents" slot, doc_type is set to
|
||||
`other_<timestamp>_<index>` — a meaningless slug. This module detects the
|
||||
`other_<timestamp>_<index>` ? a meaningless slug. This module detects the
|
||||
actual document type from OCR text + filename so the extraction prompt
|
||||
becomes type-specific rather than generic.
|
||||
|
||||
@@ -24,6 +24,12 @@ class DocCategory(str, Enum):
|
||||
AADHAAR = "Aadhaar Card"
|
||||
W2 = "W-2 Wage Statement"
|
||||
FORM_1099 = "1099 Income Form"
|
||||
FORM_1040 = "Form 1040 (U.S. Individual Income Tax Return)"
|
||||
FORM_1120 = "Form 1120/1120-S (U.S. Corporation Tax Return)"
|
||||
FORM_1065 = "Form 1065 (U.S. Partnership Tax Return)"
|
||||
SCHEDULE_K1 = "Schedule K-1"
|
||||
FORM_W9 = "Form W-9 (TIN Request)"
|
||||
EIN_LETTER = "IRS EIN Assignment Letter"
|
||||
ENGAGEMENT_LETTER = "Engagement Letter"
|
||||
TAX_ORGANIZER = "Tax Organizer"
|
||||
INVOICE = "Invoice / Bill"
|
||||
@@ -33,7 +39,7 @@ class DocCategory(str, Enum):
|
||||
GENERIC = "Other Document"
|
||||
|
||||
|
||||
# Priority-ordered keyword patterns — first match wins
|
||||
# Priority-ordered keyword patterns ? first match wins
|
||||
_PATTERNS: list[tuple[re.Pattern, DocCategory]] = [
|
||||
# Government IDs
|
||||
(re.compile(r'\bPERMANENT\s+ACCOUNT\s+NUMBER\b|\bINCOME\s+TAX\s+DEPT\b', re.I), DocCategory.PAN_CARD),
|
||||
@@ -43,6 +49,12 @@ _PATTERNS: list[tuple[re.Pattern, DocCategory]] = [
|
||||
# US Tax forms
|
||||
(re.compile(r'\bW-?2\b.*\bWAGES\b|\bWAGES.*TIPS.*OTHER\b|\bFEDERAL\s+INCOME\s+TAX\s+WITHHELD\b', re.I), DocCategory.W2),
|
||||
(re.compile(r'\b1099-?[A-Z]{0,4}\b|\bNONEMPLOYEE\s+COMPENSATION\b|\bMISCELLANEOUS\s+INCOME\b', re.I), DocCategory.FORM_1099),
|
||||
(re.compile(r'\bFORM\s+1040\b|\b1040-?SR\b|\bU\.S\.\s+INDIVIDUAL\s+INCOME\s+TAX\s+RETURN\b', re.I), DocCategory.FORM_1040),
|
||||
(re.compile(r'\bFORM\s+1120\b|\b1120-?S\b|\bU\.S\.\s+(CORPORATION|INCOME\s+TAX\s+RETURN\s+FOR\s+AN\s+S\s+CORPORATION)\b', re.I), DocCategory.FORM_1120),
|
||||
(re.compile(r'\bSCHEDULE\s+K-?1\b|\bPARTNER[\'?]S\s+SHARE\s+OF\s+INCOME\b', re.I), DocCategory.SCHEDULE_K1),
|
||||
(re.compile(r'\bFORM\s+1065\b|\bU\.S\.\s+RETURN\s+OF\s+PARTNERSHIP\s+INCOME\b', re.I), DocCategory.FORM_1065),
|
||||
(re.compile(r'\bFORM\s+W-?9\b|\bREQUEST\s+FOR\s+TAXPAYER\s+IDENTIFICATION\b', re.I), DocCategory.FORM_W9),
|
||||
(re.compile(r'\bCP\s*575\b|\bASSIGNED\s+EMPLOYER\s+IDENTIFICATION\s+NUMBER\b|\bFORM\s+SS-?4\b', re.I), DocCategory.EIN_LETTER),
|
||||
# Accounting documents
|
||||
(re.compile(r'\bENGAGEMENT\s+LETTER\b|\bTAX\s+RETURN\s+PREPARATION\s+SERVICES\b', re.I), DocCategory.ENGAGEMENT_LETTER),
|
||||
(re.compile(r'\bTAX\s+ORGANIZER\b|\bLLC\s+TAX\b|\bS[-\s]?CORP\b|\bPARTNERSHIP\s+TAX\b', re.I), DocCategory.TAX_ORGANIZER),
|
||||
@@ -61,7 +73,7 @@ def classify_other_doc(
|
||||
|
||||
Args:
|
||||
ocr_text: Raw text extracted from the document (any amount).
|
||||
filename: Original upload filename — used as a secondary hint.
|
||||
filename: Original upload filename ? used as a secondary hint.
|
||||
"""
|
||||
corpus = f"{filename} {ocr_text}"
|
||||
|
||||
@@ -70,7 +82,7 @@ def classify_other_doc(
|
||||
logger.info(f"[DocClassifier] Detected '{category.value}' from other_* upload")
|
||||
return category
|
||||
|
||||
logger.info("[DocClassifier] No match — defaulting to GENERIC")
|
||||
logger.info("[DocClassifier] No match ? defaulting to GENERIC")
|
||||
return DocCategory.GENERIC
|
||||
|
||||
|
||||
|
||||
@@ -29,6 +29,8 @@ async def send_email(to: str, subject: str, body: str) -> bool:
|
||||
smtp_port = int(os.getenv("SMTP_PORT", "587"))
|
||||
smtp_user = os.getenv("SMTP_USER")
|
||||
smtp_password = os.getenv("SMTP_PASSWORD")
|
||||
if smtp_password:
|
||||
smtp_password = smtp_password.replace(" ", "")
|
||||
mail_from_email = os.getenv("MAIL_FROM") or smtp_user
|
||||
mail_from_name = os.getenv("MAIL_FROM_NAME", "BookKeepro")
|
||||
smtp_tls = os.getenv("SMTP_TLS", "True").strip().lower() == "true"
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import os
|
||||
from app.utils.emailer import send_email
|
||||
|
||||
_FRONTEND_URL = os.getenv("FRONTEND_URL", "https://aiindiacpa.duckdns.org")
|
||||
_FRONTEND_URL = os.getenv("FRONTEND_URL", "https://aicpa.duckdns.org")
|
||||
|
||||
|
||||
async def send_signup_welcome_email(to: str, name: str | None = None):
|
||||
|
||||
@@ -38,66 +38,65 @@ def _run_deadline_reminders():
|
||||
).all()
|
||||
admin_emails = [a.email for a in admins]
|
||||
|
||||
for days_out, flag_col, label in thresholds:
|
||||
target_date = today + timedelta(days=days_out)
|
||||
deadlines = (
|
||||
db.query(FilingDeadline)
|
||||
.filter(
|
||||
FilingDeadline.deadline_date == target_date,
|
||||
getattr(FilingDeadline, flag_col) == False,
|
||||
async def _dispatch_reminders():
|
||||
for days_out, flag_col, label in thresholds:
|
||||
target_date = today + timedelta(days=days_out)
|
||||
deadlines = (
|
||||
db.query(FilingDeadline)
|
||||
.filter(
|
||||
FilingDeadline.deadline_date == target_date,
|
||||
getattr(FilingDeadline, flag_col) == False,
|
||||
)
|
||||
.all()
|
||||
)
|
||||
.all()
|
||||
)
|
||||
|
||||
for dl in deadlines:
|
||||
user = db.query(User).filter(User.id == dl.user_id).first()
|
||||
if not user:
|
||||
continue
|
||||
for dl in deadlines:
|
||||
user = db.query(User).filter(User.id == dl.user_id).first()
|
||||
if not user:
|
||||
continue
|
||||
|
||||
doc_label = dl.doc_type.capitalize()
|
||||
doc_label = dl.doc_type.capitalize()
|
||||
|
||||
# Email to user
|
||||
user_body = f"""
|
||||
<p>Dear {user.name or "Sir/Ma'am"},</p>
|
||||
<p>This is a reminder that your <strong>{doc_label} document filing deadline</strong>
|
||||
is in <strong>{label}</strong> ({dl.deadline_date.strftime('%B %d, %Y')}).</p>
|
||||
<p>Please ensure all outstanding actions are completed before the deadline.</p>
|
||||
<p>Kind regards,<br><strong>BookKeepro Team</strong></p>
|
||||
"""
|
||||
asyncio.run(
|
||||
send_email(
|
||||
# Email to user
|
||||
user_body = f"""
|
||||
<p>Dear {user.name or "Sir/Ma'am"},</p>
|
||||
<p>This is a reminder that your <strong>{doc_label} document filing deadline</strong>
|
||||
is in <strong>{label}</strong> ({dl.deadline_date.strftime('%B %d, %Y')}).</p>
|
||||
<p>Please ensure all outstanding actions are completed before the deadline.</p>
|
||||
<p>Kind regards,<br><strong>BookKeepro Team</strong></p>
|
||||
"""
|
||||
await send_email(
|
||||
to=user.email,
|
||||
subject=f"Reminder: {doc_label} Filing Deadline in {label} — BookKeepro",
|
||||
body=user_body,
|
||||
)
|
||||
)
|
||||
|
||||
# Email to all admins
|
||||
admin_body = f"""
|
||||
<p>Admin Notice:</p>
|
||||
<p>The <strong>{doc_label} filing deadline</strong> for client
|
||||
<strong>{user.name or user.email}</strong> ({user.email}) is in
|
||||
<strong>{label}</strong> ({dl.deadline_date.strftime('%B %d, %Y')}).</p>
|
||||
<p>Please review the client's status and take any necessary action.</p>
|
||||
<p><strong>BookKeepro System</strong></p>
|
||||
"""
|
||||
for admin_email in admin_emails:
|
||||
asyncio.run(
|
||||
send_email(
|
||||
# Email to all admins
|
||||
admin_body = f"""
|
||||
<p>Admin Notice:</p>
|
||||
<p>The <strong>{doc_label} filing deadline</strong> for client
|
||||
<strong>{user.name or user.email}</strong> ({user.email}) is in
|
||||
<strong>{label}</strong> ({dl.deadline_date.strftime('%B %d, %Y')}).</p>
|
||||
<p>Please review the client's status and take any necessary action.</p>
|
||||
<p><strong>BookKeepro System</strong></p>
|
||||
"""
|
||||
for admin_email in admin_emails:
|
||||
await send_email(
|
||||
to=admin_email,
|
||||
subject=f"Admin Reminder: {user.email} — {doc_label} Deadline in {label}",
|
||||
body=admin_body,
|
||||
)
|
||||
|
||||
# Mark as notified
|
||||
setattr(dl, flag_col, True)
|
||||
db.commit()
|
||||
|
||||
logger.info(
|
||||
"Sent %s deadline reminder for user %s (%s)",
|
||||
label, dl.user_id, dl.doc_type,
|
||||
)
|
||||
|
||||
# Mark as notified
|
||||
setattr(dl, flag_col, True)
|
||||
db.commit()
|
||||
|
||||
logger.info(
|
||||
"Sent %s deadline reminder for user %s (%s)",
|
||||
label, dl.user_id, dl.doc_type,
|
||||
)
|
||||
asyncio.run(_dispatch_reminders())
|
||||
except Exception as exc:
|
||||
logger.error("Deadline reminder job failed: %s", exc)
|
||||
finally:
|
||||
|
||||
Reference in New Issue
Block a user