diff --git a/services/loopback/common/methods/ticket/new.js b/services/loopback/common/methods/ticket/new.js index d73683027..0aa4aba41 100644 --- a/services/loopback/common/methods/ticket/new.js +++ b/services/loopback/common/methods/ticket/new.js @@ -43,8 +43,12 @@ module.exports = Self => { throw new UserError(`You can't create an order for a client that doesn't has tax data verified`); let clientFk = address.clientFk; + let agency; + if (params.agency) + agency = await Self.app.models.AgencyMode.findById(params.agencyModeFk); + else + agency = {code: null}; - let agency = await Self.app.models.Agency.findById(agencyModeFk); if (agency.code != 'refund') { let query = `SELECT vn.clientGetDebt(?, CURDATE()) AS debt`; let clientDebt = await Self.rawSql(query, [clientFk]);