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 }); }