148 lines
4.4 KiB
Python
148 lines
4.4 KiB
Python
from collections.abc import Mapping
|
|
from typing import TYPE_CHECKING, Any, TypeVar, cast
|
|
|
|
from attrs import define as _attrs_define
|
|
from attrs import field as _attrs_field
|
|
|
|
if TYPE_CHECKING:
|
|
from ..models.node_limit_usage import NodeLimitUsage
|
|
|
|
|
|
T = TypeVar("T", bound="NodeStock")
|
|
|
|
|
|
@_attrs_define
|
|
class NodeStock:
|
|
"""Serializer for mapping the stock of each Node.
|
|
|
|
Attributes:
|
|
id (int): Id of node
|
|
title (str): Title of the equivalent `SelectedRootNode`
|
|
root_path (list[str]): List of title on the path from root to the node.
|
|
count_total (int): Total number of items that have been purchased, are being purchased, have been refunded or
|
|
are only added to a basket.
|
|
count_new (int): Number of items that are in a basket (but not purchased, nor are being purchased, nor refunded)
|
|
count_payment_in_progress (int): Number of items that are currently being purchased.
|
|
count_validated (int): Number of items that have been purchased.
|
|
count_reserved (int): Number of items that are reserved (validated + being paid).
|
|
count_refunded (int): Number of items that have been refunded.
|
|
limits (list['NodeLimitUsage']): Any stock limits that this item has
|
|
"""
|
|
|
|
id: int
|
|
title: str
|
|
root_path: list[str]
|
|
count_total: int
|
|
count_new: int
|
|
count_payment_in_progress: int
|
|
count_validated: int
|
|
count_reserved: int
|
|
count_refunded: int
|
|
limits: list["NodeLimitUsage"]
|
|
additional_properties: dict[str, Any] = _attrs_field(init=False, factory=dict)
|
|
|
|
def to_dict(self) -> dict[str, Any]:
|
|
id = self.id
|
|
|
|
title = self.title
|
|
|
|
root_path = self.root_path
|
|
|
|
count_total = self.count_total
|
|
|
|
count_new = self.count_new
|
|
|
|
count_payment_in_progress = self.count_payment_in_progress
|
|
|
|
count_validated = self.count_validated
|
|
|
|
count_reserved = self.count_reserved
|
|
|
|
count_refunded = self.count_refunded
|
|
|
|
limits = []
|
|
for limits_item_data in self.limits:
|
|
limits_item = limits_item_data.to_dict()
|
|
limits.append(limits_item)
|
|
|
|
field_dict: dict[str, Any] = {}
|
|
field_dict.update(self.additional_properties)
|
|
field_dict.update(
|
|
{
|
|
"id": id,
|
|
"title": title,
|
|
"root_path": root_path,
|
|
"count_total": count_total,
|
|
"count_new": count_new,
|
|
"count_payment_in_progress": count_payment_in_progress,
|
|
"count_validated": count_validated,
|
|
"count_reserved": count_reserved,
|
|
"count_refunded": count_refunded,
|
|
"limits": limits,
|
|
}
|
|
)
|
|
|
|
return field_dict
|
|
|
|
@classmethod
|
|
def from_dict(cls: type[T], src_dict: Mapping[str, Any]) -> T:
|
|
from ..models.node_limit_usage import NodeLimitUsage
|
|
|
|
d = dict(src_dict)
|
|
id = d.pop("id")
|
|
|
|
title = d.pop("title")
|
|
|
|
root_path = cast(list[str], d.pop("root_path"))
|
|
|
|
count_total = d.pop("count_total")
|
|
|
|
count_new = d.pop("count_new")
|
|
|
|
count_payment_in_progress = d.pop("count_payment_in_progress")
|
|
|
|
count_validated = d.pop("count_validated")
|
|
|
|
count_reserved = d.pop("count_reserved")
|
|
|
|
count_refunded = d.pop("count_refunded")
|
|
|
|
limits = []
|
|
_limits = d.pop("limits")
|
|
for limits_item_data in _limits:
|
|
limits_item = NodeLimitUsage.from_dict(limits_item_data)
|
|
|
|
limits.append(limits_item)
|
|
|
|
node_stock = cls(
|
|
id=id,
|
|
title=title,
|
|
root_path=root_path,
|
|
count_total=count_total,
|
|
count_new=count_new,
|
|
count_payment_in_progress=count_payment_in_progress,
|
|
count_validated=count_validated,
|
|
count_reserved=count_reserved,
|
|
count_refunded=count_refunded,
|
|
limits=limits,
|
|
)
|
|
|
|
node_stock.additional_properties = d
|
|
return node_stock
|
|
|
|
@property
|
|
def additional_keys(self) -> list[str]:
|
|
return list(self.additional_properties.keys())
|
|
|
|
def __getitem__(self, key: str) -> Any:
|
|
return self.additional_properties[key]
|
|
|
|
def __setitem__(self, key: str, value: Any) -> None:
|
|
self.additional_properties[key] = value
|
|
|
|
def __delitem__(self, key: str) -> None:
|
|
del self.additional_properties[key]
|
|
|
|
def __contains__(self, key: str) -> bool:
|
|
return key in self.additional_properties
|