in invoice-processing-pipeline/processor/process.py [0:0]
def save_processed_document(document, blob):
collection = os.getenv("COLLECTION", "invoices")
info = document_info(document)
total_string = re.sub(r"[,\$]", "", info.get("total_amount", "N/A"))
try:
total = float(total_string)
except:
total = 0.0
paid_string = re.sub(r"[,\$]", "", info.get("amount_paid_since_last_invoice", "N/A"))
try:
paid = float(paid_string)
except:
paid = 0.0
rounded_total = "{:.2f}".format(total)
rounded_amount_due = "{:.2f}".format(total - paid)
data = {
"blob_name": blob.name[len(INCOMING_PREFIX):],
"company": info.get("supplier_name", "Missing name"),
"date": info.get("invoice_date", "N/A").strip(),
"due_date": info.get("due_date", "N/A").strip(),
"total": rounded_total,
"amount_due": rounded_amount_due,
"state": "Not Approved"
}
db.collection(collection).document(data["blob_name"]).set(data)