diff --git a/db/dump/fixtures.sql b/db/dump/fixtures.sql index e69974d08..76fba5b04 100644 --- a/db/dump/fixtures.sql +++ b/db/dump/fixtures.sql @@ -2863,6 +2863,10 @@ INSERT INTO `vn`.`wagonTypeTray` (`id`, `typeFk`, `height`, `colorFk`) (2, 1, 50, 2), (3, 1, 0, 3); +INSERT INTO `vn`.`travelConfig` (id, warehouseInFk, warehouseOutFk, agencyFk, companyFk) + VALUES + (1, 1, 1, 1, 442); - - +INSERT INTO `vn`.`buyConfig` (id, showLastBuy) + VALUES + (1, 6); diff --git a/modules/entry/back/methods/entry/addFromPackaging.js b/modules/entry/back/methods/entry/addFromPackaging.js index 4eaf0fcbd..9ba855303 100644 --- a/modules/entry/back/methods/entry/addFromPackaging.js +++ b/modules/entry/back/methods/entry/addFromPackaging.js @@ -48,9 +48,9 @@ module.exports = Self => { tomorrow.setDate(today.getDate() + 1); const travel = await models.Travel.create({ - shipmentHour: args.isTravelReception ? yesterday : today, - landingHour: args.isTravelReception ? today : tomorrow, - agencyFk: travelConfig.agencyFk, + shipped: args.isTravelReception ? yesterday : today, + landed: args.isTravelReception ? today : tomorrow, + agencyModeFk: travelConfig.agencyFk, warehouseInFk: travelConfig.warehouseOutFk, warehouseOutFk: travelConfig.warehouseInFk }, myOptions); @@ -63,7 +63,7 @@ module.exports = Self => { if (tx) await tx.commit(); - return {travel, entry}; + return entry; } catch (e) { if (tx) await tx.rollback(); throw e; diff --git a/modules/entry/back/methods/entry/specs/addFromPackaging.spec.js b/modules/entry/back/methods/entry/specs/addFromPackaging.spec.js new file mode 100644 index 000000000..42d33ae61 --- /dev/null +++ b/modules/entry/back/methods/entry/specs/addFromPackaging.spec.js @@ -0,0 +1,49 @@ +const models = require('vn-loopback/server/server').models; +const LoopBackContext = require('loopback-context'); + +describe('entry addFromPackaging()', () => { + const supplier = 442; + const today = new Date(); + const yesterday = new Date(today); + yesterday.setDate(today.getDate() - 1); + + beforeAll(async() => { + const activeCtx = { + accessToken: {userId: 49}, + http: { + req: { + headers: {origin: 'http://localhost'}, + }, + }, + }; + spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({ + active: activeCtx, + }); + }); + + it('should create a receipt travel', async() => { + const ctx = {args: {isTravelReception: true, supplier}}; + const tx = await models.Entry.beginTransaction({}); + const options = {transaction: tx}; + + try { + const entry = await models.Entry.addFromPackaging(ctx, options); + const travelConfig = await models.TravelConfig.findOne({}, options); + const travel = await models.Travel.findOne({order: 'id DESC'}, options); + + expect(new Date(travel.shipped).getDate()).toEqual(yesterday.getDate()); + expect(new Date(travel.landed).getDate()).toEqual(today.getDate()); + expect(travel.agencyModeFk).toEqual(travelConfig.agencyFk); + expect(travel.warehouseInFk).toEqual(travelConfig.warehouseOutFk); + expect(travel.warehouseOutFk).toEqual(travelConfig.warehouseInFk); + expect(entry.supplierFk).toEqual(supplier); + expect(entry.travelFk).toEqual(travel.id); + expect(entry.companyFk).toEqual(travelConfig.companyFk); + + await tx.rollback(); + } catch (e) { + await tx.rollback(); + throw e; + } + }); +});