94 lines
4.0 KiB
Python
94 lines
4.0 KiB
Python
from typing import Any, Dict
|
|
|
|
from uuid6 import uuid7
|
|
|
|
|
|
def none_to_empty(value: Any) -> str:
|
|
return "" if value is None else value
|
|
|
|
|
|
def create_invoice_header(
|
|
cf,
|
|
hif,
|
|
payment_method_id,
|
|
payment_method_description
|
|
) -> Dict[str, Any]:
|
|
return {
|
|
"id": str(uuid7()),
|
|
"factuges_id": hif.get("factuges_id"),
|
|
"company_id": hif.get("company_id"),
|
|
"is_proforma": hif.get("is_proforma"),
|
|
"status": hif.get("status"),
|
|
"series": hif.get("series"),
|
|
"reference": hif.get("reference"),
|
|
"description": hif.get("description"),
|
|
"invoice_date": hif.get("invoice_date"),
|
|
"operation_date": hif.get("operation_date"),
|
|
"notes": none_to_empty(hif.get("notes")),
|
|
"language_code": cf.get("language_code"),
|
|
|
|
"subtotal_amount_value": none_to_empty(hif.get("subtotal_amount_value")),
|
|
"global_discount_percentage": none_to_empty(hif.get("discount_percentage_val")),
|
|
"discount_amount_value": none_to_empty(hif.get("discount_amount_value")),
|
|
"taxable_amount_value": hif.get("taxable_amount_value"),
|
|
"taxes_amount_value": hif.get("taxes_amount_value"),
|
|
"total_amount_value": hif.get("total_amount_value"),
|
|
"payment_method_id": payment_method_id,
|
|
"payment_method_description": payment_method_description,
|
|
|
|
"customer": {
|
|
"is_company": cf["is_company"],
|
|
"name": cf["name"],
|
|
"tin": cf["tin"],
|
|
"street": cf["street"],
|
|
"city": cf["city"],
|
|
"province": cf["province"],
|
|
"postal_code": cf["postal_code"],
|
|
"country": cf["country"],
|
|
"language_code": cf["language_code"],
|
|
"phone_primary": none_to_empty(cf["phone_primary"]),
|
|
"phone_secondary": none_to_empty(cf["phone_secondary"]),
|
|
"mobile_primary": none_to_empty(cf["mobile_primary"]),
|
|
"mobile_secondary": none_to_empty(cf["mobile_secondary"]),
|
|
"email_primary": none_to_empty(cf["email_primary"]),
|
|
"email_secondary": none_to_empty(cf["email_secondary"]),
|
|
"website": cf["website"],
|
|
},
|
|
|
|
"items": [],
|
|
|
|
}
|
|
|
|
|
|
def insert_item_and_taxes(fields) -> Dict[str, Any]:
|
|
# logger.info(fields)
|
|
return {
|
|
"item_id": str(uuid7()),
|
|
"position": str(fields.get("position")),
|
|
"description": fields.get("description"),
|
|
"quantity_value": str(fields.get("quantity_value")),
|
|
"unit_value": str(fields.get("unit_value")),
|
|
"subtotal_amount_value": fields.get("subtotal_amount_value"),
|
|
"item_discount_percentage_value": none_to_empty(fields.get("item_discount_percentage_value")),
|
|
"item_discount_amount_value": none_to_empty(fields.get("item_discount_amount_value")),
|
|
"global_discount_percentage_value": none_to_empty(fields.get("global_discount_percentage_value")),
|
|
"global_discount_amount_value": none_to_empty(fields.get("global_discount_amount_value")),
|
|
"total_discount_amount_value": fields.get("total_discount_amount_value"),
|
|
"taxable_amount_value": fields.get("taxable_amount_value"),
|
|
"total_value": fields.get("total_value"),
|
|
"iva_code": fields.get("iva_code"),
|
|
"iva_percentage_value": str(fields.get("iva_percentage_value")),
|
|
"iva_amount_value": fields.get("iva_amount_value"),
|
|
"rec_code": none_to_empty(fields.get("rec_code")),
|
|
"rec_percentage_value": none_to_empty(fields.get("rec_percentage_value")),
|
|
"rec_amount_value": fields.get("rec_amount_value"),
|
|
"taxes_amount_value": fields.get("taxes_amount_value"),
|
|
}
|
|
|
|
# logger.info("Inserting item tax %s code=%s base=%s tax=%s",
|
|
# item_id, fields.get('tax_code'), fields.get('total_value'), fields.get('tax_amount'))
|
|
# cur.execute(
|
|
# SQL.INSERT_INVOICE_ITEM_TAX, (str(uuid7()), item_id, fields.get('tax_code'),
|
|
# fields.get('total_value'), fields.get('tax_amount'))
|
|
# )
|