예제 #1
0
def fetch_all_pos(connection):
    cursor = connection.cursor()
    cursor.execute(queries.get_all_pos())
    pos = []
    for row in cursor.fetchall():
        pos.append(PurchaseOrder(row))
    return pos
예제 #2
0
    def test_should_buy_not_remove_the_product_in_the_store_if_there_are_not_enough_items(self):
        # Creating the mock object
        store:Store = mock()

        # Stubbing
        when(store).are_there_enough_products("Bread", 15).thenReturn(False)

        # Execute
        purchase_order:PurchaseOrder = PurchaseOrder("Bread", 15)
        purchase_order.buy(store)

        # Verify
        verify(store, times=0).remove_products("Bread", 15)
예제 #3
0
 def read_db(self, db_file):
     """Reads POs from supplied CSV file and adds to the database object"""
     with open(db_file, 'r') as db:
         for line in db:
             if len(line) > 1:
                 line = line.replace('\n','').replace('\r','').split(',')
                 PO = PurchaseOrder(line[0], line[1])
                 PO.creation_date = line[2]
                 PO.start_ship = line[3]
                 PO.cancel_ship = line[4]
                 PO.total_cost = line[5]
                 PO.discount = line[6]
                 PO.label = line[7]
                 PO.complete = line[8]
                 self.purchase_orders[PO.po_number] = PO
예제 #4
0
    def test_should_buy_remove_the_product_in_the_store_if_there_are_enough_items(
            self):
        # Creating the mock object
        store: Store = MagicMock()

        # Stubbing
        store.are_there_enough_products.return_value = True

        # Execute
        purchase_order: PurchaseOrder = PurchaseOrder("Bread", 15)
        purchase_order.buy(store)

        # Verify
        store.remove_products.assert_called_once_with("Bread", 15)
예제 #5
0
    def test_shouldBuyWorkIfThereAreProductsTheFirstTimeButNotTheSeconeOne(self):
        # Creating the mock object
        store:Store = mock()

        # Stubbing
        when(store).are_there_enough_products("Bread", 15).thenReturn(True, False)

        # Execute
        purchase_order:PurchaseOrder = PurchaseOrder("Bread", 15)
        purchase_order.buy(store)
        purchase_order.buy(store)

        # Verify
        verify(store, times=2).are_there_enough_products("Bread", 15)
        verify(store, times=1).remove_products("Bread", 15)
예제 #6
0
 def read_export(self, customer):
     """Reads the TLW export based on customer name. If the PO number is not
     already in the program data, adds it"""
     export_file = self.get_export_file(customer)
     with open(export_file, 'r') as export:
         for line in export:
             line = line.rstrip('\n').rstrip('\r').split(',')
             if line[1] != 'PO #':
                 if line[1].lstrip('0') not in self.purchase_orders:
                     PO = PurchaseOrder(line[1].lstrip('0'), customer)
                     PO.cancel_ship = line[4]
                     #PO.total_cost = self.get_cost_from_exp(PO.po_number,
                     #                                       export_file)
                     PO.get_items_from_export(export_file)
                     PO.get_stores_from_export(export_file)
                     for item in PO.items.itervalues():
                         PO.total_cost += (item.cost * item.total_qty)
                     self.purchase_orders[PO.po_number] = PO
                 else:
                     PO = self.purchase_orders[line[1].lstrip('0')]
                     PO.cancel_ship = line[4]
                     #PO.total_cost = self.get_cost_from_exp(PO.po_number,
                                                            #export_file)
                     PO.get_items_from_export(export_file)
                     PO.get_stores_from_export(export_file)
                     PO.total_cost = 0
                     for item in PO.items.itervalues():
                         PO.total_cost += (item.cost * item.total_qty)
                     self.purchase_orders.sync()