diff --git a/loopback/locale/es.json b/loopback/locale/es.json index 9d4504ce2..e275cbb93 100644 --- a/loopback/locale/es.json +++ b/loopback/locale/es.json @@ -81,5 +81,6 @@ "This client can't be invoiced": "Este cliente no puede ser facturado", "This ticket can't be invoiced": "Este ticket no puede ser facturado", "That item is not available on that day": "El item no esta disponible para esa fecha", - "That item doesn't exists": "That item doesn't exists" + "That item doesn't exists": "That item doesn't exists", + "You cannot add services to an invoiced ticket": "No puedes aƱadir servicios a un ticket facturado" } \ No newline at end of file diff --git a/modules/ticket/back/models/ticket-service.js b/modules/ticket/back/models/ticket-service.js new file mode 100644 index 000000000..3f54a960e --- /dev/null +++ b/modules/ticket/back/models/ticket-service.js @@ -0,0 +1,12 @@ +const UserError = require('vn-loopback/util/user-error'); + +module.exports = Self => { + Self.observe('before save', async ctx => { + if (ctx.isNewInstance) { + let ticketId = ctx.instance.ticketFk; + let ticket = await Self.app.models.Ticket.findById(ticketId); + if (ticket.refFk) + throw new UserError('You cannot add services to an invoiced ticket'); + } + }); +};