コード例 #1
0
func TestMain(t *testing.T) {

	// It could be interesting to retain 'Route' in some kind of object

	cmd1 := skelet.Cmd{
		T:     stock.InCmd{"Carlsbourg", items.Items{IsoK: Iso4}, "2016-01-27"},
		Route: stockRoute,
	}

	cmd2 := skelet.Cmd{
		T:     stock.OutCmd{"Carlsbourg", items.Items{IsoK: Iso1}, "2016-01-28"},
		Route: stockRoute,
	}

	cmd3 := skelet.Cmd{
		T:     stock.InventoryCmd{"Carlsbourg", items.Items{IsoK: Iso2}, "2016-01-29"},
		Route: stockRoute,
	}

	skelet.ExecuteCommand(cmd1, stockCmd.Chain)
	skelet.ExecuteCommand(cmd2, stockCmd.Chain)
	skelet.ExecuteCommand(cmd3, stockCmd.Chain)

	c, err := repo.Get("Carlsbourg")

	if err != nil {
		t.Fatal(err)
	}

	s := c.(*stock.Stock)

	exps := map[string]item.Item{IsoK: Iso2}

	CheckItemsValueAndExistence(t, s.Items, exps, "stock")
}
コード例 #2
0
ファイル: c-main.go プロジェクト: olivier5741/stock-manager
func main() {

	prodValHeader = []string{asset.Tr("csv_header_item_product"),
		asset.Tr("csv_header_item_value", 1), asset.Tr("csv_header_item_unit", 1),
		asset.Tr("csv_header_item_value", 2), asset.Tr("csv_header_item_unit", 2),
		asset.Tr("csv_header_item_value", 3), asset.Tr("csv_header_item_unit", 3),
		asset.Tr("csv_header_item_value", 4), asset.Tr("csv_header_item_unit", 4),
	}

	// LOGGING
	logfile := loggingPrefix + asset.Tr("file_name_log")
	f, err1 := os.OpenFile(logfile,
		os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0666)
	if err1 != nil {
		log.WithFields(log.Fields{
			"filename": logfile,
			"err":      err1,
		}).Error(asset.Tr("error_file_open"))
	}
	defer f.Close()

	log.SetOutput(f)
	log.SetFormatter(&log.JSONFormatter{})
	log.SetLevel(log.ErrorLevel)

	// UPDATE
	all := sheet.AllSheets(files)

	for _, name := range all {
		s := sheet.NewSheet(name, files)
		its := items.FromStringTable(s.Table.GetContentWithRowHeader())
		var cmd skelet.Ider

		switch s.Name.Act {
		case asset.Tr("file_name_stock_in"):
			cmd = stock.InCmd{stockId, its, s.Name.Time()}
		case asset.Tr("file_name_stock_out"):
			cmd = stock.OutCmd{stockId, its, s.Name.Time()}
		case asset.Tr("file_name_inventory"):
			cmd = stock.InventoryCmd{stockId, its, s.Name.Time()}
		default:
			log.Error(asset.Tr("no_action_for_filename_error"))
		}
		skelet.ExecuteCommand(skelet.Cmd{T: cmd, Route: stockRoute}, stockCmd.Chain)
	}

	// POPULATE VIEW
	stockInt, err4 := endPt.Db.Get("main")
	iStock := stockInt.(*stock.Stock).Items
	if err4 != nil {
		log.WithFields(log.Fields{
			"err": err4,
		}).Error(asset.Tr("error_query_stock"))
	}

	prodValRender := func(tab *strtab.T) [][]string {
		return tab.GetContentWithHeaders(false)
	}
	prodEvolRender := func(tab *strtab.T) [][]string {
		return tab.GetContentWithHeaders(true)
	}

	sheet.Sheet{
		sheet.NewBasicFilename(asset.Tr("file_name_stock")),
		strtab.NewT(prodValHeader, iStock.StringSlice()...).Sort(),
		prodValRender}.Put(files)

	sheet.Sheet{
		sheet.NewDraftFilename(3, asset.Tr("file_name_inventory")),
		strtab.NewT(prodValHeader, iStock.StringSlice()...).Sort(),
		prodValRender}.Put(files)

	sheet.Sheet{
		sheet.NewDraftFilename(1, asset.Tr("file_name_stock_in")),
		strtab.NewT(prodValHeader, iStock.Empty().StringSlice()...).Sort(),
		prodValRender}.Put(files)

	sheet.Sheet{
		sheet.NewDraftFilename(2, asset.Tr("file_name_stock_out")),
		strtab.NewT(prodValHeader, iStock.Empty().StringSlice()...).Sort(),
		prodValRender}.Put(files)

	sheet.Sheet{
		sheet.NewBasicFilename(asset.Tr("file_name_product")),
		strtab.NewTfromMap(items.ItemsMapToStringMapTable(
			endPt.ProdValEvol("main"))).Sort().Transpose().Sort(),
		prodEvolRender}.Put(files)
}