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.

1# main.py
2
3time_now = int(datetime.now().timestamp())
4vendor_name = f"Sample SDK Vendor {time_now}"
5vendor_erp_id = f"VND-SDK-{time_now}"
6
7new_vendor = client.vendors.post_vendors_root(
8 ottimate_company_id=ottimate_company_id,
9 name=vendor_name,
10 erp_vendor_id=vendor_erp_id,
11)
12ottimate_vendor_id = new_vendor.vendor.get("id")
13print(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.

1# main.py
2
3dimension_name = f"SDK Department {time_now}"
4dimension_unique_key = f"dept-sdk-{time_now}"
5
6new_dimension = client.dimensions.post_dimensions_root(
7 ottimate_company_id=ottimate_company_id,
8 type="DEPARTMENT",
9 code="MKT",
10 dimension_type_code="DEPARTMENT",
11 name=dimension_name,
12 unique_key=dimension_unique_key,
13)
14ottimate_dimension_id = new_dimension.dimension.get("id")
15print(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.

1# main.py
2
3new_invoice = client.invoices.post_invoices_root(
4 upload_id=f"SDK-INV-{time_now}",
5 invoice_number=f"INV-{time_now}",
6 ottimate_location_id=ottimate_location_id,
7 ottimate_vendor_id=ottimate_vendor_id,
8 total_amount=150.0,
9 total_tax=15.0,
10 items=[{"name": "SDK Item", "quantity": 1, "price": 150.0, "mappings": {"DEPARTMENT": ottimate_dimension_id }}],
11)
12ottimate_invoice_id = new_invoice.id
13print(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.

1# main.py
2
3# --- Logging invoice creation status ---
4print(f"✅ Invoice created with ID: {ottimate_invoice_id} | {new_invoice}")
5if hasattr(new_invoice, 'status') and new_invoice.status:
6 print(f" - Overall Invoice Status: '{new_invoice.status}'")
7 for error in new_invoice.errors:
8 print(f" - Error: {error}")
9
10if hasattr(new_invoice, 'items') and new_invoice.items:
11 # --- Logging invoice line item creation status ---
12 item_status_response = new_invoice.items
13 print(f" - Line Item Ingestion Status: '{item_status_response.status}'")
14
15 if hasattr(item_status_response, 'success') and item_status_response.success:
16 print(" - Success Items:")
17 for index, item_id in item_status_response.success.items():
18 print(f" - ' (Original Index {index}): Created with item Id: {item_id}")
19
20 if hasattr(item_status_response, 'failure') and item_status_response.failure:
21 print(" - Failed Items:")
22 for index, error_message in item_status_response.failure.items():
23 print(f" - ' (Original Index {index}): Failed with error: {error_message}")
24else:
25 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.

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