Pyiiko 0.4.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.
Pyiiko/_web_docs.py ADDED
@@ -0,0 +1,534 @@
1
+ """Document-processing mixin for IikoWeb — keeps iiko_web.py under 400 lines."""
2
+ from __future__ import annotations
3
+
4
+ from typing import TYPE_CHECKING, Any
5
+
6
+ if TYPE_CHECKING:
7
+ import requests
8
+
9
+
10
+ class _DocsMixin:
11
+ """Mixin providing all document-processing endpoints for IikoWeb."""
12
+
13
+ if TYPE_CHECKING:
14
+ def _post(self, path: str, **kwargs: Any) -> requests.Response: ...
15
+
16
+ def _auth(self) -> dict[str, str]: # satisfied by IikoWeb
17
+ raise NotImplementedError
18
+
19
+ # ------------------------------------------------------------------
20
+ # Counteragents
21
+ # ------------------------------------------------------------------
22
+
23
+ def counteragents(
24
+ self,
25
+ department_id: Any = None,
26
+ type: Any = None,
27
+ limit: int | None = None,
28
+ offset: int | None = None,
29
+ ) -> Any:
30
+ """Return the list of counteragents.
31
+
32
+ :param department_id: Department identifier (optional).
33
+ :param type: Counteragent type filter (optional).
34
+ :param limit: Maximum number of records to return (optional).
35
+ :param offset: Number of records to skip (optional).
36
+ """
37
+ body = {
38
+ k: v
39
+ for k, v in {
40
+ "departmentId": department_id,
41
+ "type": type,
42
+ "limit": limit,
43
+ "offset": offset,
44
+ }.items()
45
+ if v is not None
46
+ }
47
+ return self._post(
48
+ "document-processing/counteragents",
49
+ headers=self._auth(),
50
+ json=body,
51
+ )
52
+
53
+ # ------------------------------------------------------------------
54
+ # Incoming invoice
55
+ # ------------------------------------------------------------------
56
+
57
+ def incoming_invoice_create(self, payload: dict) -> Any:
58
+ """Create an incoming invoice document.
59
+
60
+ :param payload: Incoming invoice creation payload.
61
+ """
62
+ return self._post(
63
+ "document-processing/incoming-invoice/create",
64
+ headers=self._auth(),
65
+ json=payload,
66
+ )
67
+
68
+ def incoming_invoice_export(
69
+ self,
70
+ department_id: Any,
71
+ date_from: str,
72
+ date_to: str,
73
+ supplier_id: Any = None,
74
+ revision_from: Any = None,
75
+ ) -> Any:
76
+ """Export incoming invoices filtered by department and date range.
77
+
78
+ :param department_id: Department identifier.
79
+ :param date_from: Start date (ISO string).
80
+ :param date_to: End date (ISO string).
81
+ :param supplier_id: Supplier identifier (optional).
82
+ :param revision_from: Starting revision number (optional).
83
+ """
84
+ body = {
85
+ k: v
86
+ for k, v in {
87
+ "departmentId": department_id,
88
+ "dateFrom": date_from,
89
+ "dateTo": date_to,
90
+ "supplierId": supplier_id,
91
+ "revisionFrom": revision_from,
92
+ }.items()
93
+ if v is not None
94
+ }
95
+ return self._post(
96
+ "document-processing/incoming-invoice/export",
97
+ headers=self._auth(),
98
+ json=body,
99
+ )
100
+
101
+ def incoming_invoice_export_by_number(self, payload: dict) -> Any:
102
+ """Export an incoming invoice by document number.
103
+
104
+ :param payload: Query payload containing document number.
105
+ """
106
+ return self._post(
107
+ "document-processing/incoming-invoice/export/by-number",
108
+ headers=self._auth(),
109
+ json=payload,
110
+ )
111
+
112
+ def incoming_invoice_pay(self, payload: dict) -> Any:
113
+ """Mark an incoming invoice as paid.
114
+
115
+ :param payload: Payment payload.
116
+ """
117
+ return self._post(
118
+ "document-processing/incoming-invoice/pay",
119
+ headers=self._auth(),
120
+ json=payload,
121
+ )
122
+
123
+ def incoming_invoice_set_payment_date(self, payload: dict) -> Any:
124
+ """Set the payment date on an incoming invoice.
125
+
126
+ :param payload: Payload containing invoice ID and payment date.
127
+ """
128
+ return self._post(
129
+ "document-processing/incoming-invoice/set-payment-date",
130
+ headers=self._auth(),
131
+ json=payload,
132
+ )
133
+
134
+ def incoming_invoice_update(self, payload: dict) -> Any:
135
+ """Update an existing incoming invoice.
136
+
137
+ :param payload: Updated invoice data.
138
+ """
139
+ return self._post(
140
+ "document-processing/incoming-invoice/update",
141
+ headers=self._auth(),
142
+ json=payload,
143
+ )
144
+
145
+ # ------------------------------------------------------------------
146
+ # Incoming service
147
+ # ------------------------------------------------------------------
148
+
149
+ def incoming_service_create(self, payload: dict) -> Any:
150
+ """Create an incoming service document.
151
+
152
+ :param payload: Incoming service creation payload.
153
+ """
154
+ return self._post(
155
+ "document-processing/incoming-service/create-document",
156
+ headers=self._auth(),
157
+ json=payload,
158
+ )
159
+
160
+ def incoming_service_edit(self, payload: dict) -> Any:
161
+ """Edit an existing incoming service document.
162
+
163
+ :param payload: Updated incoming service data.
164
+ """
165
+ return self._post(
166
+ "document-processing/incoming-service/edit-document",
167
+ headers=self._auth(),
168
+ json=payload,
169
+ )
170
+
171
+ def incoming_service_export(self, payload: dict) -> Any:
172
+ """Export incoming service documents.
173
+
174
+ :param payload: Export filter payload.
175
+ """
176
+ return self._post(
177
+ "document-processing/incoming-service/export",
178
+ headers=self._auth(),
179
+ json=payload,
180
+ )
181
+
182
+ def incoming_service_get(self, payload: dict) -> Any:
183
+ """Retrieve a single incoming service document.
184
+
185
+ :param payload: Query payload.
186
+ """
187
+ return self._post(
188
+ "document-processing/incoming-service/get-document",
189
+ headers=self._auth(),
190
+ json=payload,
191
+ )
192
+
193
+ # ------------------------------------------------------------------
194
+ # Internal transfer
195
+ # ------------------------------------------------------------------
196
+
197
+ def internal_transfer_create(self, payload: dict) -> Any:
198
+ """Create an internal transfer document.
199
+
200
+ :param payload: Internal transfer creation payload.
201
+ """
202
+ return self._post(
203
+ "document-processing/internal-transfer/create",
204
+ headers=self._auth(),
205
+ json=payload,
206
+ )
207
+
208
+ def internal_transfer_edit(self, payload: dict) -> Any:
209
+ """Edit an existing internal transfer document.
210
+
211
+ :param payload: Updated internal transfer data.
212
+ """
213
+ return self._post(
214
+ "document-processing/internal-transfer/edit",
215
+ headers=self._auth(),
216
+ json=payload,
217
+ )
218
+
219
+ def internal_transfer_export(self, payload: dict) -> Any:
220
+ """Export internal transfer documents.
221
+
222
+ :param payload: Export filter payload.
223
+ """
224
+ return self._post(
225
+ "document-processing/internal-transfer/export",
226
+ headers=self._auth(),
227
+ json=payload,
228
+ )
229
+
230
+ def internal_transfer_get_by_id(self, payload: dict) -> Any:
231
+ """Retrieve an internal transfer document by ID.
232
+
233
+ :param payload: Query payload containing document ID.
234
+ """
235
+ return self._post(
236
+ "document-processing/internal-transfer/export/by-id",
237
+ headers=self._auth(),
238
+ json=payload,
239
+ )
240
+
241
+ def internal_transfer_export_by_number(self, payload: dict) -> Any:
242
+ """Export an internal transfer document by document number.
243
+
244
+ :param payload: Query payload containing document number.
245
+ """
246
+ return self._post(
247
+ "document-processing/internal-transfer/export/by-number",
248
+ headers=self._auth(),
249
+ json=payload,
250
+ )
251
+
252
+ # ------------------------------------------------------------------
253
+ # Outgoing invoice
254
+ # ------------------------------------------------------------------
255
+
256
+ def outgoing_invoice_create(self, payload: dict) -> Any:
257
+ """Create an outgoing invoice document.
258
+
259
+ :param payload: Outgoing invoice creation payload.
260
+ """
261
+ return self._post(
262
+ "document-processing/outgoing-invoice/create",
263
+ headers=self._auth(),
264
+ json=payload,
265
+ )
266
+
267
+ def outgoing_invoice_export(self, payload: dict) -> Any:
268
+ """Export outgoing invoice documents.
269
+
270
+ :param payload: Export filter payload.
271
+ """
272
+ return self._post(
273
+ "document-processing/outgoing-invoice/export",
274
+ headers=self._auth(),
275
+ json=payload,
276
+ )
277
+
278
+ def outgoing_invoice_export_by_number(self, payload: dict) -> Any:
279
+ """Export an outgoing invoice by document number.
280
+
281
+ :param payload: Query payload containing document number.
282
+ """
283
+ return self._post(
284
+ "document-processing/outgoing-invoice/export/by-number",
285
+ headers=self._auth(),
286
+ json=payload,
287
+ )
288
+
289
+ def outgoing_invoice_cost_prices(self, payload: dict) -> Any:
290
+ """Retrieve cost prices for an outgoing invoice.
291
+
292
+ :param payload: Query payload.
293
+ """
294
+ return self._post(
295
+ "document-processing/outgoing-invoice/get-cost-prices",
296
+ headers=self._auth(),
297
+ json=payload,
298
+ )
299
+
300
+ def outgoing_invoice_pay(self, payload: dict) -> Any:
301
+ """Mark an outgoing invoice as paid.
302
+
303
+ :param payload: Payment payload.
304
+ """
305
+ return self._post(
306
+ "document-processing/outgoing-invoice/pay",
307
+ headers=self._auth(),
308
+ json=payload,
309
+ )
310
+
311
+ def outgoing_invoice_set_payment_date(self, payload: dict) -> Any:
312
+ """Set the payment date on an outgoing invoice.
313
+
314
+ :param payload: Payload containing invoice ID and payment date.
315
+ """
316
+ return self._post(
317
+ "document-processing/outgoing-invoice/set-payment-date",
318
+ headers=self._auth(),
319
+ json=payload,
320
+ )
321
+
322
+ def outgoing_invoice_update(self, payload: dict) -> Any:
323
+ """Update an existing outgoing invoice.
324
+
325
+ :param payload: Updated invoice data.
326
+ """
327
+ return self._post(
328
+ "document-processing/outgoing-invoice/update",
329
+ headers=self._auth(),
330
+ json=payload,
331
+ )
332
+
333
+ # ------------------------------------------------------------------
334
+ # Outgoing service
335
+ # ------------------------------------------------------------------
336
+
337
+ def outgoing_service_create(self, payload: dict) -> Any:
338
+ """Create an outgoing service document.
339
+
340
+ :param payload: Outgoing service creation payload.
341
+ """
342
+ return self._post(
343
+ "document-processing/outgoing-service/create-document",
344
+ headers=self._auth(),
345
+ json=payload,
346
+ )
347
+
348
+ def outgoing_service_edit(self, payload: dict) -> Any:
349
+ """Edit an existing outgoing service document.
350
+
351
+ :param payload: Updated outgoing service data.
352
+ """
353
+ return self._post(
354
+ "document-processing/outgoing-service/edit-document",
355
+ headers=self._auth(),
356
+ json=payload,
357
+ )
358
+
359
+ def outgoing_service_export(self, payload: dict) -> Any:
360
+ """Export outgoing service documents.
361
+
362
+ :param payload: Export filter payload.
363
+ """
364
+ return self._post(
365
+ "document-processing/outgoing-service/export",
366
+ headers=self._auth(),
367
+ json=payload,
368
+ )
369
+
370
+ def outgoing_service_get(self, payload: dict) -> Any:
371
+ """Retrieve a single outgoing service document.
372
+
373
+ :param payload: Query payload.
374
+ """
375
+ return self._post(
376
+ "document-processing/outgoing-service/get-document",
377
+ headers=self._auth(),
378
+ json=payload,
379
+ )
380
+
381
+ # ------------------------------------------------------------------
382
+ # Production document
383
+ # ------------------------------------------------------------------
384
+
385
+ def production_doc_create(self, payload: dict) -> Any:
386
+ """Create a production document.
387
+
388
+ :param payload: Production document creation payload.
389
+ """
390
+ return self._post(
391
+ "document-processing/production-document/create-document",
392
+ headers=self._auth(),
393
+ json=payload,
394
+ )
395
+
396
+ def production_doc_edit(self, payload: dict) -> Any:
397
+ """Edit an existing production document.
398
+
399
+ :param payload: Updated production document data.
400
+ """
401
+ return self._post(
402
+ "document-processing/production-document/edit-document",
403
+ headers=self._auth(),
404
+ json=payload,
405
+ )
406
+
407
+ def production_doc_export(self, payload: dict) -> Any:
408
+ """Export production documents.
409
+
410
+ :param payload: Export filter payload.
411
+ """
412
+ return self._post(
413
+ "document-processing/production-document/export",
414
+ headers=self._auth(),
415
+ json=payload,
416
+ )
417
+
418
+ def production_doc_get(self, payload: dict) -> Any:
419
+ """Retrieve a single production document.
420
+
421
+ :param payload: Query payload.
422
+ """
423
+ return self._post(
424
+ "document-processing/production-document/get-document",
425
+ headers=self._auth(),
426
+ json=payload,
427
+ )
428
+
429
+ # ------------------------------------------------------------------
430
+ # Sales document
431
+ # ------------------------------------------------------------------
432
+
433
+ def sales_doc_create(self, payload: dict) -> Any:
434
+ """Create a sales document.
435
+
436
+ :param payload: Sales document creation payload.
437
+ """
438
+ return self._post(
439
+ "document-processing/sales-document/create-document",
440
+ headers=self._auth(),
441
+ json=payload,
442
+ )
443
+
444
+ def sales_doc_edit(self, payload: dict) -> Any:
445
+ """Edit an existing sales document.
446
+
447
+ :param payload: Updated sales document data.
448
+ """
449
+ return self._post(
450
+ "document-processing/sales-document/edit-document",
451
+ headers=self._auth(),
452
+ json=payload,
453
+ )
454
+
455
+ def sales_doc_export(self, payload: dict) -> Any:
456
+ """Export sales documents.
457
+
458
+ :param payload: Export filter payload.
459
+ """
460
+ return self._post(
461
+ "document-processing/sales-document/export",
462
+ headers=self._auth(),
463
+ json=payload,
464
+ )
465
+
466
+ def sales_doc_get(self, payload: dict) -> Any:
467
+ """Retrieve a single sales document.
468
+
469
+ :param payload: Query payload.
470
+ """
471
+ return self._post(
472
+ "document-processing/sales-document/get-document",
473
+ headers=self._auth(),
474
+ json=payload,
475
+ )
476
+
477
+ # ------------------------------------------------------------------
478
+ # Writeoff document
479
+ # ------------------------------------------------------------------
480
+
481
+ def writeoff_create(self, payload: dict) -> Any:
482
+ """Create a writeoff document.
483
+
484
+ :param payload: Writeoff document creation payload.
485
+ """
486
+ return self._post(
487
+ "document-processing/writeoff-document/create",
488
+ headers=self._auth(),
489
+ json=payload,
490
+ )
491
+
492
+ def writeoff_edit(self, payload: dict) -> Any:
493
+ """Edit an existing writeoff document.
494
+
495
+ :param payload: Updated writeoff document data.
496
+ """
497
+ return self._post(
498
+ "document-processing/writeoff-document/edit",
499
+ headers=self._auth(),
500
+ json=payload,
501
+ )
502
+
503
+ def writeoff_export(self, payload: dict) -> Any:
504
+ """Export writeoff documents.
505
+
506
+ :param payload: Export filter payload.
507
+ """
508
+ return self._post(
509
+ "document-processing/writeoff-document/export",
510
+ headers=self._auth(),
511
+ json=payload,
512
+ )
513
+
514
+ def writeoff_get_by_id(self, payload: dict) -> Any:
515
+ """Retrieve a writeoff document by ID.
516
+
517
+ :param payload: Query payload containing document ID.
518
+ """
519
+ return self._post(
520
+ "document-processing/writeoff-document/export/by-id",
521
+ headers=self._auth(),
522
+ json=payload,
523
+ )
524
+
525
+ def writeoff_export_by_number(self, payload: dict) -> Any:
526
+ """Export a writeoff document by document number.
527
+
528
+ :param payload: Query payload containing document number.
529
+ """
530
+ return self._post(
531
+ "document-processing/writeoff-document/export/by-number",
532
+ headers=self._auth(),
533
+ json=payload,
534
+ )
Pyiiko/exceptions.py ADDED
@@ -0,0 +1,18 @@
1
+ """Custom exceptions for pyiiko."""
2
+ from __future__ import annotations
3
+
4
+
5
+ class IikoError(Exception):
6
+ """Base exception for all pyiiko errors."""
7
+
8
+
9
+ class IikoAuthError(IikoError):
10
+ """Raised when authentication fails (bad credentials, expired token)."""
11
+
12
+
13
+ class IikoAPIError(IikoError):
14
+ """Raised when the server returns an HTTP error response."""
15
+
16
+ def __init__(self, message: str, status_code: int | None = None) -> None:
17
+ super().__init__(message)
18
+ self.status_code = status_code