Add option for not importing location

This commit is contained in:
Alf Sebastian Houge
2022-04-06 12:06:45 +02:00
parent 15cf09f326
commit dc33aaad49
3 changed files with 24 additions and 6 deletions

View File

@@ -65,7 +65,7 @@ func DrivvoParseExpenses(content []byte, user *db.User, vehicle *db.Vehicle) ([]
return expenses, errors
}
func DrivvoParseRefuelings(content []byte, user *db.User, vehicle *db.Vehicle) ([]db.Fillup, []string) {
func DrivvoParseRefuelings(content []byte, user *db.User, vehicle *db.Vehicle, importLocation bool) ([]db.Fillup, []string) {
refuelingReader := csv.NewReader(bytes.NewReader(content))
refuelingReader.Comment = '#'
refuelingRecords, err := refuelingReader.ReadAll()
@@ -99,8 +99,10 @@ func DrivvoParseRefuelings(content []byte, user *db.User, vehicle *db.Vehicle) (
errors = append(errors, "Found an invalid odometer reading at refuel row "+strconv.Itoa(index+1))
}
// TODO: Make optional
location := record[17]
location := ""
if importLocation {
location = record[17]
}
pricePerUnit, err := strconv.ParseFloat(record[3], 32)
if err != nil {
@@ -142,7 +144,7 @@ func DrivvoParseRefuelings(content []byte, user *db.User, vehicle *db.Vehicle) (
return fillups, errors
}
func DrivvoImport(content []byte, userId string, vehicleId string) []string {
func DrivvoImport(content []byte, userId string, vehicleId string, importLocation bool) []string {
var errors []string
user, err := GetUserById(userId)
if err != nil {
@@ -172,7 +174,7 @@ func DrivvoImport(content []byte, userId string, vehicleId string) []string {
expenseSectionIndex = endParseIndex
}
fillups, errors := DrivvoParseRefuelings(content[:serviceSectionIndex], user, vehicle)
fillups, errors := DrivvoParseRefuelings(content[:serviceSectionIndex], user, vehicle, importLocation)
_ = fillups
var allExpenses []db.Expense