def main(): HoG = Customer('Heart of Gold', 'The Milky Way Galaxy', False) Millis = Customer('Milliways Restaurant', 'Magrathea', True) Arthur = Customer('Arthur Dent', 'Earth', False) drive = OrderItem('Infinite Improbability Drive', 'IID1', 1, 100, True) Trillian = OrderItem('Date with Trillian', 'DWT', 42, 1000000, True) choc = OrderItem('Chocolate', 'CHOC', 200, 250, False) ord1 = Order(1, 'Terra', False, False, HoG, [drive]) ord2 = Order(2, 'Heart of Gold', True, False, Arthur, [Trillian, choc]) ord3 = Order(3, 'Magrathea', True, False, Millis, [choc]) Order.orders = [ord1, ord2, ord3] Order.notify_backordered(Order.orders, "backordered items") Order.orders = Order.mark_backordered(Order.orders, 3, 'CHOC') # print(len( # Order.count_expedited_orders_with_backordered_items(Order.orders)) # ) # print(Order.count_expedited_orders_with_backordered_items_rec(Order.orders)) # print(Order.count_expedited_orders_with_backordered_items_tail(Order.orders)) print( tramp(Order.count_expedited_orders_with_backordered_items_tramp, Order.orders)) print( Order.count_expedited_orders_with_backordered_items_comp(Order.orders))
def mark_backordered_items(items, itemnumber): return tuple( get_update_seq(items, lambda i: i.itemnumber == itemnumber, lambda i: OrderItem(i.name, i.itemnumber, i.quantity, i.price, True) ) )
def __init__(self, _json): self.id = _json['id'] #TODO: CHECK this # self.date_created = DateTime.parse(json[:date_created]) # self.date_closed = DateTime.parse(json[:date_closed]) self.date_created = parser.parse(_json['date_created']) self.date_closed = parser.parse(_json['date_closed']) buyer = _json['buyer'] self.buyer_name = "{} {}".format(buyer['first_name'], buyer['last_name']) self.shipping_cost = 0 if _json.get('payments', None): for payment in _json['payments']: self.shipping_cost += payment['shipping_cost'] self.order_items = [] for order_item_json in _json['order_items']: self.order_items.append(OrderItem(order_item_json)) self.shipping_id = _json.get('shipping').get('id', "") if self.shipping_id is not None: self.shipping_url = "https://myaccount.mercadolibre.com.mx/sales/shipments/printShipmentsLabels?ids={}".format( self.shipping_id) else: self.shipping_url = ""
def mark_backordered(orders, orderid, itemnumber): return Order.map( lambda o: # copy all orders that do not match the orderid o if o.orderid != orderid # otherwise build a new order with a new order item list else (Order( o.orderid, o.shipping_address, o.expedited, o.shipped, o.customer, Order.map( lambda i: # copy the items that don't match item if i.itemnumber != itemnumber # otherwise build a new order item setting backordered to True else OrderItem(i.name, i.itemnumber, i.quantity, i.price, True), # iterate over all order items o.order_items))), # iterate over all orders orders)
def main(): HoG = Customer('Heart of Gold', 'The Milky Way Galaxy', False) Millis = Customer('Milliways Restaurant', 'Magrathea', True) Arthur = Customer('Arthur Dent', 'Earth', False) drive = OrderItem('Infinite Improbability Drive', 'IID1', 1, 100, True) Trillian = OrderItem('Date with Trillian', 'DWT', 42, 1000000, True) choc = OrderItem('Chocolate', 'CHOC', 200, 250, False) ord1 = Order(1, 'Terra', False, False, HoG, [drive]) ord2 = Order(2, 'Heart of Gold', True, False, Arthur, [Trillian, choc]) ord3 = Order(3, 'Magrathea', True, False, Millis, [choc]) Order.orders = [ord1, ord2, ord3] Order.notify_backordered(Order.orders, "backordered items") Order.orders = Order.mark_backordered(Order.orders, 3, 'CHOC') assert Order.orders[2].order_items[0].backordered pass
def mark_backordered(orders, orderid, itemnumber): return get_updated_tuple( orders, lambda o: o.orderid == orderid, lambda o: Order( o.orderid, o.shipping_address, o.expedited, o.shipped, o. customer, get_updated_tuple( o.order_items, lambda i: i. itemnumber == itemnumber, lambda i: OrderItem( i.name, i.itemnumber, i.quantity, i.price, True))))
continue # Items from the order json_order_items = json_order['items'] items_in_order = 0 for item in json_order_items: items_in_order = items_in_order + int(item['quantity']) css_order = CssOrder(json_order['name'], json_order['service'], items_in_order, json_order['ordered_at']) db.session.add(css_order) db.session.commit() print("> Received Order #{} for {}".format(css_order.id, css_order.name)) for item in json_order_items: order_item = OrderItem(css_order.id, item['name'], item['price_per_unit'], item['quantity']) db.session.add(order_item) db.session.commit() menu_item = MenuItem.query.filter_by(name=item['name']).first() job = q.enqueue(JobWorker.process_item, css_order.id, order_item.id, item['quantity'], menu_item.cook_time, menu_item.name) job = q.enqueue(JobWorker.process, css_order.id) except TypeError as te: print("Waiting for kafka... {}".format(str(te))) else: print("Error setting up the database tables")
def add_item(self, item: OrderItem): item.order = self self.items.append(item) return len(self.items)
from datetime import date from order_item import OrderItem from product import Product from order import Order p = Product(1, 'Smartphone', 500) print("New Product: " + str(p)) item = OrderItem(p, 1) order = Order(1, str(date.today())) order.add_item(item) print("Item added: " + str(item)) print("New Order: " + str(order))