Example #1
0
    def read_transactions(self, path):
        for customer_id, quantity, product_id, store_id in file_reader(
                path, 4, sep='|', header=True):
            remain = self._stores[store_id]._items[product_id]
            track = int(quantity)
            if customer_id in self._customers.keys():
                if remain >= track:
                    self._customers[customer_id].add_customer_cart(
                        product_id, track)  # using the student cwid as key
                    self._stores[store_id].remove_product(product_id, track)
                else:
                    self._customers[customer_id].add_customer_cart(
                        product_id, remain)
                    self._stores[store_id].remove_product(product_id, remain)

            else:
                print(
                    f"Warning: customer_id {customer_id} is not in the customers file"
                )

            if product_id in self._products.keys():
                if remain > track:
                    self._products[product_id].add_entities(customer_id, track)
                else:
                    self._products[product_id].add_entities(
                        customer_id, remain)
            else:
                print(
                    f"Warning: instructor cwid {customer_id} is not in the instructor file"
                )
Example #2
0
    def read_inventory(self, path):
        '''Inventory reader keeps a track of the quantity as well as
        links the store id and product id using the keys'''

        try:
            for store_id, quantity, product_id in file_reader(path,
                                                              3,
                                                              sep='|',
                                                              header=True):
                track = int(
                    quantity
                )  # using the tracker object to specify the type of quantity as by default it takes quantity as a string
                if store_id in self._stores.keys():
                    if product_id in self._stores[store_id]._items.keys():
                        print(
                            f"Warning: instructor cwid {product_id} is not in the instructor file"
                        )
                    else:
                        self._stores[store_id].add_products(
                            product_id, track
                        )  # as the values are specified as in the store dictionary, this used the store id to add products and quantity using the product key

                else:
                    print(
                        f"Warning: Store_id {store_id} is not in the stores file"
                    )

        except ValueError as erf:
            print(erf)
Example #3
0
 def read_products(self, path):  # reads the product file
     try:
         for product_id, store_id, product_name in file_reader(
                 path, 3, sep='|', header=False):
             if product_id in self._products.keys(
             ):  # using product id as key to generate the product id, store id and product name as mentioned below
                 print(f"Already exists {product_id}")
             else:
                 self._products[product_id] = Product(
                     product_id, store_id, product_name)
     except ValueError as err:
         print(err)
Example #4
0
 def read_stores(self, path):
     try:
         for store_id, store_name in file_reader(
                 path, 2, sep='*', header=True
         ):  # specifies the header and seperater using my file reader
             if store_id in self._stores.keys():  # store id checker
                 print(f"Already exists {store_id}")
             else:
                 self._stores[store_id] = Stores(
                     store_id, store_name
                 )  # generate the store id and store name using store id as key
     except ValueError as err:
         print(err)
Example #5
0
 def read_customers(self, path):  # reads the customers file
     try:
         for customer_id, customer_name in file_reader(path,
                                                       2,
                                                       sep=",",
                                                       header=True):
             if customer_id in self._customers.keys():
                 print(f"ALready exists {customer_id}")
             else:
                 self._customers[customer_id] = Customer(
                     customer_name, customer_id)
     except ValueError as err:
         print(err)