|
@@ -204,51 +204,21 @@ class Order(_YamlInitConstructor):
|
|
order_date = order_date.date()
|
|
order_date = order_date.date()
|
|
assert type(order_date) is datetime.date
|
|
assert type(order_date) is datetime.date
|
|
self.order_date = order_date
|
|
self.order_date = order_date
|
|
- assert customer_id is None or type(customer_id) is unicode
|
|
+ if customer_id is not None:
|
|
- self.customer_id = customer_id
|
|
+ assert type(customer_id) is unicode
|
|
|
|
+ self.customer_id = customer_id
|
|
if items is None:
|
|
if items is None:
|
|
- items = []
|
|
+ self.items = []
|
|
- assert type(items) is list
|
|
+ else:
|
|
- self.items = items
|
|
+ assert type(items) is list
|
|
|
|
+ assert all([isinstance(i, Item) for i in items])
|
|
|
|
+ self.items = items
|
|
if discounts is None:
|
|
if discounts is None:
|
|
- discounts = []
|
|
+ self.discounts = []
|
|
- assert type(discounts) is list
|
|
+ else:
|
|
- self.discounts = discounts
|
|
+ assert type(discounts) is list
|
|
-
|
|
+ assert all([isinstance(d, Discount) for d in discounts])
|
|
- def dict_repr(self):
|
|
+ self.discounts = discounts
|
|
- return {k: v for (k, v) in {
|
|
|
|
- 'articles': self.items,
|
|
|
|
- 'customer_id': self.customer_id,
|
|
|
|
- 'discounts': self.discounts,
|
|
|
|
- 'order_date': self.order_date.strftime('%Y-%m-%d'),
|
|
|
|
- 'order_id': self.order_id,
|
|
|
|
- 'platform': self.platform,
|
|
|
|
- }.items() if v is not None}
|
|
|
|
-
|
|
|
|
- @staticmethod
|
|
|
|
- def from_dict(attr):
|
|
|
|
- order = Order(
|
|
|
|
- platform = attr['platform'],
|
|
|
|
- order_id = attr['order_id'],
|
|
|
|
- order_date = datetime.datetime.strptime(attr['order_date'], '%Y-%m-%d'),
|
|
|
|
- )
|
|
|
|
-
|
|
|
|
- if 'customer_id' in attr:
|
|
|
|
- order.customer_id = attr['customer_id']
|
|
|
|
-
|
|
|
|
- for item in attr['articles']:
|
|
|
|
- if type(item) is dict:
|
|
|
|
- item = Item.from_dict(item)
|
|
|
|
- assert isinstance(item, Item)
|
|
|
|
- order.items.append(item)
|
|
|
|
-
|
|
|
|
- for discount in attr['discounts']:
|
|
|
|
- if type(discount) is dict:
|
|
|
|
- discount = Discount.from_dict(discount)
|
|
|
|
- assert isinstance(discount, Discount)
|
|
|
|
- order.discounts.append(discount)
|
|
|
|
-
|
|
|
|
- return order
|
|
|
|
|
|
|
|
def __eq__(self, other):
|
|
def __eq__(self, other):
|
|
return (type(self) == type(other)
|
|
return (type(self) == type(other)
|
|
@@ -271,20 +241,6 @@ class Item(_YamlInitConstructor):
|
|
assert type(price_brutto) is Sum
|
|
assert type(price_brutto) is Sum
|
|
self.price_brutto = price_brutto
|
|
self.price_brutto = price_brutto
|
|
|
|
|
|
- def dict_repr(self):
|
|
|
|
- return {
|
|
|
|
- 'name': self.name,
|
|
|
|
- 'price_brutto': self.price_brutto.value,
|
|
|
|
- 'price_brutto_currency': self.price_brutto.currency,
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- @staticmethod
|
|
|
|
- def from_dict(attr):
|
|
|
|
- return Item(
|
|
|
|
- name = attr['name'],
|
|
|
|
- price_brutto = Sum(attr['price_brutto'], attr['price_brutto_currency']),
|
|
|
|
- )
|
|
|
|
-
|
|
|
|
def __eq__(self, other):
|
|
def __eq__(self, other):
|
|
return (type(self) == type(other)
|
|
return (type(self) == type(other)
|
|
and vars(self) == vars(other))
|
|
and vars(self) == vars(other))
|