Pyiiko 0.2.16__tar.gz → 0.4.0__tar.gz
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-0.4.0/LICENSE +201 -0
- pyiiko-0.4.0/PKG-INFO +344 -0
- pyiiko-0.4.0/Pyiiko/__init__.py +15 -0
- pyiiko-0.4.0/Pyiiko/_base.py +83 -0
- pyiiko-0.4.0/Pyiiko/_server_nomenclature.py +288 -0
- pyiiko-0.4.0/Pyiiko/_web_docs.py +534 -0
- pyiiko-0.4.0/Pyiiko/exceptions.py +18 -0
- pyiiko-0.4.0/Pyiiko/iiko_web.py +392 -0
- pyiiko-0.4.0/Pyiiko/py.typed +0 -0
- pyiiko-0.4.0/Pyiiko/server.py +637 -0
- pyiiko-0.4.0/Pyiiko/transport.py +203 -0
- pyiiko-0.4.0/Pyiiko.egg-info/PKG-INFO +344 -0
- {Pyiiko-0.2.16 → pyiiko-0.4.0}/Pyiiko.egg-info/SOURCES.txt +11 -10
- pyiiko-0.4.0/Pyiiko.egg-info/requires.txt +12 -0
- {Pyiiko-0.2.16 → pyiiko-0.4.0}/Pyiiko.egg-info/top_level.txt +0 -1
- pyiiko-0.4.0/README.md +308 -0
- pyiiko-0.4.0/pyproject.toml +90 -0
- pyiiko-0.4.0/tests/test_iiko_web.py +862 -0
- pyiiko-0.4.0/tests/test_server.py +927 -0
- pyiiko-0.4.0/tests/test_transport.py +276 -0
- Pyiiko-0.2.16/PKG-INFO +0 -10
- Pyiiko-0.2.16/Pyiiko/__init__.py +0 -6
- Pyiiko-0.2.16/Pyiiko/biz.py +0 -366
- Pyiiko-0.2.16/Pyiiko/card5.py +0 -457
- Pyiiko-0.2.16/Pyiiko/frontWeb.py +0 -281
- Pyiiko-0.2.16/Pyiiko/server.py +0 -922
- Pyiiko-0.2.16/Pyiiko/settings.py +0 -7
- Pyiiko-0.2.16/Pyiiko/transport.py +0 -145
- Pyiiko-0.2.16/Pyiiko/webAPI.py +0 -5
- Pyiiko-0.2.16/Pyiiko.egg-info/PKG-INFO +0 -10
- Pyiiko-0.2.16/Pyiiko.egg-info/requires.txt +0 -2
- Pyiiko-0.2.16/README.md +0 -25
- Pyiiko-0.2.16/setup.py +0 -20
- Pyiiko-0.2.16/test/__init__.py +0 -1
- Pyiiko-0.2.16/test/test.py +0 -10
- Pyiiko-0.2.16/test/test_server.py +0 -42
- Pyiiko-0.2.16/test/test_transport.py +0 -51
- {Pyiiko-0.2.16 → pyiiko-0.4.0}/Pyiiko.egg-info/dependency_links.txt +0 -0
- {Pyiiko-0.2.16 → pyiiko-0.4.0}/setup.cfg +0 -0
pyiiko-0.4.0/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright 2018 Gadzhibala Pirmagomedov
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
pyiiko-0.4.0/PKG-INFO
ADDED
|
@@ -0,0 +1,344 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: Pyiiko
|
|
3
|
+
Version: 0.4.0
|
|
4
|
+
Summary: Python library for iiko ERP API
|
|
5
|
+
Author-email: Gadzhibala Pirmagomedov <gadzhibala@protonmail.com>
|
|
6
|
+
License-Expression: Apache-2.0
|
|
7
|
+
Project-URL: Homepage, https://github.com/gadzhi/pyiiko
|
|
8
|
+
Project-URL: Repository, https://github.com/gadzhi/pyiiko
|
|
9
|
+
Project-URL: Issues, https://github.com/gadzhi/pyiiko/issues
|
|
10
|
+
Project-URL: Changelog, https://github.com/gadzhi/pyiiko/blob/master/CHANGELOG.md
|
|
11
|
+
Keywords: iiko,restaurant,erp,api,horeca
|
|
12
|
+
Classifier: Development Status :: 4 - Beta
|
|
13
|
+
Classifier: Intended Audience :: Developers
|
|
14
|
+
Classifier: Programming Language :: Python :: 3
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
19
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
20
|
+
Classifier: Typing :: Typed
|
|
21
|
+
Requires-Python: >=3.9
|
|
22
|
+
Description-Content-Type: text/markdown
|
|
23
|
+
License-File: LICENSE
|
|
24
|
+
Requires-Dist: requests>=2.28.0
|
|
25
|
+
Requires-Dist: lxml>=4.9.0
|
|
26
|
+
Requires-Dist: urllib3>=1.26.0
|
|
27
|
+
Provides-Extra: dev
|
|
28
|
+
Requires-Dist: pytest>=7.4; extra == "dev"
|
|
29
|
+
Requires-Dist: pytest-cov>=4.1; extra == "dev"
|
|
30
|
+
Requires-Dist: responses>=0.23.0; extra == "dev"
|
|
31
|
+
Requires-Dist: ruff>=0.4.0; extra == "dev"
|
|
32
|
+
Requires-Dist: mypy>=1.9; extra == "dev"
|
|
33
|
+
Requires-Dist: types-requests>=2.31; extra == "dev"
|
|
34
|
+
Requires-Dist: lxml-stubs>=0.5; extra == "dev"
|
|
35
|
+
Dynamic: license-file
|
|
36
|
+
|
|
37
|
+
<p align="center">
|
|
38
|
+
<img src="https://habrastorage.org/webt/bi/od/mp/biodmpylxpnkxhjtewsjro_-8ps.jpeg" height="160" alt="pyiiko">
|
|
39
|
+
</p>
|
|
40
|
+
|
|
41
|
+
<h1 align="center">pyiiko</h1>
|
|
42
|
+
|
|
43
|
+
<p align="center">Python-библиотека для работы с API iiko ERP</p>
|
|
44
|
+
|
|
45
|
+
<p align="center">
|
|
46
|
+
<a href="https://pypi.org/project/Pyiiko/"><img src="https://img.shields.io/pypi/v/Pyiiko?color=blue" alt="PyPI version"></a>
|
|
47
|
+
<a href="https://pypi.org/project/Pyiiko/"><img src="https://img.shields.io/pypi/pyversions/Pyiiko" alt="Python versions"></a>
|
|
48
|
+
<a href="https://pypi.org/project/Pyiiko/"><img src="https://img.shields.io/pypi/dm/Pyiiko?color=green" alt="PyPI downloads"></a>
|
|
49
|
+
<a href="https://www.apache.org/licenses/LICENSE-2.0"><img src="https://img.shields.io/pypi/l/Pyiiko" alt="License: Apache 2.0"></a>
|
|
50
|
+
</p>
|
|
51
|
+
|
|
52
|
+
---
|
|
53
|
+
|
|
54
|
+
## Возможности
|
|
55
|
+
|
|
56
|
+
- **iiko Server API** — on-premise установки (складской учёт, номенклатура, отчёты OLAP, сотрудники, накладные, EDI)
|
|
57
|
+
- **iiko Transport API** — облачный API (организации, терминалы, доставки, города, улицы)
|
|
58
|
+
- **iiko Public Web API** — облачный API нового поколения (документооборот, номенклатура, закупки)
|
|
59
|
+
- Автоматический retry на 5xx ошибки (3 попытки с backoff)
|
|
60
|
+
- Единая иерархия исключений: `IikoError` → `IikoAuthError` / `IikoAPIError`
|
|
61
|
+
- Context manager для автоматического освобождения ресурсов
|
|
62
|
+
- Type hints, PEP 561 `py.typed`
|
|
63
|
+
|
|
64
|
+
## Установка
|
|
65
|
+
|
|
66
|
+
```bash
|
|
67
|
+
pip install Pyiiko
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
**Требования:** Python 3.9+
|
|
71
|
+
|
|
72
|
+
## Быстрый старт
|
|
73
|
+
|
|
74
|
+
### iiko Server (on-premise)
|
|
75
|
+
|
|
76
|
+
```python
|
|
77
|
+
from Pyiiko import IikoServer
|
|
78
|
+
|
|
79
|
+
# Пароль передаётся в виде SHA1-хеша
|
|
80
|
+
server = IikoServer(
|
|
81
|
+
ip="https://your-server.example.com:443",
|
|
82
|
+
login="login",
|
|
83
|
+
password="da39a3ee5e6b4b0d3255bfef95601890afd80709",
|
|
84
|
+
)
|
|
85
|
+
|
|
86
|
+
print(server.version()) # "7.8.9"
|
|
87
|
+
print(server.departments()) # XML с иерархией подразделений
|
|
88
|
+
print(server.products()) # XML с номенклатурой
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
Использование как context manager освобождает токен (лицензионный слот) автоматически:
|
|
92
|
+
|
|
93
|
+
```python
|
|
94
|
+
with IikoServer(ip="...", login="...", password="...") as server:
|
|
95
|
+
stores = server.stores()
|
|
96
|
+
employees = server.employees()
|
|
97
|
+
# токен уничтожен, лицензия освобождена
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
Если токен уже получен — передайте его напрямую, чтобы не делать лишний запрос:
|
|
101
|
+
|
|
102
|
+
```python
|
|
103
|
+
server = IikoServer(ip="https://...", token="your-existing-token")
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
### iiko Public Web API
|
|
107
|
+
|
|
108
|
+
```python
|
|
109
|
+
from Pyiiko import IikoWeb
|
|
110
|
+
|
|
111
|
+
client = IikoWeb(api_key="your-api-key")
|
|
112
|
+
|
|
113
|
+
# Список складов
|
|
114
|
+
stores = client.stores()
|
|
115
|
+
|
|
116
|
+
# Список продуктов с пагинацией
|
|
117
|
+
products = client.products(limit=100, offset=0)
|
|
118
|
+
|
|
119
|
+
# Экспорт приходных накладных
|
|
120
|
+
invoices = client.incoming_invoice_export(
|
|
121
|
+
department_id="dept-guid-...",
|
|
122
|
+
date_from="2024-01-01",
|
|
123
|
+
date_to="2024-01-31",
|
|
124
|
+
)
|
|
125
|
+
|
|
126
|
+
# Список заказов на закупку
|
|
127
|
+
orders = client.orders_list({"storeId": 1, "limit": 50})
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
Передайте уже полученный токен, чтобы пропустить авторизацию:
|
|
131
|
+
|
|
132
|
+
```python
|
|
133
|
+
client = IikoWeb(token={"token": "eyJ...", "expires_in": 9999999999})
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
### iiko Transport (Cloud)
|
|
137
|
+
|
|
138
|
+
```python
|
|
139
|
+
from Pyiiko import Transport
|
|
140
|
+
|
|
141
|
+
client = Transport(key="your-api-login-key")
|
|
142
|
+
|
|
143
|
+
orgs = client.organization()
|
|
144
|
+
terminals = client.terminal(org_id="org-guid-...")
|
|
145
|
+
cities = client.cities(org_id="org-guid-...")
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
Создание доставки:
|
|
149
|
+
|
|
150
|
+
```python
|
|
151
|
+
order = {
|
|
152
|
+
"organizationId": "org-guid-...",
|
|
153
|
+
"order": {
|
|
154
|
+
"phone": "+79001234567",
|
|
155
|
+
"deliveryPoint": {"coordinates": {"latitude": 55.75, "longitude": 37.61}},
|
|
156
|
+
"items": [{"productId": "product-guid-...", "amount": 1}],
|
|
157
|
+
},
|
|
158
|
+
}
|
|
159
|
+
response = client.delivery_create(order_info=order)
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
## Обработка ошибок
|
|
163
|
+
|
|
164
|
+
```python
|
|
165
|
+
from Pyiiko import IikoServer, IikoAuthError, IikoAPIError
|
|
166
|
+
|
|
167
|
+
try:
|
|
168
|
+
server = IikoServer(ip="...", login="user", password="wrong")
|
|
169
|
+
except IikoAuthError:
|
|
170
|
+
print("Неверные учётные данные")
|
|
171
|
+
|
|
172
|
+
try:
|
|
173
|
+
data = server.departments()
|
|
174
|
+
except IikoAPIError as e:
|
|
175
|
+
print(f"Ошибка API: HTTP {e.status_code}")
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
| Исключение | Когда возникает |
|
|
179
|
+
|---|---|
|
|
180
|
+
| `IikoError` | Базовый класс всех ошибок pyiiko |
|
|
181
|
+
| `IikoAuthError` | Неверный логин/пароль, пустой токен |
|
|
182
|
+
| `IikoAPIError` | Сервер вернул HTTP 4xx/5xx |
|
|
183
|
+
|
|
184
|
+
## Справочник методов
|
|
185
|
+
|
|
186
|
+
### `IikoServer`
|
|
187
|
+
|
|
188
|
+
| Метод | Описание |
|
|
189
|
+
|---|---|
|
|
190
|
+
| `version()` | Версия iiko сервера |
|
|
191
|
+
| `server_info()` | Информация о сервере и лицензии |
|
|
192
|
+
| `departments()` | Иерархия подразделений |
|
|
193
|
+
| `stores()` | Список складов |
|
|
194
|
+
| `groups()` | Группы и отделения |
|
|
195
|
+
| `terminals()` | Список терминалов |
|
|
196
|
+
| `terminals_search(anonymous, **kwargs)` | Поиск терминалов |
|
|
197
|
+
| `employees()` | Сотрудники |
|
|
198
|
+
| `products(includeDeleted)` | Номенклатура |
|
|
199
|
+
| `products_find(**kwargs)` | Поиск по номенклатуре |
|
|
200
|
+
| `suppliers()` | Поставщики |
|
|
201
|
+
| `suppliers_find(name, code)` | Поиск поставщиков |
|
|
202
|
+
| `suppliers_price(code, date)` | Прайс-лист поставщика |
|
|
203
|
+
| `events(**kwargs)` | События |
|
|
204
|
+
| `events_filter(body)` | События по фильтру XML |
|
|
205
|
+
| `olap(report, data_from, data_to, **kwargs)` | OLAP-отчёт v1 |
|
|
206
|
+
| `olap2(body)` | OLAP-отчёт v2 (JSON) |
|
|
207
|
+
| `sales(departament, **kwargs)` | Отчёт по выручке |
|
|
208
|
+
| `product_expense(departament, **kwargs)` | Расход продуктов |
|
|
209
|
+
| `store_operation(**kwargs)` | Складские операции |
|
|
210
|
+
| `reports_balance(timestamp, **kwargs)` | Балансы по счетам |
|
|
211
|
+
| `invoice_in(**kwargs)` | Приходные накладные |
|
|
212
|
+
| `invoice_out(**kwargs)` | Расходные накладные |
|
|
213
|
+
| `invoice_number_in(current_year, **kwargs)` | Приходная накладная по номеру |
|
|
214
|
+
| `invoice_number_out(current_year, **kwargs)` | Расходная накладная по номеру |
|
|
215
|
+
| `production_doc(xml)` | Загрузка акта приготовления |
|
|
216
|
+
| `close_session(dateFrom, dateTo)` | Кассовые смены |
|
|
217
|
+
| `edi(edi, **kwargs)` | EDI заказы |
|
|
218
|
+
| `quit_token()` | Уничтожить токен / освободить лицензию |
|
|
219
|
+
|
|
220
|
+
### `Transport`
|
|
221
|
+
|
|
222
|
+
| Метод | Описание |
|
|
223
|
+
|---|---|
|
|
224
|
+
| `organization()` | Список организаций |
|
|
225
|
+
| `terminal(org_id)` | Терминальные группы |
|
|
226
|
+
| `regions(org_id)` | Регионы доставки |
|
|
227
|
+
| `cities(org_id)` | Города |
|
|
228
|
+
| `streets_by_city(org_id, city)` | Улицы города |
|
|
229
|
+
| `delivery_create(order_info)` | Создать доставку |
|
|
230
|
+
| `check_create(order_info)` | Валидировать заказ перед созданием |
|
|
231
|
+
| `by_id(org_id, order_id)` | Доставка по ID |
|
|
232
|
+
| `by_delivery_date(org_id, delivery_date_from)` | Доставки по дате |
|
|
233
|
+
| `by_revision(org_id, revision)` | Доставки с ревизии |
|
|
234
|
+
|
|
235
|
+
### `IikoWeb`
|
|
236
|
+
|
|
237
|
+
#### Авторизация
|
|
238
|
+
|
|
239
|
+
| Метод | Описание |
|
|
240
|
+
|---|---|
|
|
241
|
+
| `get_token()` | Получить новый Bearer-токен по API-ключу |
|
|
242
|
+
| `token()` | Вернуть текущий токен (dict) |
|
|
243
|
+
|
|
244
|
+
#### Справочники (entities)
|
|
245
|
+
|
|
246
|
+
| Метод | Описание |
|
|
247
|
+
|---|---|
|
|
248
|
+
| `stores()` | Список складов |
|
|
249
|
+
| `store(store_id)` | Склад по ID |
|
|
250
|
+
| `products(filters, limit, offset)` | Номенклатура |
|
|
251
|
+
| `product_categories(filters, limit, offset)` | Категории продуктов |
|
|
252
|
+
| `product_sizes(filters, limit, offset)` | Размеры продуктов |
|
|
253
|
+
| `users(filters, limit, offset)` | Пользователи |
|
|
254
|
+
| `payment_types(filters, limit, offset)` | Типы оплат |
|
|
255
|
+
| `cash_flow_categories(filters, limit, offset)` | Статьи ДДС |
|
|
256
|
+
|
|
257
|
+
#### Номенклатура
|
|
258
|
+
|
|
259
|
+
| Метод | Описание |
|
|
260
|
+
|---|---|
|
|
261
|
+
| `update_barcodes(payload)` | Обновить штрих-коды |
|
|
262
|
+
|
|
263
|
+
#### Документооборот
|
|
264
|
+
|
|
265
|
+
| Метод | Описание |
|
|
266
|
+
|---|---|
|
|
267
|
+
| `counteragents(department_id, type, limit, offset)` | Список контрагентов |
|
|
268
|
+
| `incoming_invoice_create(payload)` | Создать приходную накладную |
|
|
269
|
+
| `incoming_invoice_export(department_id, date_from, date_to, ...)` | Экспорт приходных накладных |
|
|
270
|
+
| `incoming_invoice_export_by_number(payload)` | Приходная накладная по номеру |
|
|
271
|
+
| `incoming_invoice_pay(payload)` | Провести оплату приходной накладной |
|
|
272
|
+
| `incoming_invoice_set_payment_date(payload)` | Установить дату оплаты |
|
|
273
|
+
| `incoming_invoice_update(payload)` | Обновить приходную накладную |
|
|
274
|
+
| `incoming_service_create(payload)` | Создать акт входящих услуг |
|
|
275
|
+
| `incoming_service_edit(payload)` | Изменить акт входящих услуг |
|
|
276
|
+
| `incoming_service_export(payload)` | Экспорт актов входящих услуг |
|
|
277
|
+
| `incoming_service_get(payload)` | Получить акт входящих услуг |
|
|
278
|
+
| `internal_transfer_create(payload)` | Создать внутреннее перемещение |
|
|
279
|
+
| `internal_transfer_edit(payload)` | Изменить внутреннее перемещение |
|
|
280
|
+
| `internal_transfer_export(payload)` | Экспорт внутренних перемещений |
|
|
281
|
+
| `internal_transfer_get_by_id(payload)` | Перемещение по ID |
|
|
282
|
+
| `internal_transfer_export_by_number(payload)` | Перемещение по номеру |
|
|
283
|
+
| `outgoing_invoice_create(payload)` | Создать расходную накладную |
|
|
284
|
+
| `outgoing_invoice_export(payload)` | Экспорт расходных накладных |
|
|
285
|
+
| `outgoing_invoice_export_by_number(payload)` | Расходная накладная по номеру |
|
|
286
|
+
| `outgoing_invoice_cost_prices(payload)` | Себестоимость по расходной накладной |
|
|
287
|
+
| `outgoing_invoice_pay(payload)` | Провести оплату расходной накладной |
|
|
288
|
+
| `outgoing_invoice_set_payment_date(payload)` | Установить дату оплаты |
|
|
289
|
+
| `outgoing_invoice_update(payload)` | Обновить расходную накладную |
|
|
290
|
+
| `outgoing_service_create(payload)` | Создать акт исходящих услуг |
|
|
291
|
+
| `outgoing_service_edit(payload)` | Изменить акт исходящих услуг |
|
|
292
|
+
| `outgoing_service_export(payload)` | Экспорт актов исходящих услуг |
|
|
293
|
+
| `outgoing_service_get(payload)` | Получить акт исходящих услуг |
|
|
294
|
+
| `production_doc_create(payload)` | Создать акт приготовления |
|
|
295
|
+
| `production_doc_edit(payload)` | Изменить акт приготовления |
|
|
296
|
+
| `production_doc_export(payload)` | Экспорт актов приготовления |
|
|
297
|
+
| `production_doc_get(payload)` | Получить акт приготовления |
|
|
298
|
+
| `sales_doc_create(payload)` | Создать акт реализации |
|
|
299
|
+
| `sales_doc_edit(payload)` | Изменить акт реализации |
|
|
300
|
+
| `sales_doc_export(payload)` | Экспорт актов реализации |
|
|
301
|
+
| `sales_doc_get(payload)` | Получить акт реализации |
|
|
302
|
+
| `writeoff_create(payload)` | Создать акт списания |
|
|
303
|
+
| `writeoff_edit(payload)` | Изменить акт списания |
|
|
304
|
+
| `writeoff_export(payload)` | Экспорт актов списания |
|
|
305
|
+
| `writeoff_get_by_id(payload)` | Акт списания по ID |
|
|
306
|
+
| `writeoff_export_by_number(payload)` | Акт списания по номеру |
|
|
307
|
+
|
|
308
|
+
#### Закупки
|
|
309
|
+
|
|
310
|
+
| Метод | Описание |
|
|
311
|
+
|---|---|
|
|
312
|
+
| `order_create(store_id, workflow_id, due_date, ...)` | Создать заказ на закупку |
|
|
313
|
+
| `order_get(order_id)` | Заказ на закупку по ID |
|
|
314
|
+
| `orders_list(payload)` | Список заказов на закупку |
|
|
315
|
+
| `order_add_products(payload)` | Добавить продукты в заказ |
|
|
316
|
+
| `order_select_supplier(payload)` | Выбрать поставщика для заказа |
|
|
317
|
+
| `order_task_status(task_id)` | Статус асинхронной задачи заказа |
|
|
318
|
+
| `order_select_units(payload)` | Выбрать единицы измерения для заказа |
|
|
319
|
+
| `workflow_activate(workflow_id)` | Активировать рабочий процесс |
|
|
320
|
+
| `workflow_deactivate(workflow_id)` | Деактивировать рабочий процесс |
|
|
321
|
+
| `workflow_get(workflow_id)` | Рабочий процесс по ID |
|
|
322
|
+
| `workflows_list(payload)` | Список рабочих процессов |
|
|
323
|
+
|
|
324
|
+
## Разработка
|
|
325
|
+
|
|
326
|
+
```bash
|
|
327
|
+
git clone https://github.com/gadzhi/pyiiko.git
|
|
328
|
+
cd pyiiko
|
|
329
|
+
python -m venv .venv && source .venv/bin/activate
|
|
330
|
+
pip install -e ".[dev]"
|
|
331
|
+
pytest --cov=Pyiiko
|
|
332
|
+
```
|
|
333
|
+
|
|
334
|
+
Тесты не требуют подключения к серверу — HTTP замокан через `responses`.
|
|
335
|
+
|
|
336
|
+
Подробности в [CONTRIBUTING.md](CONTRIBUTING.md).
|
|
337
|
+
|
|
338
|
+
## Changelog
|
|
339
|
+
|
|
340
|
+
Смотрите [CHANGELOG.md](CHANGELOG.md).
|
|
341
|
+
|
|
342
|
+
## Лицензия
|
|
343
|
+
|
|
344
|
+
[Apache License 2.0](LICENSE)
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"""pyiiko — Python library for iiko ERP API."""
|
|
2
|
+
from .exceptions import IikoAPIError, IikoAuthError, IikoError
|
|
3
|
+
from .iiko_web import IikoWeb
|
|
4
|
+
from .server import IikoServer
|
|
5
|
+
from .transport import Transport
|
|
6
|
+
|
|
7
|
+
__version__ = "0.4.0"
|
|
8
|
+
__all__ = [
|
|
9
|
+
"IikoServer",
|
|
10
|
+
"Transport",
|
|
11
|
+
"IikoWeb",
|
|
12
|
+
"IikoError",
|
|
13
|
+
"IikoAuthError",
|
|
14
|
+
"IikoAPIError",
|
|
15
|
+
]
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
"""Shared HTTP session, retry logic, and error handling for iiko API clients."""
|
|
2
|
+
from __future__ import annotations
|
|
3
|
+
|
|
4
|
+
import logging
|
|
5
|
+
from typing import Any
|
|
6
|
+
|
|
7
|
+
import requests
|
|
8
|
+
from requests.adapters import HTTPAdapter
|
|
9
|
+
from urllib3.util.retry import Retry
|
|
10
|
+
|
|
11
|
+
from .exceptions import IikoAPIError
|
|
12
|
+
|
|
13
|
+
logger = logging.getLogger(__name__)
|
|
14
|
+
|
|
15
|
+
DEFAULT_TIMEOUT = 10
|
|
16
|
+
_RETRY_TOTAL = 3
|
|
17
|
+
_RETRY_BACKOFF = 0.5
|
|
18
|
+
_RETRY_STATUS_CODES = (500, 502, 503, 504)
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
class BaseIikoClient:
|
|
22
|
+
"""Base class for all iiko API clients.
|
|
23
|
+
|
|
24
|
+
Provides a shared requests.Session with automatic retries on transient
|
|
25
|
+
server errors, structured logging, and uniform HTTP error handling.
|
|
26
|
+
|
|
27
|
+
Supports use as a context manager::
|
|
28
|
+
|
|
29
|
+
with IikoServer(ip=..., login=..., password=...) as client:
|
|
30
|
+
data = client.departments()
|
|
31
|
+
"""
|
|
32
|
+
|
|
33
|
+
def __init__(self, base_url: str, timeout: int = DEFAULT_TIMEOUT) -> None:
|
|
34
|
+
self._base_url = base_url.rstrip("/")
|
|
35
|
+
self._timeout = timeout
|
|
36
|
+
self._session = self._build_session()
|
|
37
|
+
|
|
38
|
+
@staticmethod
|
|
39
|
+
def _build_session() -> requests.Session:
|
|
40
|
+
session = requests.Session()
|
|
41
|
+
retry = Retry(
|
|
42
|
+
total=_RETRY_TOTAL,
|
|
43
|
+
backoff_factor=_RETRY_BACKOFF,
|
|
44
|
+
status_forcelist=list(_RETRY_STATUS_CODES),
|
|
45
|
+
allowed_methods=["GET", "POST"],
|
|
46
|
+
raise_on_status=False,
|
|
47
|
+
)
|
|
48
|
+
adapter = HTTPAdapter(max_retries=retry)
|
|
49
|
+
session.mount("https://", adapter)
|
|
50
|
+
session.mount("http://", adapter)
|
|
51
|
+
return session
|
|
52
|
+
|
|
53
|
+
def _request(self, method: str, path: str, **kwargs: Any) -> requests.Response:
|
|
54
|
+
url = f"{self._base_url}/{path.lstrip('/')}"
|
|
55
|
+
logger.debug("%s %s", method.upper(), url)
|
|
56
|
+
try:
|
|
57
|
+
response = self._session.request(
|
|
58
|
+
method, url, timeout=self._timeout, **kwargs
|
|
59
|
+
)
|
|
60
|
+
response.raise_for_status()
|
|
61
|
+
return response
|
|
62
|
+
except requests.HTTPError as exc:
|
|
63
|
+
status = exc.response.status_code if exc.response is not None else None
|
|
64
|
+
raise IikoAPIError(
|
|
65
|
+
f"HTTP {status} from {url}",
|
|
66
|
+
status_code=status,
|
|
67
|
+
) from exc
|
|
68
|
+
|
|
69
|
+
def _get(self, path: str, **kwargs: Any) -> requests.Response:
|
|
70
|
+
return self._request("GET", path, **kwargs)
|
|
71
|
+
|
|
72
|
+
def _post(self, path: str, **kwargs: Any) -> requests.Response:
|
|
73
|
+
return self._request("POST", path, **kwargs)
|
|
74
|
+
|
|
75
|
+
def close(self) -> None:
|
|
76
|
+
"""Close the underlying HTTP session."""
|
|
77
|
+
self._session.close()
|
|
78
|
+
|
|
79
|
+
def __enter__(self) -> BaseIikoClient:
|
|
80
|
+
return self
|
|
81
|
+
|
|
82
|
+
def __exit__(self, *args: Any) -> None:
|
|
83
|
+
self.close()
|