def addItem(self, orderedItem, storeOrderId): """Adds a new ordered item to the system pre-condition:The ordered item as well as the store order id it is part of should be passed in as arguments post-condition:The ordered item is stored in the system""" AccessLayer.addOrderedItem(orderedItem.productStock.id, "Awaiting Shipment", orderedItem.deliveryOption.id, storeOrderId)
def setShipped(self): """Updates the orders, noting that the product has been shipped to the customer pre-condition:The ordered item should have been stored in the system post-condition:The product stock associated with this product will have its quantity reduced by one and this ordered item will have the state 'Shipped'""" self.state = "Shipped" self.productStock.notifyItemsShipped(1) AccessLayer.setOrderedItemShipped(self.id)
def addStoreOrder(self, orderDescription): """Adds a new store order to the system pre-condition:The description of the order must be passed as an argument post-condition:The store order is added to the system and the id of the stored store order is returned""" storeOrderId = AccessLayer.addStoreOrder( orderDescription.customer.customerId, orderDescription.deliveryAddress) for orderedItem in orderDescription.orderedItems: AccessLayer.addOrderedItem(orderedItem.productStock.id, "Awaiting Shipment", orderedItem.deliveryOption.id, storeOrderId, orderedItem.productStock.sellerId) return storeOrderId
def getCustomerById(self, id): """Fetches a customer based on the customer id pre-condition:The id of the customer (integer) to fetch should be passed as an argument post-condition:If a customer with that id exists they will be returned, otherwise a None object will be""" name = AccessLayer.getCustomerName(id) if name == None: return None return self._createCustomerObject(id, name)
def getCustomerByName(self, name): """Fetches a customer based on the customer name pre-condition:The name of the customer (string) to fetch should be passed as an argument post-condition:If a customer with that name exists they will be returned, otherwise a None object will be""" id = AccessLayer.getCustomerId(name) if id == None: return None return self._createCustomerObject(id, name)
def addCustomer(self, customer): """Adds a new customer to the system pre-condition:A customer object should be supplied as an argument, the customer should have a unique name post-condition:The customer is stored in the system""" if self.getCustomerByName(customer.name) != None: raise ValueError() customer.customerId = AccessLayer.addCustomer(customer) return customer.customerId
def getOrder(self, storeOrderId): """Fetches a specific store order from the system pre-condition:The id of the StoreOrder to fetch must be supplied post-condition:A StoreOrder object with the appropriate details is returned""" orderArr = AccessLayer.getOrder(storeOrderId) if len(orderArr) == 0: return None customer = Customer.Customers().getCustomerById(orderArr[3]) return self.orderArrToStoreOrder(orderArr, customer)
def getOrdersForCustomer(self, customerId): """Returns all the store orders for a particular customer pre-condition:The id of the customer needs to be passed as an argument post-condition:A list of the store orders for a specific customer is returned""" ordersArr = AccessLayer.getOrdersForCustomer(customerId) orders = [] customer = Customer.Customers().getCustomerById(customerId) for orderArr in ordersArr: orders.append(self.orderArrToStoreOrder(orderArr, customer)) return orders
def getOrderedItemForStoreOrder(self, storeOrderId): """Returns all the ordered items for a particular store order pre-condition:The id of the store order needs to be passed as an arguments post-condition:A list of the store orders for a specific order is returned""" itemsArr = AccessLayer.getOrderedItemForStoreOrder(storeOrderId) orderedItems = [] for arr in itemsArr: productStockId = arr[0] productStock = Products.ProductStocks().getProductStock( productStockId) orderdItem = OrderedItem(productStock) orderdItem.state = arr[1] orderdItem.deliveryOption = Seller.DeliveryOptions( ).getDeliveryOption(arr[2], arr[4]) orderedItems.append(orderdItem) return orderedItems
def getOrderedItems(self): """Returns the Ordered Items associated with this specific store order pre-condition:None post-condition:All the Ordered Items are returned in a list""" return StoreOrder.itemArrToItems( AccessLayer.getOrderedItemsForStoreOrder(self.storeOrderId))