Skip to content

Commit ec70dba

Browse files
committed
Added tests and fixed some APIs
1 parent 784a962 commit ec70dba

File tree

19 files changed

+1645
-205
lines changed

19 files changed

+1645
-205
lines changed

docs/en/docs/integrations/clopos/api-reference/response.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,6 @@
5454

5555
::: integrify.clopos.schemas.objects.sub.ModifierGroup
5656

57-
::: integrify.clopos.schemas.objects.sub.Recipe
58-
5957
::: integrify.clopos.schemas.objects.sub.Package
6058

6159
::: integrify.clopos.schemas.objects.sub.Tax
@@ -80,10 +78,12 @@
8078

8179
::: integrify.clopos.schemas.objects.sub.OrderProductProduct
8280

83-
::: integrify.clopos.schemas.objects.sub.LineItem
84-
8581
::: integrify.clopos.schemas.objects.sub.ReceiptPaymentMethod
8682

83+
::: integrify.clopos.schemas.objects.sub.ReceiptProduct
84+
8785
### Helper Type
8886

8987
::: integrify.clopos.helpers.IsoDateTime
88+
89+
::: integrify.clopos.helpers.BoolInt

docs/en/partial.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Clopos:
2-
- About: "integrations/clopos/about.md"
3-
- Env Variables: "integrations/clopos/env.md"
2+
- "integrations/clopos/about.md"
3+
- "integrations/clopos/env.md"
44
- API Reference:
55
- API Client: "integrations/clopos/api-reference/client.md"
66
- Schemas:

pyproject.toml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,7 @@ classifiers = [
3535
"Topic :: Internet :: WWW/HTTP :: HTTP Servers",
3636
"Topic :: Internet :: WWW/HTTP",
3737
]
38-
dependencies = [
39-
"integrify-core",
40-
]
38+
dependencies = ["integrify-core"]
4139

4240
[project.urls]
4341
Homepage = "https://integrify.mmzeynalli.dev/integrations/clopos/about"
@@ -67,6 +65,7 @@ dev = [
6765
docs = [
6866
"mkdocs-material[imaging]>=9.6.4,<10",
6967
"mkdocstrings[python]>=0.28.1,<1.0.0",
68+
"mkdocs-panzoom-plugin>=0.1.3,<0.2",
7069
"griffe-pydantic>=1.1.0,<2",
7170
]
7271

src/integrify/clopos/client.py

Lines changed: 150 additions & 47 deletions
Large diffs are not rendered by default.

src/integrify/clopos/env.py

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import os
22
from enum import Enum
3-
from warnings import warn
43

54
from integrify.utils import Environment
65

@@ -14,13 +13,6 @@
1413
CLOPOS_ENV: str = os.getenv('CLOPOS_ENV', Environment.TEST.value)
1514

1615

17-
if not CLOPOS_CLIENT_ID or not CLOPOS_CLIENT_SECRET: # pragma: no cover
18-
warn(
19-
'If you do not set CLOPOS_CLIENT_ID and CLOPOS_CLIENT_SECRET environment variables, '
20-
'the integration might not work. '
21-
)
22-
23-
2416
class API(str, Enum):
2517
"""Endpoint constant-ları"""
2618

src/integrify/clopos/handlers.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
GetCustomersRequest,
2525
GetOrdersRequest,
2626
GetPaginatedDataRequest,
27+
GetProductByIDRequest,
2728
GetProductsRequest,
2829
GetStationsRequest,
2930
UpdateOrderRequest,
@@ -152,6 +153,16 @@ def post_handle_payload(self, data):
152153
return json.dumps(data) # for urlencoding
153154

154155

156+
class GetProductByIDHandler(AuthedAPIPayloadHandler):
157+
def __init__(
158+
self,
159+
req_model=GetProductByIDRequest,
160+
resp_model=ObjectResponse[Product],
161+
dry=False,
162+
):
163+
super().__init__(req_model, resp_model, dry)
164+
165+
155166
class GetOrdersHandler(AuthedAPIPayloadHandler):
156167
def __init__(
157168
self,

src/integrify/clopos/helpers.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
from datetime import datetime
22
from typing import Annotated, Union
33

4-
from pydantic import BeforeValidator, Field
4+
from pydantic import BeforeValidator
55

66
IsoDateTime = Annotated[
77
Union[str, datetime, None],
8-
Field(BeforeValidator(lambda v: v.isoformat() if isinstance(v, datetime) else v)),
8+
BeforeValidator(lambda v: v.isoformat() if isinstance(v, datetime) else v),
99
]
1010
"""ISO 8601 date-time format Pydantic field validator."""
11+
12+
BoolInt = Annotated[int, BeforeValidator(lambda v: int(bool(v)))]
13+
"""Boolean to integer Pydantic field validator."""

src/integrify/clopos/schemas/enums.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,15 @@ class ProductType(str, Enum):
1313
TIMER = 'TIMER'
1414
PREPARATION = 'PREPARATION'
1515
INGREDIENT = 'INGREDIENT'
16-
MODIFICATION = 'MODIFICATION '
16+
MODIFICATION = 'MODIFICATION'
1717

1818

1919
class OrderStatus(str, Enum):
2020
IN_PROGRESS = 'IN_PROGRESS'
2121
PENDING = 'PENDING'
2222
CONFIRMED = 'CONFIRMED'
2323
COMPLETED = 'COMPLETED'
24+
RECEIVED = 'RECEIVED'
2425
CANCELLED = 'CANCELLED'
2526
IGNORE = 'IGNORE'
2627

Lines changed: 38 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
from decimal import Decimal
2-
from typing import Optional
32

43
from pydantic import BaseModel
54

65
from integrify.clopos.helpers import IsoDateTime
6+
from integrify.utils import UnsetField, UnsetOrNoneField
77

88

99
class PaymentMethodIn(BaseModel):
@@ -17,8 +17,39 @@ class PaymentMethodIn(BaseModel):
1717
"""The amount of the payment method"""
1818

1919

20-
class ReceiptProductIn(BaseModel):
20+
class ServiceIn(BaseModel):
21+
sale_type_id: int
22+
sale_type_name: str
23+
venue_id: int
24+
venue_name: str
25+
26+
27+
class CustomerIn(BaseModel):
2128
id: int
29+
name: str
30+
customer_discount_type: UnsetField[int] = None
31+
phone: UnsetField[str] = None
32+
address: UnsetOrNoneField[str]
33+
34+
35+
class ProductIn(BaseModel):
36+
product_id: int
37+
count: int
38+
product_modificators: UnsetOrNoneField[list[dict]]
39+
meta: UnsetOrNoneField[dict]
40+
41+
42+
class OrderPayloadIn(BaseModel):
43+
service: ServiceIn
44+
customer: CustomerIn
45+
products: list[ProductIn]
46+
meta: UnsetOrNoneField[dict]
47+
48+
49+
class ReceiptProductIn(BaseModel):
50+
model_config = {'extra': 'allow'}
51+
52+
id: UnsetField[int]
2253
"""The unique identifier for the receipt product"""
2354

2455
cid: str
@@ -27,12 +58,6 @@ class ReceiptProductIn(BaseModel):
2758
product_id: int
2859
"""The ID of the product associated with the receipt product"""
2960

30-
receipt_id: int
31-
"""The ID of the receipt associated with the receipt product"""
32-
33-
product_hash: str
34-
"""The hash of the product associated with the receipt product"""
35-
3661
meta: dict
3762
"""The meta data of the receipt product"""
3863

@@ -48,62 +73,20 @@ class ReceiptProductIn(BaseModel):
4873
price: Decimal
4974
"""The price of the receipt product"""
5075

51-
cost: Decimal
76+
cost: UnsetField[Decimal]
5277
"""The cost of the receipt product"""
5378

5479
is_gift: bool
5580
"""Whether the receipt product is a gift"""
5681

57-
preprint_count: int
58-
"""The preprint count of the receipt product"""
59-
60-
station_printed_count: int
61-
"""The station printed count of the receipt product"""
62-
63-
station_aborted_count: int
64-
"""The station aborted count of the receipt product"""
65-
66-
seller_id: int
67-
"""The ID of the seller associated with the receipt product"""
68-
69-
loyalty_type: Optional[str]
70-
"""The loyalty type of the receipt product"""
71-
72-
loyalty_value: Optional[Decimal]
73-
"""The loyalty value of the receipt product"""
74-
75-
discount_rate: Decimal
76-
"""The discount rate of the receipt product"""
77-
78-
discount_value: Decimal
79-
"""The discount value of the receipt product"""
80-
81-
discount_type: Decimal
82-
"""The discount type of the receipt product"""
83-
84-
total_discount: Decimal
85-
"""The total discount of the receipt product"""
86-
87-
subtotal: Decimal
88-
"""The subtotal of the receipt product"""
89-
90-
receipt_discount: Decimal
91-
"""The receipt discount of the receipt product"""
92-
93-
created_at: IsoDateTime
82+
created_at: UnsetField[IsoDateTime]
9483
"""The created at of the receipt product"""
9584

96-
updated_at: IsoDateTime
85+
updated_at: UnsetField[IsoDateTime]
9786
"""The updated at of the receipt product"""
9887

99-
terminal_updated_at: IsoDateTime
88+
terminal_updated_at: UnsetField[IsoDateTime]
10089
"""The terminal updated at of the receipt product"""
10190

102-
deleted_at: IsoDateTime
91+
deleted_at: UnsetField[IsoDateTime]
10392
"""The deleted at of the receipt product"""
104-
105-
receipt_product_modificators: list
106-
"""The receipt product modificators of the receipt product"""
107-
108-
taxes: list
109-
"""The taxes of the receipt product"""

src/integrify/clopos/schemas/objects/main.py

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
from pydantic import BaseModel, Field
55

66
from integrify.clopos.schemas.enums import CategoryType, DiscountType, OrderStatus, ProductType
7-
from integrify.clopos.schemas.objects.input import ReceiptProductIn
87
from integrify.clopos.schemas.objects.sub import (
98
Balance,
109
Image,
@@ -15,7 +14,7 @@
1514
Package,
1615
Price,
1716
ReceiptPaymentMethod,
18-
Recipe,
17+
ReceiptProduct,
1918
Tax,
2019
TimerSetting,
2120
Timestamp,
@@ -334,7 +333,7 @@ class Product(Timestamp):
334333
net_output: UnsetOrNoneField[int]
335334
"""Net output of the product"""
336335

337-
type: ProductType
336+
type: UnsetOrNoneField[ProductType]
338337
"""product, ingredient, accounting"""
339338

340339
name: str
@@ -361,7 +360,7 @@ class Product(Timestamp):
361360
cost: UnsetOrNoneField[Decimal]
362361
"""The cost of the product"""
363362

364-
status: int
363+
status: UnsetOrNoneField[int]
365364
"""1 = active, 0 = inactive"""
366365

367366
hidden: UnsetOrNoneField[bool]
@@ -394,7 +393,7 @@ class Product(Timestamp):
394393
modificator_groups: UnsetOrNoneField[list[ModifierGroup]]
395394
"""List of modificator groups for GOODS type products. See Modificator Group Object"""
396395

397-
recipe: UnsetOrNoneField[Recipe]
396+
recipe: UnsetOrNoneField[list['Product']]
398397
"""Recipe for DISH or PREPARATION type products. See Recipe Item."""
399398

400399
packages: UnsetOrNoneField[list[Package]]
@@ -466,10 +465,10 @@ class Product(Timestamp):
466465
venues: UnsetOrNoneField[list[Venue]]
467466
"""The venues the product is available in"""
468467

469-
properties: UnsetOrNoneField[list[dict]]
468+
properties: UnsetOrNoneField[Union[dict, list]]
470469
"""The properties of the product"""
471470

472-
media: list[Media]
471+
media: UnsetOrNoneField[list[Media]]
473472
"""Media of the product"""
474473

475474
tags: UnsetOrNoneField[list[dict]]
@@ -487,6 +486,12 @@ class Product(Timestamp):
487486
open_receipts_count: UnsetOrNoneField[int]
488487
"""The number of open receipts for the product"""
489488

489+
created_at: UnsetOrNoneField[str] # type: ignore[assignment]
490+
"""The timestamp when the object was created"""
491+
492+
updated_at: UnsetOrNoneField[str] # type: ignore[assignment]
493+
"""The timestamp when the object was last updated"""
494+
490495

491496
class PaymentMethod(Timestamp):
492497
id: int
@@ -545,7 +550,7 @@ class SaleType(Timestamp):
545550
payment_method: UnsetOrNoneField[PaymentMethod]
546551
"""An object containing details of the associated payment method"""
547552

548-
media: list[Media]
553+
media: UnsetOrNoneField[list[Media]]
549554
"""Media of the sale type"""
550555

551556

@@ -783,7 +788,7 @@ class Receipt(Timestamp):
783788
order_number: UnsetOrNoneField[str]
784789
"""Order number"""
785790

786-
receipt_products: UnsetOrNoneField[list[ReceiptProductIn]] = None
791+
receipt_products: UnsetOrNoneField[list[ReceiptProduct]] = None
787792
"""Receipt products"""
788793

789794
terminal_updated_at: UnsetOrNoneField[str]

0 commit comments

Comments
 (0)