Catalog Allowances

This section covers managing catalog allowances using the Ottimate SDK.

Fetching Catalog Allowances

You can retrieve all allowances for a company, with optional filters.

1# main.py
2
3catalog_allowances = client.catalog.get_catalog_allowances(
4 ottimate_company_id=ottimate_company_id
5)
6print(f"Fetched {len(catalog_allowances.results)} catalog allowances.")
7for allowance in catalog_allowances.results:
8 print(f" - Allowance ID: {allowance.id}, Amount: {allowance.amount}, Catalog Entry: {allowance.catalog_entry_id}")

Fetching Catalog Allowances with Filters

You can filter allowances by location or effective date.

1# main.py
2
3# Filter by location
4catalog_allowances = client.catalog.get_catalog_allowances(
5 ottimate_company_id=ottimate_company_id,
6 ottimate_location_id=location_id
7)
8
9# Filter by effective date
10from datetime import datetime
11today = datetime.now().strftime("%Y-%m-%d")
12catalog_allowances = client.catalog.get_catalog_allowances(
13 ottimate_company_id=ottimate_company_id,
14 effective_date=today
15)

Creating a Catalog Allowance

This example shows how to create a new allowance for a catalog entry.

1# main.py
2
3from datetime import datetime
4
5start_date = datetime.now()
6new_allowance = client.catalog.post_catalog_allowances(
7 ottimate_company_id=ottimate_company_id,
8 catalog_entry_id=catalog_entry_id,
9 amount=5.00,
10 start_date=start_date
11)
12print(f"Created catalog allowance with ID {new_allowance.id}")

Updating a Catalog Allowance

You can update an existing allowance by its ID.

1# main.py
2
3updated_allowance = client.catalog.patch_catalog_allowances_id(
4 id=allowance_id,
5 amount=7.50
6)
7print(f"Updated catalog allowance ID {allowance_id} to new amount: {updated_allowance.amount}")

Bulk Creating Catalog Allowances

This example demonstrates how to create multiple allowances in a single API call.

1# main.py
2
3from datetime import datetime, timedelta
4from ottimate.catalog.types.catalog_allowance_bulk_create_request_allowances_item import CatalogAllowanceBulkCreateRequestAllowancesItem
5
6start_date = datetime.now()
7
8allowances = [
9 CatalogAllowanceBulkCreateRequestAllowancesItem(
10 catalog_entry_id=catalog_entry_id,
11 amount=5.00,
12 start_date=start_date,
13 reference_id=f"bulk-allow-1-{time_now}"
14 ),
15 CatalogAllowanceBulkCreateRequestAllowancesItem(
16 catalog_entry_id=catalog_entry_id,
17 amount=3.00,
18 start_date=start_date + timedelta(days=30),
19 reference_id=f"bulk-allow-2-{time_now}"
20 ),
21]
22
23bulk_response = client.catalog.post_catalog_allowances_bulk(
24 ottimate_company_id=ottimate_company_id,
25 allowances=allowances
26)
27
28print(f"Bulk created {bulk_response.success_count} catalog allowances.")
29
30if hasattr(bulk_response, "created") and bulk_response.created:
31 print("Created allowances:")
32 for allowance in bulk_response.created:
33 print(f" - ID: {allowance.get('id')}, Catalog Entry: {allowance.get('catalog_entry_id')}, Amount: {allowance.get('amount')}")
34
35if hasattr(bulk_response, "updated") and bulk_response.updated:
36 print("Updated allowances:")
37 for allowance in bulk_response.updated:
38 print(f" - ID: {allowance.get('id')}, Catalog Entry: {allowance.get('catalog_entry_id')}, Amount: {allowance.get('amount')}")
39
40if hasattr(bulk_response, "errors") and bulk_response.errors:
41 print("Failed allowances:")
42 for error in bulk_response.errors:
43 print(f" - Error: {error}")