Skip to navigation

End-to-End Workflow

This example demonstrates a complete workflow using the Ottimate Python SDK, from creating entities to creating and verifying an invoice.

1. Create a Vendor

First, let’s create a new vendor.

# main.py
time_now = int(datetime.now().timestamp())
vendor_name = f"Sample SDK Vendor {time_now}"
vendor_erp_id = f"VND-SDK-{time_now}"
new_vendor = client.vendors.post_vendors_root(
ottimate_company_id=ottimate_company_id,
name=vendor_name,
erp_vendor_id=vendor_erp_id,
)
ottimate_vendor_id = new_vendor.vendor.get("id")
print(f"✅ Vendor '{vendor_name}' created with ID: {ottimate_vendor_id}")

2. Create a Dimension

Next, we’ll create a dimension that can be used for line item allocation.

# main.py
dimension_name = f"SDK Department {time_now}"
dimension_unique_key = f"dept-sdk-{time_now}"
new_dimension = client.dimensions.post_dimensions_root(
ottimate_company_id=ottimate_company_id,
type="DEPARTMENT",
code="MKT",
dimension_type_code="DEPARTMENT",
name=dimension_name,
unique_key=dimension_unique_key,
)
ottimate_dimension_id = new_dimension.dimension.get("id")
print(f"✅ Dimension '{dimension_name}' created with ID: {ottimate_dimension_id}")

3. Create an Invoice

Now, we’ll create an invoice using the ottimate_vendor_id and ottimate_dimension_id we just received.

# main.py
new_invoice = client.invoices.post_invoices_root(
upload_id=f"SDK-INV-{time_now}",
invoice_number=f"INV-{time_now}",
ottimate_location_id=ottimate_location_id,
ottimate_vendor_id=ottimate_vendor_id,
total_amount=150.0,
total_tax=15.0,
items=[{"name": "SDK Item", "quantity": 1, "price": 150.0, "mappings": {"DEPARTMENT": ottimate_dimension_id }}],
)
ottimate_invoice_id = new_invoice.id
print(f"✅ Invoice created with ID: {ottimate_invoice_id}")

4. Check Invoice Status

After creating the invoice, you can check its status and any potential errors.

# main.py
# --- Logging invoice creation status ---
print(f"✅ Invoice created with ID: {ottimate_invoice_id} | {new_invoice}")
if hasattr(new_invoice, 'status') and new_invoice.status:
print(f" - Overall Invoice Status: '{new_invoice.status}'")
for error in new_invoice.errors:
print(f" - Error: {error}")
if hasattr(new_invoice, 'items') and new_invoice.items:
# --- Logging invoice line item creation status ---
item_status_response = new_invoice.items
print(f" - Line Item Ingestion Status: '{item_status_response.status}'")
if hasattr(item_status_response, 'success') and item_status_response.success:
print(" - Success Items:")
for index, item_id in item_status_response.success.items():
print(f" - ' (Original Index {index}): Created with item Id: {item_id}")
if hasattr(item_status_response, 'failure') and item_status_response.failure:
print(" - Failed Items:")
for index, error_message in item_status_response.failure.items():
print(f" - ' (Original Index {index}): Failed with error: {error_message}")
else:
print(" - No line item details returned in the response.")

5. Fetch the Invoice

Finally, you can fetch the invoice by its ID to verify its details.

# main.py
print(f"\n🔍 Fetching invoice with ID: {ottimate_invoice_id}...")
fetched_invoice = client.invoices.get_invoices_id(id=ottimate_invoice_id)
if fetched_invoice:
print(f"✅ Successfully fetched invoice. Invoice Number: {fetched_invoice.invoice_number}")
else:
print("🔥 Error: Could not fetch the invoice.")