You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
45 lines
1.1 KiB
45 lines
1.1 KiB
cd /home/def/otb_billing/backend || exit 1 |
|
|
|
STAMP="$(date +%Y%m%d-%H%M%S)" |
|
cp app.py "app.py.email-attachment.${STAMP}.bak" |
|
|
|
python3 <<'PY' |
|
from pathlib import Path |
|
|
|
p = Path("app.py") |
|
t = p.read_text() |
|
|
|
# Find the payment confirmation email block |
|
old = "attachments=None," |
|
|
|
new = """attachments=[{ |
|
"filename": f"invoice_{invoice.get('invoice_number')}.pdf", |
|
"content": generate_invoice_pdf_bytes(invoice_id), |
|
"mime": "application/pdf" |
|
}],""" |
|
|
|
if old not in t: |
|
raise SystemExit("FAILED: attachments=None not found") |
|
|
|
t = t.replace(old, new, 1) |
|
|
|
# Add helper function if missing |
|
if "def generate_invoice_pdf_bytes" not in t: |
|
t += """ |
|
|
|
def generate_invoice_pdf_bytes(invoice_id): |
|
from io import BytesIO |
|
buffer = BytesIO() |
|
c = canvas.Canvas(buffer, pagesize=letter) |
|
c.drawString(100, 750, f"Invoice #{invoice_id}") |
|
c.drawString(100, 730, "Generated by OTB Billing") |
|
c.save() |
|
buffer.seek(0) |
|
return buffer.read() |
|
""" |
|
|
|
p.write_text(t) |
|
print("OK: email attachment patch applied") |
|
PY |
|
|
|
sudo systemctl restart otb_billing.service
|
|
|