branddrive-python-sdk 0.1.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (45) hide show
  1. branddrive/__init__.py +33 -0
  2. branddrive/client.py +134 -0
  3. branddrive/config.py +15 -0
  4. branddrive/dataclasses/__init__.py +118 -0
  5. branddrive/dataclasses/_utils.py +8 -0
  6. branddrive/dataclasses/customers.py +66 -0
  7. branddrive/dataclasses/expenses.py +155 -0
  8. branddrive/dataclasses/invoices.py +131 -0
  9. branddrive/dataclasses/payment_links.py +134 -0
  10. branddrive/dataclasses/pos.py +141 -0
  11. branddrive/dataclasses/products.py +166 -0
  12. branddrive/dataclasses/purchase_orders.py +141 -0
  13. branddrive/dataclasses/services.py +76 -0
  14. branddrive/dataclasses/vendors.py +48 -0
  15. branddrive/dataclasses/wallets.py +72 -0
  16. branddrive/exceptions.py +35 -0
  17. branddrive/protocols/__init__.py +43 -0
  18. branddrive/protocols/analytics.py +61 -0
  19. branddrive/protocols/customers.py +42 -0
  20. branddrive/protocols/expenses.py +69 -0
  21. branddrive/protocols/invoices.py +81 -0
  22. branddrive/protocols/payment_links.py +49 -0
  23. branddrive/protocols/pos.py +88 -0
  24. branddrive/protocols/products.py +150 -0
  25. branddrive/protocols/purchase_orders.py +68 -0
  26. branddrive/protocols/services.py +56 -0
  27. branddrive/protocols/vendors.py +39 -0
  28. branddrive/protocols/wallets.py +52 -0
  29. branddrive/resources/__init__.py +125 -0
  30. branddrive/resources/_utils.py +10 -0
  31. branddrive/resources/analytics.py +198 -0
  32. branddrive/resources/customers.py +194 -0
  33. branddrive/resources/expenses.py +209 -0
  34. branddrive/resources/invoices.py +268 -0
  35. branddrive/resources/payment_links.py +265 -0
  36. branddrive/resources/pos.py +353 -0
  37. branddrive/resources/products.py +612 -0
  38. branddrive/resources/purchase_orders.py +235 -0
  39. branddrive/resources/services.py +184 -0
  40. branddrive/resources/vendors.py +152 -0
  41. branddrive/resources/wallets.py +204 -0
  42. branddrive_python_sdk-0.1.0.dist-info/METADATA +132 -0
  43. branddrive_python_sdk-0.1.0.dist-info/RECORD +45 -0
  44. branddrive_python_sdk-0.1.0.dist-info/WHEEL +5 -0
  45. branddrive_python_sdk-0.1.0.dist-info/top_level.txt +1 -0
@@ -0,0 +1,235 @@
1
+ from __future__ import annotations
2
+
3
+ from datetime import date, datetime
4
+ from typing import Any, Optional
5
+ from urllib.parse import quote
6
+
7
+ import httpx
8
+
9
+ from ..exceptions import handle_api_exception
10
+ from ..dataclasses.purchase_orders import (
11
+ PurchaseOrderCreate,
12
+ PurchaseOrderPaymentCreate,
13
+ PurchaseOrderProcurementCreate,
14
+ PurchaseOrderUpdate,
15
+ )
16
+
17
+
18
+ class PurchaseOrder:
19
+ def __init__(self, client: httpx.Client) -> None:
20
+ self.client = client
21
+
22
+ @staticmethod
23
+ def _validate_id(name: str, value: int) -> None:
24
+ if isinstance(value, bool) or not isinstance(value, int):
25
+ raise TypeError(f"{name} must be an integer")
26
+ if value < 1:
27
+ raise ValueError(f"{name} must be greater than 0")
28
+
29
+ @staticmethod
30
+ def _path_id(name: str, value: int) -> str:
31
+ PurchaseOrder._validate_id(name, value)
32
+ return quote(str(value), safe="")
33
+
34
+ @staticmethod
35
+ def _handle_response(response: httpx.Response) -> dict[str, Any]:
36
+ if not response.is_success:
37
+ raise handle_api_exception(response)
38
+ return response.json()
39
+
40
+ @staticmethod
41
+ def _handle_binary_response(response: httpx.Response) -> bytes:
42
+ if not response.is_success:
43
+ raise handle_api_exception(response)
44
+ return response.content
45
+
46
+ def create_purchase_order(
47
+ self,
48
+ purchase_order_data: PurchaseOrderCreate,
49
+ ) -> dict[str, Any]:
50
+ """Create a purchase order."""
51
+ response = self.client.request(
52
+ "POST",
53
+ "/api/v1/purchase-order/",
54
+ json=purchase_order_data.to_dict(),
55
+ )
56
+ return self._handle_response(response)
57
+
58
+ def list_purchase_orders(
59
+ self,
60
+ currency_id: int,
61
+ branch_id: Optional[int] = None,
62
+ limit: int = 10,
63
+ offset: int = 0,
64
+ start_date: Optional[date] = None,
65
+ end_date: Optional[date] = None,
66
+ ) -> dict[str, Any]:
67
+ """List purchase orders with optional filters and pagination."""
68
+ self._validate_id("currency_id", currency_id)
69
+ if branch_id is not None:
70
+ self._validate_id("branch_id", branch_id)
71
+
72
+ for name, value in (("limit", limit), ("offset", offset)):
73
+ if isinstance(value, bool) or not isinstance(value, int):
74
+ raise TypeError(f"{name} must be an integer")
75
+ if limit < 1:
76
+ raise ValueError("limit must be greater than 0")
77
+ if offset < 0:
78
+ raise ValueError("offset must be greater than or equal to 0")
79
+ if start_date is not None and (
80
+ isinstance(start_date, datetime) or not isinstance(start_date, date)
81
+ ):
82
+ raise TypeError("start_date must be a date")
83
+ if end_date is not None and (
84
+ isinstance(end_date, datetime) or not isinstance(end_date, date)
85
+ ):
86
+ raise TypeError("end_date must be a date")
87
+
88
+ params: dict[str, int | str] = {
89
+ "currencyId": currency_id,
90
+ "limit": limit,
91
+ "offset": offset,
92
+ }
93
+ if branch_id is not None:
94
+ params["branchId"] = branch_id
95
+ if start_date is not None:
96
+ params["startDate"] = start_date.isoformat()
97
+ if end_date is not None:
98
+ params["endDate"] = end_date.isoformat()
99
+
100
+ response = self.client.request(
101
+ "GET",
102
+ "/api/v1/purchase-order",
103
+ params=params,
104
+ )
105
+ return self._handle_response(response)
106
+
107
+ def retrieve_purchase_order(
108
+ self,
109
+ purchase_order_id: int,
110
+ ) -> dict[str, Any]:
111
+ """Retrieve a purchase order by ID."""
112
+ purchase_order_path_id = self._path_id(
113
+ "purchase_order_id",
114
+ purchase_order_id,
115
+ )
116
+ response = self.client.request(
117
+ "GET",
118
+ f"/api/v1/purchase-order/{purchase_order_path_id}",
119
+ )
120
+ return self._handle_response(response)
121
+
122
+ def update_purchase_order(
123
+ self,
124
+ purchase_order_id: int,
125
+ purchase_order_data: PurchaseOrderUpdate,
126
+ ) -> dict[str, Any]:
127
+ """Update a purchase order."""
128
+ purchase_order_path_id = self._path_id(
129
+ "purchase_order_id",
130
+ purchase_order_id,
131
+ )
132
+ response = self.client.request(
133
+ "PATCH",
134
+ f"/api/v1/purchase-order/{purchase_order_path_id}",
135
+ json=purchase_order_data.to_dict(),
136
+ )
137
+ return self._handle_response(response)
138
+
139
+ def delete_purchase_order(
140
+ self,
141
+ purchase_order_id: int,
142
+ ) -> dict[str, Any]:
143
+ """Delete a purchase order."""
144
+ purchase_order_path_id = self._path_id(
145
+ "purchase_order_id",
146
+ purchase_order_id,
147
+ )
148
+ response = self.client.request(
149
+ "DELETE",
150
+ f"/api/v1/purchase-order/{purchase_order_path_id}",
151
+ )
152
+ return self._handle_response(response)
153
+
154
+ def add_procurement(
155
+ self,
156
+ purchase_order_id: int,
157
+ procurement: PurchaseOrderProcurementCreate,
158
+ ) -> dict[str, Any]:
159
+ """Add a product procurement to a purchase order."""
160
+ purchase_order_path_id = self._path_id(
161
+ "purchase_order_id",
162
+ purchase_order_id,
163
+ )
164
+ response = self.client.request(
165
+ "POST",
166
+ f"/api/v1/purchase-order/{purchase_order_path_id}/procurement",
167
+ json=procurement.to_dict(),
168
+ )
169
+ return self._handle_response(response)
170
+
171
+ def update_procurement(self, procurement_id: int) -> dict[str, Any]:
172
+ """Update a purchase-order procurement using the documented endpoint."""
173
+ procurement_path_id = self._path_id(
174
+ "procurement_id",
175
+ procurement_id,
176
+ )
177
+ response = self.client.request(
178
+ "PATCH",
179
+ f"/api/v1/purchase-order/procurement/{procurement_path_id}",
180
+ )
181
+ return self._handle_response(response)
182
+
183
+ def delete_procurement(self, procurement_id: int) -> dict[str, Any]:
184
+ """Delete a purchase-order procurement."""
185
+ procurement_path_id = self._path_id(
186
+ "procurement_id",
187
+ procurement_id,
188
+ )
189
+ response = self.client.request(
190
+ "DELETE",
191
+ f"/api/v1/purchase-order/procurement/{procurement_path_id}",
192
+ )
193
+ return self._handle_response(response)
194
+
195
+ def record_payment(
196
+ self,
197
+ purchase_order_id: int,
198
+ payment_data: PurchaseOrderPaymentCreate,
199
+ ) -> dict[str, Any]:
200
+ """Record a payment against a purchase order."""
201
+ purchase_order_path_id = self._path_id(
202
+ "purchase_order_id",
203
+ purchase_order_id,
204
+ )
205
+ response = self.client.request(
206
+ "POST",
207
+ f"/api/v1/purchase-order/{purchase_order_path_id}/payment/record",
208
+ json=payment_data.to_dict(),
209
+ )
210
+ return self._handle_response(response)
211
+
212
+ def delete_payment(
213
+ self,
214
+ purchase_order_id: int,
215
+ payment_id: int,
216
+ ) -> dict[str, Any]:
217
+ """Delete a recorded purchase-order payment."""
218
+ purchase_order_path_id = self._path_id(
219
+ "purchase_order_id",
220
+ purchase_order_id,
221
+ )
222
+ payment_path_id = self._path_id("payment_id", payment_id)
223
+ response = self.client.request(
224
+ "DELETE",
225
+ f"/api/v1/purchase-order/{purchase_order_path_id}/payment/{payment_path_id}",
226
+ )
227
+ return self._handle_response(response)
228
+
229
+ def export_payments(self) -> bytes:
230
+ """Export purchase-order payment records."""
231
+ response = self.client.request(
232
+ "GET",
233
+ "/api/v1/purchase-order/export",
234
+ )
235
+ return self._handle_binary_response(response)
@@ -0,0 +1,184 @@
1
+ from __future__ import annotations
2
+
3
+ from typing import Any, Optional
4
+ from urllib.parse import quote
5
+
6
+ import httpx
7
+
8
+ from ..exceptions import handle_api_exception
9
+ from ..dataclasses.services import (
10
+ ServiceCategoryCreate,
11
+ ServiceCategoryUpdate,
12
+ ServiceCreate,
13
+ UpdateServiceData,
14
+ )
15
+ from ..protocols.services import _ServiceAPI, _ServiceCategoryAPI
16
+ from ._utils import validate_pagination
17
+
18
+
19
+ class Service:
20
+ def __init__(self, client: httpx.Client) -> None:
21
+ self.client = client
22
+ self.category: _ServiceCategoryAPI = Category(client)
23
+
24
+ @staticmethod
25
+ def _validate_id(name: str, value: int) -> str:
26
+ if isinstance(value, bool) or not isinstance(value, int):
27
+ raise TypeError(f"{name} must be an integer")
28
+ if value < 1:
29
+ raise ValueError(f"{name} must be greater than 0")
30
+ return quote(str(value), safe="")
31
+
32
+ def _handle_response(self, response: httpx.Response) -> dict[str, Any]:
33
+ if not response.is_success:
34
+ raise handle_api_exception(response)
35
+ return response.json()
36
+
37
+ def create_service(self, service_data: ServiceCreate) -> dict[str, Any]:
38
+ """Create a service."""
39
+ response = self.client.request(
40
+ "POST",
41
+ "/api/v1/services",
42
+ json=service_data.to_dict(),
43
+ )
44
+ return self._handle_response(response)
45
+
46
+ def list_services(
47
+ self,
48
+ limit: int = 10,
49
+ offset: int = 0,
50
+ search: Optional[str] = None,
51
+ sort: Optional[int] = None,
52
+ ) -> dict[str, Any]:
53
+ """List services with pagination and optional search/sort."""
54
+ validate_pagination(limit, offset)
55
+ if search is not None and not isinstance(search, str):
56
+ raise TypeError("search must be a string")
57
+ if sort is not None and (
58
+ isinstance(sort, bool) or not isinstance(sort, int)
59
+ ):
60
+ raise TypeError("sort must be an integer")
61
+
62
+ params: dict[str, int | str] = {
63
+ "limit": limit,
64
+ "offset": offset,
65
+ }
66
+ if search is not None:
67
+ params["search"] = search
68
+ if sort is not None:
69
+ params["sort"] = sort
70
+
71
+ response = self.client.request(
72
+ "GET",
73
+ "/api/v1/services",
74
+ params=params,
75
+ )
76
+ return self._handle_response(response)
77
+
78
+ def retrieve_service(self, service_id: int) -> dict[str, Any]:
79
+ """Retrieve one service."""
80
+ service_path_id = self._validate_id("service_id", service_id)
81
+ response = self.client.request(
82
+ "GET",
83
+ f"/api/v1/services/{service_path_id}",
84
+ )
85
+ return self._handle_response(response)
86
+
87
+ def update_service(
88
+ self,
89
+ service_id: int,
90
+ service_data: UpdateServiceData,
91
+ ) -> dict[str, Any]:
92
+ """Update a service."""
93
+ service_path_id = self._validate_id("service_id", service_id)
94
+ response = self.client.request(
95
+ "PATCH",
96
+ f"/api/v1/services/{service_path_id}",
97
+ json=service_data.to_dict(),
98
+ )
99
+ return self._handle_response(response)
100
+
101
+ def delete_service(self, service_id: int) -> dict[str, Any]:
102
+ """Delete one service."""
103
+ service_path_id = self._validate_id("service_id", service_id)
104
+ response = self.client.request(
105
+ "DELETE",
106
+ f"/api/v1/services/{service_path_id}",
107
+ )
108
+ return self._handle_response(response)
109
+
110
+ def delete_bulk_services(self, service_ids: list[int]) -> dict[str, Any]:
111
+ """Delete multiple services."""
112
+ if not isinstance(service_ids, list) or not service_ids:
113
+ raise ValueError("service_ids must be a non-empty list")
114
+ for service_id in service_ids:
115
+ self._validate_id("service_id", service_id)
116
+
117
+ response = self.client.request(
118
+ "DELETE",
119
+ "/api/v1/services/bulk",
120
+ json={"bulkServiceIds": service_ids},
121
+ )
122
+ return self._handle_response(response)
123
+
124
+
125
+ class Category(Service):
126
+ def __init__(self, client: httpx.Client) -> None:
127
+ self.client = client
128
+
129
+ def create_category(
130
+ self,
131
+ category_data: ServiceCategoryCreate,
132
+ ) -> dict[str, Any]:
133
+ """Create a service category."""
134
+ response = self.client.request(
135
+ "POST",
136
+ "/api/v1/services/category",
137
+ json=category_data.to_dict(),
138
+ )
139
+ return self._handle_response(response)
140
+
141
+ def list_categories(self, limit: Optional[int] = 10) -> dict[str, Any]:
142
+ """List service categories."""
143
+ if limit is not None:
144
+ if isinstance(limit, bool) or not isinstance(limit, int):
145
+ raise TypeError("limit must be an integer")
146
+ if limit < 1:
147
+ raise ValueError("limit must be greater than 0")
148
+
149
+ params = {"limit": limit} if limit is not None else {}
150
+ response = self.client.request(
151
+ "GET",
152
+ "/api/v1/services/category",
153
+ params=params,
154
+ )
155
+ return self._handle_response(response)
156
+
157
+ def update_category(
158
+ self,
159
+ category_id: int,
160
+ category_data: ServiceCategoryUpdate,
161
+ ) -> dict[str, Any]:
162
+ """Update a service category."""
163
+ category_path_id = self._validate_id(
164
+ "category_id",
165
+ category_id,
166
+ )
167
+ response = self.client.request(
168
+ "PATCH",
169
+ f"/api/v1/services/category/{category_path_id}",
170
+ json=category_data.to_dict(),
171
+ )
172
+ return self._handle_response(response)
173
+
174
+ def delete_category(self, category_id: int) -> dict[str, Any]:
175
+ """Delete a service category."""
176
+ category_path_id = self._validate_id(
177
+ "category_id",
178
+ category_id,
179
+ )
180
+ response = self.client.request(
181
+ "DELETE",
182
+ f"/api/v1/services/category/{category_path_id}",
183
+ )
184
+ return self._handle_response(response)
@@ -0,0 +1,152 @@
1
+ from __future__ import annotations
2
+
3
+ from pathlib import Path
4
+ from typing import Any, Optional
5
+ from urllib.parse import quote
6
+
7
+ import httpx
8
+
9
+ from ..exceptions import handle_api_exception
10
+ from ..dataclasses.vendors import VendorData, UpdateVendorData
11
+ from ._utils import validate_pagination
12
+
13
+
14
+ class Vendor:
15
+ def __init__(self, client: httpx.Client) -> None:
16
+ self.client = client
17
+
18
+ @staticmethod
19
+ def _validate_id(name: str, value: int) -> None:
20
+ if isinstance(value, bool) or not isinstance(value, int):
21
+ raise TypeError(f"{name} must be an integer")
22
+ if value < 1:
23
+ raise ValueError(f"{name} must be greater than 0")
24
+
25
+ @staticmethod
26
+ def _path_id(name: str, value: int) -> str:
27
+ Vendor._validate_id(name, value)
28
+ return quote(str(value), safe="")
29
+
30
+ def _handle_response(self, response: httpx.Response) -> dict[str, Any]:
31
+ if not response.is_success:
32
+ raise handle_api_exception(response)
33
+ return response.json()
34
+
35
+ def _handle_binary_response(self, response: httpx.Response) -> bytes:
36
+ if not response.is_success:
37
+ raise handle_api_exception(response)
38
+ return response.content
39
+
40
+ def create_vendor(self, vendor_data: VendorData) -> dict[str, Any]:
41
+ """Create a vendor record."""
42
+ response = self.client.request(
43
+ "POST",
44
+ "/api/v1/vendor",
45
+ json=vendor_data.to_dict(),
46
+ )
47
+ return self._handle_response(response)
48
+
49
+ def import_csv(
50
+ self,
51
+ file_path: str | Path,
52
+ file_field: str = "Data",
53
+ ) -> dict[str, Any]:
54
+ """Import vendor records from a CSV file."""
55
+ if not isinstance(file_field, str) or not file_field.strip():
56
+ raise ValueError("file_field must be a non-empty string")
57
+
58
+ path = Path(file_path)
59
+ if not path.exists():
60
+ raise FileNotFoundError(f"{file_path} not found.")
61
+ if not path.is_file():
62
+ raise ValueError("Supported path must be a file.")
63
+ if path.suffix.lower() != ".csv":
64
+ raise ValueError("Only CSV files are supported.")
65
+
66
+ with path.open("rb") as csv_file:
67
+ response = self.client.request(
68
+ "POST",
69
+ "/api/v1/vendor/import",
70
+ files={
71
+ file_field: (
72
+ path.name,
73
+ csv_file,
74
+ "text/csv",
75
+ )
76
+ },
77
+ )
78
+ return self._handle_response(response)
79
+
80
+ def export(
81
+ self,
82
+ branch_id: Optional[int] = None,
83
+ email: Optional[str] = None,
84
+ file_type: Optional[str] = "csv",
85
+ ) -> bytes:
86
+ """Download vendor records as a file."""
87
+ params: dict[str, int | str] = {}
88
+ if branch_id is not None:
89
+ self._validate_id("branch_id", branch_id)
90
+ params["branchId"] = branch_id
91
+ if email is not None:
92
+ if not isinstance(email, str):
93
+ raise TypeError("email must be a string")
94
+ params["email"] = email
95
+ if file_type is not None:
96
+ if not isinstance(file_type, str):
97
+ raise TypeError("file_type must be a string")
98
+ params["type"] = file_type
99
+
100
+ response = self.client.request(
101
+ "GET",
102
+ "/api/v1/vendor/download",
103
+ params=params,
104
+ )
105
+ return self._handle_binary_response(response)
106
+
107
+ def list_vendors(
108
+ self,
109
+ limit: int = 10,
110
+ offset: int = 0,
111
+ ) -> dict[str, Any]:
112
+ """List vendor records with pagination."""
113
+ validate_pagination(limit, offset)
114
+ response = self.client.request(
115
+ "GET",
116
+ "/api/v1/vendor",
117
+ params={"offset": offset, "limit": limit},
118
+ )
119
+ return self._handle_response(response)
120
+
121
+ def retrieve_vendor(self, vendor_id: int) -> dict[str, Any]:
122
+ """Retrieve one vendor record."""
123
+ vendor_path_id = self._path_id("vendor_id", vendor_id)
124
+ response = self.client.request(
125
+ "GET",
126
+ f"/api/v1/vendor/{vendor_path_id}",
127
+ )
128
+ return self._handle_response(response)
129
+
130
+ def update_vendor(
131
+ self,
132
+ vendor_id: int,
133
+ vendor_data: UpdateVendorData,
134
+ ) -> dict[str, Any]:
135
+ """Update a vendor record."""
136
+ vendor_path_id = self._path_id("vendor_id", vendor_id)
137
+ response = self.client.request(
138
+ "PATCH",
139
+ f"/api/v1/vendor/{vendor_path_id}",
140
+ json=vendor_data.to_dict(),
141
+ )
142
+ return self._handle_response(response)
143
+
144
+ def toggle_status(self, vendor_id: int) -> dict[str, Any]:
145
+ """Toggle a vendor's active status."""
146
+ self._validate_id("vendor_id", vendor_id)
147
+ response = self.client.request(
148
+ "POST",
149
+ "/api/v1/vendor/toggle-status",
150
+ json={"vendorId": vendor_id},
151
+ )
152
+ return self._handle_response(response)