def __init__(self):

        self.idName = "ProductId"
        self.idQ = "Quantity"
        self.idCost = "UnitCost"
        self.idPrice = "UnitPrice"
        self.addStyle = behavior_accumulate_retail()
 def test_stockTotalCostandRetail(self):
     inv = StoreInventory()
     # to calculate the accumulative  retail available, set addBehavior to
     # salesAddBehaviour (this behavior may be renamed to
     # accumulativeRetailBehaviour)
     inv.setAddStyle(behavior_accumulate_retail())
     inv.addProductsCSV("./csvs/ifix-stock_2016-01-22.csv")
     assert inv.costAll() == 588989.66
     assert inv.costAll(retail=True) == 3244457
    def test_totalSalesBySKU(self):

        sold = SalesProductList()
        sold.addProductsCSV("./csvs/stock-sales_TEST.csv")

        eA = Product()
        eA.setAddStyle(behavior_accumulate_retail())
        eA = eA.addStyle.addItem(eA, -6, 5, 10)  # calculated manually

        assert sold['602'].totalCost == eA.totalCost
        assert sold['602'].count == eA.count
        assert sold['602'].retail == eA.retail

        assert sold['602'].totalCost == -30
        assert sold['602'].count == -6
        assert sold['602'].retail == -60
    def test_weightedUnitPrice(self):

        inv = StoreInventory()
        # to calculate the accumulative  retail available, set addBehavior to
        # salesAddBehaviour (this behavior may be renamed to
        # accumulativeRetailBehaviour)
        inv.setAddStyle(behavior_accumulate_retail())
        inv.addProductsCSV("./csvs/trendTest/ifix-stock_trendTest.csv")

        orders = OrdersList()
        orders.addProductsCSV("./csvs/trendTest/stock-purchases_trendTest.csv")

        sales = SalesProductList()
        sales.addProductsCSV("./csvs/trendTest/stock-sales_trendTest.csv")

        inv.addOrders(orders)
        wUnitCost = inv.getWeightedUnitCost("6691")

        # rounding is required at the last moment so errors do not accumulate

        assert round(wUnitCost, 2) == 89.61
        assert round(sales["6691"].count * wUnitCost, 2) == -358.43
        inv.addSales(sales)
        assert round(inv["6691"].count * wUnitCost, 2) == 806.47