fleetmap-reports 1.0.554 → 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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fleetmap-reports",
3
- "version": "1.0.554",
3
+ "version": "1.0.555",
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)),