5914-transferInvoiceOut #1761
|
@ -3,6 +3,7 @@ module.exports = Self => {
|
|||
const models = Self.app.models;
|
||||
const myOptions = {};
|
||||
let tx;
|
||||
const refundTickets = [];
|
||||
|
||||
if (typeof options == 'object')
|
||||
Object.assign(myOptions, options);
|
||||
|
@ -25,22 +26,19 @@ module.exports = Self => {
|
|||
const sales = await models.Sale.find(salesFilter, myOptions);
|
||||
let ticketsIds = [...new Set(sales.map(sale => sale.ticketFk))];
|
||||
|
||||
const refundTickets = [];
|
||||
const mappedTickets = new Map();
|
||||
const now = Date.vnNew();
|
||||
|
||||
if (group) ticketsIds = [ticketsIds[0]];
|
||||
jorgep marked this conversation as resolved
Outdated
|
||||
|
||||
for (let ticketId in ticketsIds) {
|
||||
await createTicketRefund(
|
||||
for (let ticketId of ticketsIds) {
|
||||
const ticketRefund = await createTicketRefund(
|
||||
ctx,
|
||||
ticketsIds[ticketId],
|
||||
ticketId,
|
||||
withWarehouse,
|
||||
refundTickets,
|
||||
now,
|
||||
myOptions
|
||||
);
|
||||
jorgep marked this conversation as resolved
alexm
commented
Aqui Aqui
|
||||
mappedTickets.set(ticketsIds[ticketId], refundTickets[ticketId].id);
|
||||
refundTickets.push(ticketRefund);
|
||||
mappedTickets.set(ticketId, ticketRefund.id);
|
||||
}
|
||||
|
||||
for (const sale of sales) {
|
||||
|
@ -89,28 +87,25 @@ module.exports = Self => {
|
|||
if (tx) await tx.rollback();
|
||||
throw e;
|
||||
}
|
||||
|
||||
async function createTicketRefund(
|
||||
jorgep marked this conversation as resolved
Outdated
alexm
commented
Pero no quedarem en que clone.js no debia tindre res relacionat en refund Pero no quedarem en que clone.js no debia tindre res relacionat en refund
|
||||
ctx,
|
||||
ticketId,
|
||||
withWarehouse,
|
||||
myOptions
|
||||
) {
|
||||
const models = Self.app.models;
|
||||
const now = Date.vnNew();
|
||||
|
||||
const ticket = await models.Ticket.findById(ticketId, null, myOptions);
|
||||
ctx.args.clientId = ticket.clientFk;
|
||||
ctx.args.shipped = now;
|
||||
ctx.args.landed = now;
|
||||
ctx.args.warehouseId = withWarehouse ? ticket.warehouseFk : null;
|
||||
ctx.args.companyId = ticket.companyFk;
|
||||
ctx.args.addressId = ticket.addressFk;
|
||||
|
||||
return models.Ticket.new(ctx, myOptions);
|
||||
}
|
||||
};
|
||||
|
||||
async function createTicketRefund(
|
||||
ctx,
|
||||
ticketId,
|
||||
withWarehouse,
|
||||
refundTickets,
|
||||
now,
|
||||
myOptions
|
||||
) {
|
||||
const models = Self.app.models;
|
||||
|
||||
const ticket = await models.Ticket.findById(ticketId, myOptions);
|
||||
ctx.args.clientId = ticket.clientFk;
|
||||
ctx.args.shipped = now;
|
||||
ctx.args.landed = now;
|
||||
ctx.args.warehouseId = withWarehouse ? ticket.warehouseFk : null;
|
||||
ctx.args.companyId = ticket.companyFk;
|
||||
ctx.args.addressId = ticket.addressFk;
|
||||
|
||||
const refundTicket = await models.Ticket.new(ctx, myOptions);
|
||||
|
||||
refundTickets.push(refundTicket);
|
||||
}
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue
y te ahorres fer if y else