diff --git a/modules/travel/back/methods/travel/getAverageDays.js b/modules/travel/back/methods/travel/getAverageDays.js index e56ac21e6..7f6be936e 100644 --- a/modules/travel/back/methods/travel/getAverageDays.js +++ b/modules/travel/back/methods/travel/getAverageDays.js @@ -31,7 +31,7 @@ module.exports = Self => { t.warehouseInFk, t.warehouseOutFk, t.landed, - t.shipped,+ + t.shipped, t.agencyFk FROM travel t WHERE t.agencyFk = ? LIMIT 50)`, [agencyModeFk]); @@ -43,6 +43,7 @@ module.exports = Self => { WHERE t.agencyFk ORDER BY id DESC LIMIT 50) AS dayDuration FROM tmp.travel t WHERE t.agencyFk ORDER BY t.id DESC LIMIT 1`); + let resultAvgDays = stmts.push(stmt) - 1; stmts.push( `DROP TEMPORARY TABLE @@ -52,6 +53,7 @@ module.exports = Self => { let result = await conn.executeStmt(sql); avgDays = result[resultAvgDays]; + return avgDays; }; }; diff --git a/modules/travel/front/create/index.js b/modules/travel/front/create/index.js index c76728e59..ba5bbd1ff 100644 --- a/modules/travel/front/create/index.js +++ b/modules/travel/front/create/index.js @@ -22,6 +22,8 @@ class Controller extends Section { agencyModeFk: this.travel.agencyModeFk }; this.$http.get(query, {params}).then(res => { + if (res.data.length < 1) + return; const landed = new Date(value); const futureDate = landed.getDate() + res.data[0].dayDuration; landed.setDate(futureDate); diff --git a/modules/travel/front/create/index.spec.js b/modules/travel/front/create/index.spec.js index dcb17d494..af1864ffd 100644 --- a/modules/travel/front/create/index.spec.js +++ b/modules/travel/front/create/index.spec.js @@ -41,7 +41,7 @@ describe('Travel Component vnTravelCreate', () => { }); }); - describe('onShippedChange()', () => { + fdescribe('onShippedChange()', () => { it(`should do nothing if there's no agencyModeFk in the travel.`, () => { controller.travel = {}; controller.onShippedChange(); @@ -51,6 +51,20 @@ describe('Travel Component vnTravelCreate', () => { expect(controller.travel.warehouseOutFk).toBeUndefined(); }); + it(`should do nothing if it hasn't value on response data.`, () => { + controller.travel = {agencyModeFk: 4}; + const tomorrow = new Date(); + const result = [{}]; + const expectedResponse = [{}]; + + const query = `travels/getAverageDays?agencyModeFk=${controller.travel.agencyModeFk}`; + $httpBackend.expectGET(query).respond(expectedResponse); + controller.onShippedChange(tomorrow); + $httpBackend.flush(); + + expect(expectedResponse).toEqual(result); + }); + it(`should fill the fields when it's selected a date and agency.`, () => { controller.travel = {agencyModeFk: 1}; const tomorrow = new Date();