diff --git a/db/routines/vn/procedures/invoiceOut_newFromAddress.sql b/db/routines/vn/procedures/invoiceOut_newFromAddress.sql index d0ab90a3e..495ace608 100644 --- a/db/routines/vn/procedures/invoiceOut_newFromAddress.sql +++ b/db/routines/vn/procedures/invoiceOut_newFromAddress.sql @@ -39,8 +39,8 @@ BEGIN AND t.refFk IS NULL AND t.companyFk = vCompanyFk AND t.shipped BETWEEN - util.firstDayOfYear(vMaxShipped - INTERVAL 1 YEAR) AND - util.dayend(vMaxShipped); + util.firstDayOfYear(vMaxShipped - INTERVAL 1 YEAR) + AND util.dayend(vMaxShipped); CALL invoiceOut_new(vSerial, util.VN_CURDATE(), vTaxArea, vInvoiceId); diff --git a/modules/invoiceOut/back/methods/invoiceOut/createManualInvoice.js b/modules/invoiceOut/back/methods/invoiceOut/createManualInvoice.js index 32445a8df..a06128848 100644 --- a/modules/invoiceOut/back/methods/invoiceOut/createManualInvoice.js +++ b/modules/invoiceOut/back/methods/invoiceOut/createManualInvoice.js @@ -13,7 +13,7 @@ module.exports = Self => { { arg: 'addressFk', type: 'any', - description: 'The consignatary address id' + description: 'The address id' }, { arg: 'ticketFk', @@ -72,8 +72,12 @@ module.exports = Self => { let query; try { if (ticketFk) { - const ticket = await models.Ticket.findById(ticketFk, null, myOptions); - const company = await models.Company.findById(ticket.companyFk, null, myOptions); + const ticket = await models.Ticket.findById(ticketFk, { + fields: ['clientFk', 'companyFk', 'shipped', 'refFk', 'totalWithVat'] + }, myOptions); + const company = await models.Company.findById(ticket.companyFk, { + fields: ['code'] + }, myOptions); clientFk = ticket.clientFk; maxShipped = ticket.shipped; @@ -93,7 +97,9 @@ module.exports = Self => { throw new UserError(`Max shipped required`); if (addressFk) { - const address = await models.Address.findById(addressFk, null, myOptions); + const address = await models.Address.findById(addressFk, { + fields: ['clientFk'] + }, myOptions); if (clientFk && clientFk !== address.clientFk) throw new UserError('The provided clientFk does not match');