fleetmap-reports 1.0.554 → 1.0.556

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fleetmap-reports",
3
- "version": "1.0.554",
3
+ "version": "1.0.556",
4
4
  "description": "",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
@@ -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 (userData.withOdooServices) {
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 = userData.withOdooServices ? getOdooAvgConsumption(refuelingPositions, trips) : 0
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: userData.withOdooServices ? odooAvgConsumption : getCanAvgConsumption(distance, spentFuel),
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 (userData.withOdooServices) {
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
@@ -377,7 +377,6 @@ describe('Test_Reports', function () {
377
377
  it('FuelConsumption Odoo Report', async () => {
378
378
  const report = await getReports()
379
379
  const userData = await report.getUserData()
380
- userData.withOdooServices = true
381
380
  userData.devices = userData.devices.filter(d => d.id === 22326)
382
381
  const data = await report.fuelConsumptionReport(
383
382
  new Date(Date.UTC(2022, 9, 1, 0, 0, 0, 0)),
@@ -205,8 +205,17 @@ async function exportLocationReportToPDF (userData, reportData) {
205
205
 
206
206
  if (positionsData) {
207
207
  if (userData.includeDigitalPorts) {
208
- headers.push(getDigitalPort1Label(userData.byDriver ? positionsData[0].driver : positionsData[0].device, translations))
209
- headers.push(getDigitalPort2Label(userData.byDriver ? positionsData[0].driver : positionsData[0].device, translations))
208
+ headers.push(
209
+ getDigitalPort1Label(
210
+ userData.byDriver ? positionsData[0].driver : positionsData[0].device,
211
+ translations,
212
+ positionsData[0].device.attributes
213
+ ))
214
+ headers.push(
215
+ getDigitalPort2Label(
216
+ userData.byDriver ? positionsData[0].driver : positionsData[0].device,
217
+ translations,
218
+ positionsData[0].device.attributes))
210
219
  }
211
220
  headers.push('Latitude')
212
221
  headers.push('Longitude')
@@ -247,8 +256,8 @@ async function exportLocationReportToPDF (userData, reportData) {
247
256
  }
248
257
 
249
258
  if (userData.includeDigitalPorts) {
250
- temp.push(getDigitalPortValue(a, 1, translations))
251
- temp.push(getDigitalPortValue(a, 2, translations))
259
+ temp.push(getDigitalPortValue(a, 1, translations, d.attributes))
260
+ temp.push(getDigitalPortValue(a, 2, translations, d.attributes))
252
261
  }
253
262
  temp.push(a.latitude)
254
263
  temp.push(a.longitude)
@@ -296,18 +305,24 @@ function getTempValue (row) {
296
305
  )) || ''
297
306
  }
298
307
 
299
- function getDigitalPort1Label (row, translations) {
300
- return row.attributes.door1 || translations.report.digital_ports1
308
+ function getDigitalPort1Label (row, translations, dAttributes) {
309
+ return dAttributes.sensor1 || translations.report.digital_ports1
301
310
  }
302
311
 
303
312
  function getDigitalPort2Label (row, translations) {
304
313
  return row.attributes.door2 || translations.report.digital_ports2
305
314
  }
306
315
 
307
- function getDigitalPortValue (row, index, translations) {
316
+ function getDigitalPortValue (row, index, translations, dAttributes) {
308
317
  switch (index) {
309
318
  case 1:
310
- return row.attributes && row.attributes.door1 ? translations.report[row.attributes.door1] : ''
319
+ if (row.attributes && row.attributes.door1 !== undefined) {
320
+ return translations.report[row.attributes.door1]
321
+ }
322
+ if (row.attributes && row.attributes.sensor !== undefined) {
323
+ return dAttributes.sensor1On || row.attributes.sensor
324
+ }
325
+ break
311
326
  case 2:
312
327
  if (row.attributes && row.attributes.door2) {
313
328
  return translations.report[row.attributes.door2]
@@ -80,27 +80,18 @@ async function createZoneReport (from, to, userData, traccar) {
80
80
  return reportData
81
81
  }
82
82
 
83
- async function getAllInOne (
83
+ async function getRoute (
84
84
  traccar,
85
85
  from,
86
86
  to,
87
87
  devices,
88
- getRoutes,
89
- getTrips,
90
- getStops,
91
- getSummary,
92
88
  currentDeviceCount = 0,
93
89
  totalDevices = devices.length,
94
90
  sliceSize = 5,
95
91
  devicesPerRequest = 1,
96
92
  counter = undefined,
97
93
  userData) {
98
- let url = `/reports/allinone?from=${from.toISOString()}&to=${to.toISOString()}`
99
- if (getRoutes) url += '&type=route'
100
- if (getTrips) url += '&type=trips'
101
- if (getStops) url += '&type=stops'
102
- if (getSummary) url += '&type=summary'
103
-
94
+ const url = `/reports/allinone?from=${from.toISOString()}&to=${to.toISOString()}&type=route`
104
95
  const sliced = automaticReports.sliceArray(devices, sliceSize)
105
96
  const result = []
106
97
  console.log('getAll, slicing', sliceSize)