Pyiiko 0.4.0__tar.gz → 0.5.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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: Pyiiko
3
- Version: 0.4.0
3
+ Version: 0.5.0
4
4
  Summary: Python library for iiko ERP API
5
5
  Author-email: Gadzhibala Pirmagomedov <gadzhibala@protonmail.com>
6
6
  License-Expression: Apache-2.0
@@ -4,7 +4,7 @@ from .iiko_web import IikoWeb
4
4
  from .server import IikoServer
5
5
  from .transport import Transport
6
6
 
7
- __version__ = "0.4.0"
7
+ __version__ = "0.5.0"
8
8
  __all__ = [
9
9
  "IikoServer",
10
10
  "Transport",
@@ -0,0 +1,103 @@
1
+ """Reference-data (v2 справочники) mixin for IikoServer — keeps server.py under 800 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 _EntitiesMixin:
11
+ """Mixin providing v2 reference-data (справочники) endpoints for IikoServer.
12
+
13
+ Two endpoints are exposed:
14
+
15
+ * ``GET /api/v2/entities/list`` — return common reference records for one
16
+ or more entity types (available since iiko 5.0).
17
+ * ``GET /api/v2/entities/{entityType}/ids`` — return the list of UUIDs for
18
+ an entity type (available since iiko 9.2.1028.0).
19
+ """
20
+
21
+ if TYPE_CHECKING:
22
+ def _get(self, path: str, **kwargs: Any) -> requests.Response: ...
23
+
24
+ def _key(self, **extra: Any) -> dict[str, Any]: # satisfied by IikoServer
25
+ raise NotImplementedError
26
+
27
+ # ------------------------------------------------------------------
28
+ # Справочники
29
+ # ------------------------------------------------------------------
30
+
31
+ def entities_list(
32
+ self,
33
+ root_types: list[str],
34
+ include_deleted: bool = True,
35
+ revision_from: int = -1,
36
+ ) -> Any:
37
+ """Return reference data for one or more entity types (v2 API).
38
+
39
+ :param root_types: One or more entity type names, e.g.
40
+ ``["DiscountType", "PaymentType"]``. Supported values include
41
+ ``Account``, ``DiscountType``, ``PaymentType``, ``TaxCategory``,
42
+ ``LocalTax``, ``OrderType``, ``ProductSize``, and others.
43
+ :param include_deleted: Include deleted records (default ``True``,
44
+ matching the API default).
45
+ :param revision_from: Return only items whose revision is strictly
46
+ greater than this value. ``-1`` disables the filter (default).
47
+ :returns: Parsed JSON list. Each element contains ``id``,
48
+ ``rootType``, ``deleted``, ``code``, ``name``. Some types expose
49
+ additional fields:
50
+
51
+ * ``OrderType`` → ``orderServiceType``, ``defaultForServiceType``
52
+ * ``ProductSize`` → ``shortName``
53
+ * ``TaxCategory`` → ``vatPercent``
54
+ * ``LocalTax`` → ``appliedVAT``, ``vatCategoryId``,
55
+ ``ordersTypesIds``, ``allOrderTypes``, ``categoriesIds``,
56
+ ``departmentsSettings``, ``reporting``, ``createdAt``,
57
+ ``updatedAt``
58
+
59
+ Available since iiko 5.0.
60
+
61
+ Example::
62
+
63
+ data = server.entities_list(
64
+ ["DiscountType", "PaymentType"],
65
+ include_deleted=False,
66
+ )
67
+ """
68
+ params: list[tuple[str, Any]] = [
69
+ ("key", self._key()["key"]),
70
+ ("includeDeleted", str(include_deleted).lower()),
71
+ ("revisionFrom", revision_from),
72
+ ]
73
+ for rt in root_types:
74
+ params.append(("rootType", rt))
75
+ return self._get("api/v2/entities/list", params=params).json()
76
+
77
+ def entities_ids(
78
+ self,
79
+ entity_type: str,
80
+ include_deleted: bool = True,
81
+ revision_from: int = -1,
82
+ ) -> Any:
83
+ """Return the list of UUID identifiers for an entity type (v2 API).
84
+
85
+ :param entity_type: Entity type name, e.g. ``"Account"``.
86
+ :param include_deleted: Include deleted records (default ``True``).
87
+ :param revision_from: Return only items whose revision is strictly
88
+ greater than this value. ``-1`` disables the filter (default).
89
+ :returns: Parsed JSON list of UUID strings.
90
+
91
+ Available since iiko 9.2.1028.0.
92
+
93
+ Example::
94
+
95
+ ids = server.entities_ids("Account", include_deleted=False, revision_from=10)
96
+ """
97
+ return self._get(
98
+ f"api/v2/entities/{entity_type}/ids",
99
+ params=self._key(
100
+ includeDeleted=str(include_deleted).lower(),
101
+ revisionFrom=revision_from,
102
+ ),
103
+ ).json()
@@ -8,13 +8,14 @@ from typing import Any
8
8
  from lxml import etree
9
9
 
10
10
  from ._base import DEFAULT_TIMEOUT, BaseIikoClient
11
+ from ._server_entities import _EntitiesMixin
11
12
  from ._server_nomenclature import _NomenclatureMixin
12
13
  from .exceptions import IikoAuthError
13
14
 
14
15
  logger = logging.getLogger(__name__)
15
16
 
16
17
 
17
- class IikoServer(_NomenclatureMixin, BaseIikoClient):
18
+ class IikoServer(_EntitiesMixin, _NomenclatureMixin, BaseIikoClient):
18
19
  """Client for the iiko Server REST API (on-premise installations).
19
20
 
20
21
  Authenticates on construction and stores the token for subsequent calls.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: Pyiiko
3
- Version: 0.4.0
3
+ Version: 0.5.0
4
4
  Summary: Python library for iiko ERP API
5
5
  Author-email: Gadzhibala Pirmagomedov <gadzhibala@protonmail.com>
6
6
  License-Expression: Apache-2.0
@@ -3,6 +3,7 @@ README.md
3
3
  pyproject.toml
4
4
  Pyiiko/__init__.py
5
5
  Pyiiko/_base.py
6
+ Pyiiko/_server_entities.py
6
7
  Pyiiko/_server_nomenclature.py
7
8
  Pyiiko/_web_docs.py
8
9
  Pyiiko/exceptions.py
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "Pyiiko"
7
- version = "0.4.0"
7
+ version = "0.5.0"
8
8
  description = "Python library for iiko ERP API"
9
9
  readme = "README.md"
10
10
  license = "Apache-2.0"
@@ -925,3 +925,96 @@ def test_nomenclature_category_restore(server):
925
925
  )
926
926
  result = server.nomenclature_category_restore(["cat-uuid"])
927
927
  assert result["result"] == "SUCCESS"
928
+
929
+
930
+ # ---------------------------------------------------------------------------
931
+ # Entities v2 — reference data (справочники)
932
+ # ---------------------------------------------------------------------------
933
+
934
+ _ENT_BASE = f"{SERVER_BASE}/api/v2/entities"
935
+
936
+
937
+ @responses.activate
938
+ def test_entities_list_returns_data(server):
939
+ payload = [{"id": "uuid-1", "rootType": "DiscountType", "deleted": False, "code": None, "name": "Скидка 20%"}]
940
+ responses.add(responses.GET, f"{_ENT_BASE}/list", json=payload, status=200)
941
+ result = server.entities_list(["DiscountType"])
942
+ assert result[0]["rootType"] == "DiscountType"
943
+ assert result[0]["id"] == "uuid-1"
944
+
945
+
946
+ @responses.activate
947
+ def test_entities_list_multiple_root_types(server):
948
+ responses.add(responses.GET, f"{_ENT_BASE}/list", json=[], status=200)
949
+ server.entities_list(["DiscountType", "PaymentType"])
950
+ url = responses.calls[0].request.url
951
+ assert "rootType=DiscountType" in url
952
+ assert "rootType=PaymentType" in url
953
+
954
+
955
+ @responses.activate
956
+ def test_entities_list_include_deleted_false(server):
957
+ responses.add(responses.GET, f"{_ENT_BASE}/list", json=[], status=200)
958
+ server.entities_list(["TaxCategory"], include_deleted=False)
959
+ assert "includeDeleted=false" in responses.calls[0].request.url
960
+
961
+
962
+ @responses.activate
963
+ def test_entities_list_include_deleted_default_true(server):
964
+ responses.add(responses.GET, f"{_ENT_BASE}/list", json=[], status=200)
965
+ server.entities_list(["Account"])
966
+ assert "includeDeleted=true" in responses.calls[0].request.url
967
+
968
+
969
+ @responses.activate
970
+ def test_entities_list_revision_from_param(server):
971
+ responses.add(responses.GET, f"{_ENT_BASE}/list", json=[], status=200)
972
+ server.entities_list(["Account"], revision_from=42)
973
+ assert "revisionFrom=42" in responses.calls[0].request.url
974
+
975
+
976
+ @responses.activate
977
+ def test_entities_list_passes_auth_key(server):
978
+ from tests.conftest import FAKE_TOKEN
979
+ responses.add(responses.GET, f"{_ENT_BASE}/list", json=[], status=200)
980
+ server.entities_list(["OrderType"])
981
+ assert f"key={FAKE_TOKEN}" in responses.calls[0].request.url
982
+
983
+
984
+ @responses.activate
985
+ def test_entities_ids_returns_list(server):
986
+ uuids = ["15fb045f-db6a-269d-6473-023f3c936fcf", "6aacad98-dc14-2a85-10fc-0b0261eb8849"]
987
+ responses.add(responses.GET, f"{_ENT_BASE}/Account/ids", json=uuids, status=200)
988
+ result = server.entities_ids("Account")
989
+ assert result == uuids
990
+
991
+
992
+ @responses.activate
993
+ def test_entities_ids_entity_type_in_path(server):
994
+ responses.add(responses.GET, f"{_ENT_BASE}/PaymentType/ids", json=[], status=200)
995
+ server.entities_ids("PaymentType")
996
+ assert "/api/v2/entities/PaymentType/ids" in responses.calls[0].request.url
997
+
998
+
999
+ @responses.activate
1000
+ def test_entities_ids_include_deleted_and_revision(server):
1001
+ responses.add(responses.GET, f"{_ENT_BASE}/Account/ids", json=[], status=200)
1002
+ server.entities_ids("Account", include_deleted=False, revision_from=10)
1003
+ url = responses.calls[0].request.url
1004
+ assert "includeDeleted=false" in url
1005
+ assert "revisionFrom=10" in url
1006
+
1007
+
1008
+ @responses.activate
1009
+ def test_entities_ids_default_include_deleted_true(server):
1010
+ responses.add(responses.GET, f"{_ENT_BASE}/Account/ids", json=[], status=200)
1011
+ server.entities_ids("Account")
1012
+ assert "includeDeleted=true" in responses.calls[0].request.url
1013
+
1014
+
1015
+ @responses.activate
1016
+ def test_entities_ids_passes_auth_key(server):
1017
+ from tests.conftest import FAKE_TOKEN
1018
+ responses.add(responses.GET, f"{_ENT_BASE}/Account/ids", json=[], status=200)
1019
+ server.entities_ids("Account")
1020
+ assert f"key={FAKE_TOKEN}" in responses.calls[0].request.url
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes