fleetmap-reports 1.0.553 → 1.0.555
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/fuelconsumption-report.js +8 -4
- package/src/index.test.js +0 -30
- package/src/util/utils.js +1 -1
package/package.json
CHANGED
|
@@ -27,7 +27,7 @@ async function createFuelConsumptionReport (from, to, userData, traccar) {
|
|
|
27
27
|
const routeData = allInOne.route
|
|
28
28
|
|
|
29
29
|
const fuelServicesData = []
|
|
30
|
-
if (
|
|
30
|
+
if (devices.some(d => d.attributes.odooId)) {
|
|
31
31
|
fuelServicesData.push(...(await odoo.getOdooFuelServices(traccar, from, to)))
|
|
32
32
|
}
|
|
33
33
|
|
|
@@ -55,7 +55,7 @@ async function createFuelConsumptionReport (from, to, userData, traccar) {
|
|
|
55
55
|
new Map()
|
|
56
56
|
)
|
|
57
57
|
|
|
58
|
-
const odooAvgConsumption =
|
|
58
|
+
const odooAvgConsumption = useOdooFuelData(d, route) ? getOdooAvgConsumption(refuelingPositions, trips) : 0
|
|
59
59
|
|
|
60
60
|
const days = []
|
|
61
61
|
const keys = Array.from(groupedTripsByDay.keys())
|
|
@@ -70,7 +70,7 @@ async function createFuelConsumptionReport (from, to, userData, traccar) {
|
|
|
70
70
|
date: day,
|
|
71
71
|
distance,
|
|
72
72
|
spentFuel,
|
|
73
|
-
avgConsumption:
|
|
73
|
+
avgConsumption: useOdooFuelData(d, route) ? odooAvgConsumption : getCanAvgConsumption(distance, spentFuel),
|
|
74
74
|
endOdometer: dayTrips.slice(-1)[0].endOdometer,
|
|
75
75
|
duration: dayTrips.reduce((a, b) => a + b.duration, 0),
|
|
76
76
|
refueling: (dayRefueling && dayRefueling.length > 0) ? dayRefueling.reduce((a, b) => a + b.diff, 0) : 0
|
|
@@ -113,7 +113,7 @@ function calculateConsumption (userData, d, day, avgConsumption, data) {
|
|
|
113
113
|
if (d.attributes.xpert) {
|
|
114
114
|
return automaticReports.calculateXpertSpentFuel(day, data.route)
|
|
115
115
|
}
|
|
116
|
-
if (
|
|
116
|
+
if (useOdooFuelData(d, data.route)) {
|
|
117
117
|
return Math.round((avgConsumption.byKms * (data.trips.reduce((a, b) => a + b.distance, 0) / 1000)) / 100)
|
|
118
118
|
}
|
|
119
119
|
return automaticReports.calculateSpentFuel(data.trips.reduce((a, b) => a + b.spentFuel, 0), d)
|
|
@@ -226,6 +226,10 @@ function deviceName (device) {
|
|
|
226
226
|
return device.name + (device.attributes.license_plate ? ', ' + device.attributes.license_plate : '') + (device.model ? ', ' + device.model : '')
|
|
227
227
|
}
|
|
228
228
|
|
|
229
|
+
function useOdooFuelData (d, route) {
|
|
230
|
+
return route.length && !route[0].attributes.fuel && d.attributes.odooId
|
|
231
|
+
}
|
|
232
|
+
|
|
229
233
|
exports.createFuelConsumptionReport = createFuelConsumptionReport
|
|
230
234
|
exports.exportFuelConsumptionReportToPDF = exportFuelConsumptionReportToPDF
|
|
231
235
|
exports.exportFuelConsumptionReportToExcel = exportFuelConsumptionReportToExcel
|
package/src/index.test.js
CHANGED
|
@@ -120,22 +120,6 @@ describe('Test_Reports', function () {
|
|
|
120
120
|
assert.equal(device.trips[1].endPOIName, undefined)
|
|
121
121
|
}, 20000)
|
|
122
122
|
// eslint-disable-next-line no-undef
|
|
123
|
-
it('Trip 2 by device', async () => {
|
|
124
|
-
const report = await getReports()
|
|
125
|
-
const userData = await report.getUserData()
|
|
126
|
-
userData.devices = userData.devices.filter(d => d.id === 11437)
|
|
127
|
-
|
|
128
|
-
const data = await report.tripReport(
|
|
129
|
-
new Date(Date.UTC(2022, 2, 4, 0, 0, 0, 0)),
|
|
130
|
-
new Date(Date.UTC(2022, 2, 4, 23, 59, 59, 0)),
|
|
131
|
-
userData)
|
|
132
|
-
|
|
133
|
-
assert.equal(data.length, 1)
|
|
134
|
-
const device = data[0].devices.find(d => d.device.id === 11437)
|
|
135
|
-
assert.equal(device.trips.length, 5) // Total Trips
|
|
136
|
-
assert.equal(device.totalDistance, 207353.2299999997) // Total Kms
|
|
137
|
-
}, 20000)
|
|
138
|
-
// eslint-disable-next-line no-undef
|
|
139
123
|
it('Trip by device with time period ', async () => {
|
|
140
124
|
const report = await getReports()
|
|
141
125
|
const userData = await report.getUserData()
|
|
@@ -297,19 +281,6 @@ describe('Test_Reports', function () {
|
|
|
297
281
|
assert.equal(device.summary[0].endTime, '2022-01-31T17:36:27.000+0000')
|
|
298
282
|
}, 80000)
|
|
299
283
|
// eslint-disable-next-line no-undef
|
|
300
|
-
it('Activity 2 by device', async () => {
|
|
301
|
-
const report = await getReports()
|
|
302
|
-
const userData = await report.getUserData()
|
|
303
|
-
userData.devices = userData.devices.filter(d => d.id === 11437)
|
|
304
|
-
const data = await report.activityReport(new Date(Date.UTC(2022, 2, 5, 0, 0, 0, 0)),
|
|
305
|
-
new Date(Date.UTC(2022, 2, 5, 23, 59, 59, 0)),
|
|
306
|
-
userData)
|
|
307
|
-
assert.equal(data.length, 1)
|
|
308
|
-
const device = data[0].devices.find(d => d.device.id === 11437)
|
|
309
|
-
assert.equal(device.summary[0].endTime, '2022-03-05T23:59:55.000+0000')
|
|
310
|
-
assert.equal(device.summary[0].distance, 232925.12000000034)
|
|
311
|
-
}, 40000)
|
|
312
|
-
// eslint-disable-next-line no-undef
|
|
313
284
|
it('Activity byDevice groupByDay', async () => {
|
|
314
285
|
const report = await getReports()
|
|
315
286
|
const userData = await report.getUserData()
|
|
@@ -406,7 +377,6 @@ describe('Test_Reports', function () {
|
|
|
406
377
|
it('FuelConsumption Odoo Report', async () => {
|
|
407
378
|
const report = await getReports()
|
|
408
379
|
const userData = await report.getUserData()
|
|
409
|
-
userData.withOdooServices = true
|
|
410
380
|
userData.devices = userData.devices.filter(d => d.id === 22326)
|
|
411
381
|
const data = await report.fuelConsumptionReport(
|
|
412
382
|
new Date(Date.UTC(2022, 9, 1, 0, 0, 0, 0)),
|
package/src/util/utils.js
CHANGED
|
@@ -7,7 +7,7 @@ const distance = require('@turf/distance')
|
|
|
7
7
|
exports.getTranslations = (userData) => {
|
|
8
8
|
const lang = this.getLanguage(userData)
|
|
9
9
|
if (!messages[lang]) {
|
|
10
|
-
console.warn('no lang found for', userData.user, userData.user.attributes.lang
|
|
10
|
+
console.warn('no lang found for', userData.user, userData.user.attributes.lang)
|
|
11
11
|
}
|
|
12
12
|
return messages[lang] ? messages[lang] : messages['en-GB']
|
|
13
13
|
}
|