This commit is contained in:
parent
09dbd29086
commit
8bb8b8cfba
|
@ -24,7 +24,6 @@ module.exports = function(Self) {
|
|||
});
|
||||
|
||||
Self.makeInvoice = async(ctx, ticketsIds, options) => {
|
||||
const userId = ctx.req.accessToken.userId;
|
||||
const models = Self.app.models;
|
||||
const date = Date.vnNew();
|
||||
date.setHours(0, 0, 0, 0);
|
||||
|
@ -42,6 +41,7 @@ module.exports = function(Self) {
|
|||
|
||||
let serial;
|
||||
let invoiceId;
|
||||
let invoiceOut;
|
||||
try {
|
||||
const tickets = await models.Ticket.find({
|
||||
where: {
|
||||
|
@ -92,6 +92,11 @@ module.exports = function(Self) {
|
|||
if (serial != 'R' && invoiceId)
|
||||
await Self.rawSql('CALL invoiceOutBooking(?)', [invoiceId], myOptions);
|
||||
|
||||
invoiceOut = await models.InvoiceOut.findById(invoiceId, {
|
||||
include: {
|
||||
relation: 'client'
|
||||
}
|
||||
}, myOptions);
|
||||
if (tx) await tx.commit();
|
||||
} catch (e) {
|
||||
if (tx) await tx.rollback();
|
||||
|
@ -102,12 +107,6 @@ module.exports = function(Self) {
|
|||
await models.InvoiceOut.createPdf(ctx, invoiceId);
|
||||
|
||||
if (invoiceId) {
|
||||
const invoiceOut = await models.InvoiceOut.findById(invoiceId, {
|
||||
include: {
|
||||
relation: 'client'
|
||||
}
|
||||
});
|
||||
|
||||
ctx.args = {
|
||||
reference: invoiceOut.ref,
|
||||
recipientId: invoiceOut.clientFk,
|
||||
|
|
|
@ -1,11 +1,14 @@
|
|||
const models = require('vn-loopback/server/server').models;
|
||||
const LoopBackContext = require('loopback-context');
|
||||
|
||||
describe('ticket makeInvoice()', () => {
|
||||
fdescribe('ticket makeInvoice()', () => {
|
||||
const userId = 19;
|
||||
const ticketId = 11;
|
||||
const clientId = 1102;
|
||||
const activeCtx = {
|
||||
getLocale: () => {
|
||||
return 'en';
|
||||
},
|
||||
accessToken: {userId: userId},
|
||||
headers: {origin: 'http://localhost:5000'},
|
||||
};
|
||||
|
@ -67,6 +70,7 @@ describe('ticket makeInvoice()', () => {
|
|||
it('should invoice a ticket, then try again to fail', async() => {
|
||||
const invoiceOutModel = models.InvoiceOut;
|
||||
spyOn(invoiceOutModel, 'createPdf');
|
||||
spyOn(invoiceOutModel, 'invoiceEmail');
|
||||
|
||||
const tx = await models.Ticket.beginTransaction({});
|
||||
|
||||
|
@ -90,6 +94,7 @@ describe('ticket makeInvoice()', () => {
|
|||
it('should success to invoice a ticket', async() => {
|
||||
const invoiceOutModel = models.InvoiceOut;
|
||||
spyOn(invoiceOutModel, 'createPdf');
|
||||
spyOn(invoiceOutModel, 'invoiceEmail');
|
||||
|
||||
const tx = await models.Ticket.beginTransaction({});
|
||||
|
||||
|
|
Loading…
Reference in New Issue