|
| 1 | +from typing import Optional, Dict |
| 2 | + |
| 3 | +from extend.client import APIClient |
| 4 | +from .resource import Resource |
| 5 | + |
| 6 | + |
| 7 | +class ExpenseData(Resource): |
| 8 | + @property |
| 9 | + def _base_url(self) -> str: |
| 10 | + return "/expensedata" |
| 11 | + |
| 12 | + def __init__(self, api_client: APIClient): |
| 13 | + super().__init__(api_client) |
| 14 | + |
| 15 | + async def get_expense_categories( |
| 16 | + self, |
| 17 | + active: Optional[bool] = None, |
| 18 | + required: Optional[bool] = None, |
| 19 | + search: Optional[str] = None, |
| 20 | + sort_field: Optional[str] = None, |
| 21 | + sort_direction: Optional[str] = None, |
| 22 | + ) -> Dict: |
| 23 | + """Get a list of expense categories. |
| 24 | +
|
| 25 | + Args: |
| 26 | + active (Optional[bool]): Show only active categories |
| 27 | + required (Optional[bool]): Show only required categories |
| 28 | + search (Optional[str]): Full-text search query for filtering categories |
| 29 | + sort_field (Optional[str]): Field to sort by |
| 30 | + sort_direction (Optional[str]): Direction of sorting ("asc" or "desc") |
| 31 | +
|
| 32 | + Returns: |
| 33 | + Dict: A dictionary containing: |
| 34 | + - expenseCategories: List of Expense Category objects |
| 35 | +
|
| 36 | + Raises: |
| 37 | + httpx.HTTPError: If the request fails |
| 38 | + """ |
| 39 | + |
| 40 | + params = { |
| 41 | + "active": active, |
| 42 | + "required": required, |
| 43 | + "search": search, |
| 44 | + "sortField": sort_field, |
| 45 | + "sortDirection": sort_direction, |
| 46 | + } |
| 47 | + |
| 48 | + return await self._request(method="get", path=f"/categories", params=params) |
| 49 | + |
| 50 | + async def get_expense_category(self, category_id: str) -> Dict: |
| 51 | + """Get detailed information about a specific expense category. |
| 52 | +
|
| 53 | + Args: |
| 54 | + category_id (str): The unique identifier of the expense category |
| 55 | +
|
| 56 | + Returns: |
| 57 | + Dict: A dictionary containing the expense category details |
| 58 | +
|
| 59 | + Raises: |
| 60 | + httpx.HTTPError: If the request fails or transaction not found |
| 61 | + """ |
| 62 | + return await self._request(method="get", path=f"/categories/{category_id}") |
| 63 | + |
| 64 | + async def get_expense_category_labels( |
| 65 | + self, |
| 66 | + category_id: str, |
| 67 | + page: Optional[int] = None, |
| 68 | + per_page: Optional[int] = None, |
| 69 | + active: Optional[bool] = None, |
| 70 | + search: Optional[str] = None, |
| 71 | + sort_field: Optional[str] = None, |
| 72 | + sort_direction: Optional[str] = None, |
| 73 | + ) -> Dict: |
| 74 | + """Get a paginated list of expense categories. |
| 75 | +
|
| 76 | + Args: |
| 77 | + category_id (str): The unique identifier of the expense category |
| 78 | + page (Optional[int]): The page number for pagination (1-based) |
| 79 | + per_page (Optional[int]): Number of items per page |
| 80 | + active (Optional[bool]): Show only active labels |
| 81 | + search (Optional[str]): Full-text search query |
| 82 | + sort_field (Optional[str]): Field to sort by (e.g., activeLabelNameAsc, name) |
| 83 | + sort_direction (Optional[str]): Sort direction (asc, desc) for sortable fields |
| 84 | +
|
| 85 | + Returns: |
| 86 | + Dict: A dictionary containing: |
| 87 | + - expenseLabels: List of Expense Category Label objects |
| 88 | + - pagination: Dictionary containing the following pagination stats: |
| 89 | + - page: Current page number |
| 90 | + - pageItemCount: Number of items per page |
| 91 | + - totalItems: Total number expense category labels across all pages |
| 92 | + - numberOfPages: Total number of pages |
| 93 | +
|
| 94 | + Raises: |
| 95 | + httpx.HTTPError: If the request fails |
| 96 | + """ |
| 97 | + |
| 98 | + params = { |
| 99 | + "page": page, |
| 100 | + "count": per_page, |
| 101 | + "active": active, |
| 102 | + "search": search, |
| 103 | + "sortField": sort_field, |
| 104 | + "sortDirection": sort_direction, |
| 105 | + } |
| 106 | + |
| 107 | + return await self._request(method="get", path=f"/categories/{category_id}/labels", params=params) |
| 108 | + |
| 109 | + async def create_expense_category( |
| 110 | + self, |
| 111 | + name: str, |
| 112 | + code: str, |
| 113 | + required: bool, |
| 114 | + active: Optional[bool] = None, |
| 115 | + free_text_allowed: Optional[bool] = None, |
| 116 | + integrator_enabled: Optional[bool] = None, |
| 117 | + integrator_field_number: Optional[int] = None, |
| 118 | + ) -> Dict: |
| 119 | + """Create an expense category. |
| 120 | +
|
| 121 | + Args: |
| 122 | + name (str): User-facing name for this expense category |
| 123 | + code (str): Code for the expense category |
| 124 | + required (bool): Whether this field is required for all users |
| 125 | + active (Optional[bool]): Whether this category is active and available for input |
| 126 | + free_text_allowed (Optional[bool]): Whether free text input is allowed |
| 127 | + integrator_enabled (Optional[bool]): Whether this category is integrator enabled |
| 128 | + integrator_field_number (Optional[int]): Field number used by the integrator |
| 129 | +
|
| 130 | + Returns: |
| 131 | + Dict: A dictionary containing the newly created expense category |
| 132 | +
|
| 133 | + Raises: |
| 134 | + httpx.HTTPError: If the request fails or the transaction is not found |
| 135 | + """ |
| 136 | + |
| 137 | + payload = { |
| 138 | + "name": name, |
| 139 | + "code": code, |
| 140 | + "required": required, |
| 141 | + "active": active, |
| 142 | + "freeTextAllowed": free_text_allowed, |
| 143 | + "integratorEnabled": integrator_enabled, |
| 144 | + "integratorFieldNumber": integrator_field_number, |
| 145 | + } |
| 146 | + |
| 147 | + return await self._request( |
| 148 | + method="post", |
| 149 | + params=payload |
| 150 | + ) |
| 151 | + |
| 152 | + async def create_expense_category_label( |
| 153 | + self, |
| 154 | + category_id: str, |
| 155 | + name: str, |
| 156 | + code: str, |
| 157 | + active: bool = True |
| 158 | + ) -> Dict: |
| 159 | + """Create an expense category. |
| 160 | +
|
| 161 | + Args: |
| 162 | + category_id (str): The unique identifier of the expense category |
| 163 | + name (str): User-facing name for this expense category label |
| 164 | + code (str): Code for the expense category label |
| 165 | + active (bool): Whether the label is active and available for input |
| 166 | +
|
| 167 | + Returns: |
| 168 | + Dict: A dictionary containing the newly created expense category label |
| 169 | +
|
| 170 | + Raises: |
| 171 | + httpx.HTTPError: If the request fails or the transaction is not found |
| 172 | + """ |
| 173 | + payload = { |
| 174 | + "name": name, |
| 175 | + "code": code, |
| 176 | + "active": active, |
| 177 | + } |
| 178 | + |
| 179 | + return await self._request( |
| 180 | + method="post", |
| 181 | + path=f"/{category_id}", |
| 182 | + params=payload |
| 183 | + ) |
| 184 | + |
| 185 | + async def update_expense_category( |
| 186 | + self, |
| 187 | + category_id: str, |
| 188 | + name: Optional[str] = None, |
| 189 | + active: Optional[bool] = None, |
| 190 | + required: Optional[bool] = None, |
| 191 | + free_text_allowed: Optional[bool] = None, |
| 192 | + integrator_enabled: Optional[bool] = None, |
| 193 | + integrator_field_number: Optional[int] = None, |
| 194 | + ) -> Dict: |
| 195 | + """Update the an expense category. |
| 196 | +
|
| 197 | + Args: |
| 198 | + category_id (str): The unique identifier of the expense category |
| 199 | + name (Optional[str]): User-facing name for this expense category |
| 200 | + active (Optional[bool]): Whether the category is active |
| 201 | + required (Optional[bool]): Whether this field is required for all users |
| 202 | + free_text_allowed (Optional[bool]): Whether free text input is allowed |
| 203 | + integrator_enabled (Optional[bool]): Whether this category is integrator enabled |
| 204 | + integrator_field_number (Optional[int]): Field number used by the integrator |
| 205 | +
|
| 206 | + Returns: |
| 207 | + Dict: A dictionary containing the updated expense category details |
| 208 | +
|
| 209 | + Raises: |
| 210 | + httpx.HTTPError: If the request fails or the transaction is not found |
| 211 | + """ |
| 212 | + |
| 213 | + payload = { |
| 214 | + "name": name, |
| 215 | + "active": active, |
| 216 | + "required": required, |
| 217 | + "freeTextAllowed": free_text_allowed, |
| 218 | + "integratorEnabled": integrator_enabled, |
| 219 | + "integratorFieldNumber": integrator_field_number, |
| 220 | + } |
| 221 | + |
| 222 | + return await self._request( |
| 223 | + method="patch", |
| 224 | + path=f"/{category_id}", |
| 225 | + params=payload |
| 226 | + ) |
| 227 | + |
| 228 | + async def update_expense_category_label( |
| 229 | + self, |
| 230 | + category_id: str, |
| 231 | + label_id: str, |
| 232 | + name: Optional[str] = None, |
| 233 | + active: Optional[bool] = None, |
| 234 | + ) -> Dict: |
| 235 | + """Update an expense category label. |
| 236 | +
|
| 237 | + Args: |
| 238 | + category_id (str): The unique identifier of the expense category |
| 239 | + label_id (str): The unique identifier of the expense category label to update |
| 240 | + name (Optional[str]): User-facing name for the expense label |
| 241 | + active (Optional[bool]): Whether the label is active and available for input |
| 242 | +
|
| 243 | + Returns: |
| 244 | + Dict: A dictionary containing the updated expense category details |
| 245 | +
|
| 246 | + Raises: |
| 247 | + httpx.HTTPError: If the request fails or the transaction is not found |
| 248 | + """ |
| 249 | + |
| 250 | + payload = { |
| 251 | + "name": name, |
| 252 | + "active": active, |
| 253 | + } |
| 254 | + |
| 255 | + return await self._request( |
| 256 | + method="patch", |
| 257 | + path=f"/{category_id}/labels/{label_id}", |
| 258 | + params=payload |
| 259 | + ) |
0 commit comments