Skip to content

Commit

Permalink
import products dynamic column
Browse files Browse the repository at this point in the history
fixes #4
fixes #6
  • Loading branch information
tbellembois committed Sep 12, 2019
1 parent 33a512d commit 05a8304
Showing 1 changed file with 22 additions and 37 deletions.
59 changes: 22 additions & 37 deletions models/sqlitedatastore.go
Original file line number Diff line number Diff line change
Expand Up @@ -1413,10 +1413,8 @@ func (db *SQLiteDataStore) Import(dir string) error {
if csvFile, err = os.Open(path.Join(dir, "product.csv")); err != nil {
return (err)
}
log.Debug("1")
csvMap = helpers.CSVToMap(bufio.NewReader(csvFile))
i = 0
log.Debug("2")
for _, k := range csvMap {
id := k["id"]
cenumber := k["ce_number"]
Expand Down Expand Up @@ -1658,6 +1656,8 @@ func (db *SQLiteDataStore) Import(dir string) error {
}
id := line[0]
label := line[1]
// uppercase liter
label = strings.Replace(label, "l", "L", -1)
// finding new id
var nid int
if err = db.Get(&nid, `SELECT unit_id FROM unit WHERE unit_label = ?`, label); err != nil {
Expand All @@ -1670,42 +1670,27 @@ func (db *SQLiteDataStore) Import(dir string) error {
if csvFile, err = os.Open(path.Join(dir, "storage.csv")); err != nil {
return (err)
}
csvReader = csv.NewReader(bufio.NewReader(csvFile))
csvMap = helpers.CSVToMap(bufio.NewReader(csvFile))
i = 0
for {
line, error := csvReader.Read()

// skip header
if i == 0 {
i++
continue
}

if error == io.EOF {
break
} else if error != nil {
tx.Rollback()
return err
}
// for debug
oldid := line[0]
product := line[1]
person := line[2]
storeLocation := line[3]
unit := line[4]
entrydate := line[6]
exitdate := line[7]
comment := line[8]
barecode := line[9]
reference := line[10]
batchNumber := line[11]
supplier := line[12]
archive := line[13]
creationdate := line[15]
volumeWeight := line[16]
openingdate := line[17]
toDestroy := line[18]
expirationdate := line[19]
for _, k := range csvMap {
oldid := k["id"]
product := k["product"]
person := k["person"]
storeLocation := k["store_location"]
unit := k["unit"]
entrydate := k["entry_datetime"]
exitdate := k["exit_datetime"]
comment := k["comment"]
barecode := k["barecode"]
reference := k["reference"]
batchNumber := k["batch_number"]
supplier := k["supplier"]
archive := k["archive"]
creationdate := k["creation_datetime"]
volumeWeight := k["volume_weight"]
openingdate := k["opening_datetime"]
toDestroy := k["to_destroy"]
expirationdate := k["expiration_datetime"]

log.Debug(log.WithFields(log.Fields{
"oldid": oldid,
Expand Down

0 comments on commit 05a8304

Please sign in to comment.