From 41d950eaef35ee735859476ae7b6b8e9d4195610 Mon Sep 17 00:00:00 2001 From: Gerard Date: Tue, 12 Feb 2019 14:23:04 +0100 Subject: [PATCH] hotfix errors creting tickets --- modules/agency/back/methods/agency/getShipped.js | 2 +- modules/ticket/back/methods/ticket/new.js | 10 +++++++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/modules/agency/back/methods/agency/getShipped.js b/modules/agency/back/methods/agency/getShipped.js index 04fa62a89..19179f766 100644 --- a/modules/agency/back/methods/agency/getShipped.js +++ b/modules/agency/back/methods/agency/getShipped.js @@ -23,6 +23,6 @@ module.exports = Self => { SELECT * FROM tmp.agencyHourGetShipped`; let result = await Self.rawSql(query, [params.landed, params.addressFk, params.agencyModeFk]); - return result[1][0].shipped; + return result[1][0].shipped || null; }; }; diff --git a/modules/ticket/back/methods/ticket/new.js b/modules/ticket/back/methods/ticket/new.js index c0404e084..a1a53ca3b 100644 --- a/modules/ticket/back/methods/ticket/new.js +++ b/modules/ticket/back/methods/ticket/new.js @@ -24,7 +24,7 @@ module.exports = Self => { Self.new = async(ctx, params, transaction) => { let address = await Self.app.models.Address.findOne({ where: {id: params.addressFk}, - fields: ['clientFk'], + fields: ['id', 'clientFk'], include: [ {relation: 'client', scope: { @@ -54,11 +54,15 @@ module.exports = Self => { throw new UserError(`You can't create a ticket for a client that has a debt`); } + let agency; + if (params.agencyModeFk) + agency = await Self.app.models.AgencyMode.findById(params.agencyModeFk); + if (!params.shipped && params.landed) { params.shipped = await Self.app.models.Agency.getShipped({ landed: params.landed, addressFk: address.id, - agencyModeFk: params.agencyModeFk + agencyModeFk: agency.agencyFk }); } @@ -66,7 +70,7 @@ module.exports = Self => { params.landed = await Self.app.models.Agency.getLanded({ shipped: params.shipped, addressFk: address.id, - agencyModeFk: params.agencyModeFk, + agencyModeFk: agency.agencyFk, warehouseFk: params.warehouseFk }); }