This commit is contained in:
parent
8ae5a0de0f
commit
5cdec35ed4
|
@ -2863,6 +2863,10 @@ INSERT INTO `vn`.`wagonTypeTray` (`id`, `typeFk`, `height`, `colorFk`)
|
||||||
(2, 1, 50, 2),
|
(2, 1, 50, 2),
|
||||||
(3, 1, 0, 3);
|
(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);
|
||||||
|
|
|
@ -48,9 +48,9 @@ module.exports = Self => {
|
||||||
tomorrow.setDate(today.getDate() + 1);
|
tomorrow.setDate(today.getDate() + 1);
|
||||||
|
|
||||||
const travel = await models.Travel.create({
|
const travel = await models.Travel.create({
|
||||||
shipmentHour: args.isTravelReception ? yesterday : today,
|
shipped: args.isTravelReception ? yesterday : today,
|
||||||
landingHour: args.isTravelReception ? today : tomorrow,
|
landed: args.isTravelReception ? today : tomorrow,
|
||||||
agencyFk: travelConfig.agencyFk,
|
agencyModeFk: travelConfig.agencyFk,
|
||||||
warehouseInFk: travelConfig.warehouseOutFk,
|
warehouseInFk: travelConfig.warehouseOutFk,
|
||||||
warehouseOutFk: travelConfig.warehouseInFk
|
warehouseOutFk: travelConfig.warehouseInFk
|
||||||
}, myOptions);
|
}, myOptions);
|
||||||
|
@ -63,7 +63,7 @@ module.exports = Self => {
|
||||||
|
|
||||||
if (tx) await tx.commit();
|
if (tx) await tx.commit();
|
||||||
|
|
||||||
return {travel, entry};
|
return entry;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
if (tx) await tx.rollback();
|
if (tx) await tx.rollback();
|
||||||
throw e;
|
throw e;
|
||||||
|
|
|
@ -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;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
Loading…
Reference in New Issue