4
from app.inventory.inventory_config import config
5
from app.inventory.order.schemas import SuggestConfirmScheme
6
from core.fastapi.adapters import BaseAdapter
7
from core.fastapi.adapters.action_decorator import action
8
from core.types import UUIDEncoder
11
class InventoryAdapter(BaseAdapter):
13
protocol = config.APP_PROTOCOL
14
port = config.APP_PORT
15
host = config.APP_HOST
18
async def order(self, params=None, **kwargs):
19
data = await self.list(model='order', params=params)
22
async def order_type(self, params=None, **kwargs):
23
path = '/api/inventory/order_type'
24
responce = await self.session.get(self.domain + path, params=params)
25
data = responce.json()
28
@action(model='move', multiple=False, permits=[])
29
async def action_move_confirm(self, payload: dict | str) -> dict:
33
path = f'/api/inventory/move/confirm'
34
if isinstance(payload, str):
35
payload = json.loads(payload)
36
responce = await self.client.post(self.host + path, json=payload, params={})
37
return responce.json()
39
@action(model='move', multiple=False, permits=[])
40
async def action_move_confirmmmm(self, payload: dict | str):
44
path = f'/api/inventory/move/confirm'
45
if isinstance(payload, str):
46
payload = json.loads(payload)
47
responce = await self.client.post(self.host + path, json=payload, params={})
48
return responce.json()
50
@action(model='suggest',schema=SuggestConfirmScheme, multiple=True, permits=[])
51
async def action_suggest_confirm(self, schema: SuggestConfirmScheme | dict):
52
if isinstance(schema, dict):
53
schema = SuggestConfirmScheme(**schema)
54
path = f'/api/inventory/suggest/confirm'
55
responce = await self.client.post(self.host + path, json=schema.model_dump_json(), params={})
56
return responce.json()
58
@action(model='move', multiple=False, permits=[])
59
async def get_moves_by_barcode(self, barcode: str, order_id: UUID):
60
path = f'/api/inventory/move/get_moves_by_barcode'
63
'order_id': order_id.__str__()
65
responce = await self.client.post(self.host + path, json=payload, params={})
66
return responce.json()
68
@action(model='order', multiple=False, permits=[])
69
async def order_start(self, payload: dict, **kwargs):
70
"""Назначение пользователя на заказ, если не указан, то возьется из запроса"""
71
if isinstance(payload, dict):
72
payload = json.dumps(payload, cls=UUIDEncoder)
73
path = f'/api/inventory/order/order_start'
74
responce = await self.client.post(self.host + path, json=payload, params={})
75
return responce.json()
77
@action(model='order', multiple=False, permits=[])
78
async def assign_order(self, order_id, user_id: UUID):
79
"""Назначение пользователя на заказ, если не указан, то возьется из запроса"""
80
if isinstance(user_id, UUID):
81
user_id = user_id.__str__()
82
if isinstance(order_id, UUID):
83
order_id = order_id.__str__()
84
path = f'/api/inventory/order/assign_order'
87
'user_id': user_id if user_id else None
89
responce = await self.client.post(self.host + path, json=payload, params={})
90
return responce.json()