5914-transferInvoiceOut #1761

Merged
jorgep merged 55 commits from 5914-transferInvoiceOut into dev 2023-10-26 12:39:11 +00:00
1 changed files with 26 additions and 31 deletions
Showing only changes of commit 50543963c1 - Show all commits

View File

@ -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
Outdated
Review
if(group) ticketsIds = ticketsIds[0]

                for (let ticketId of ticketsIds) {
                    await createTicketRefund(
                        ticketId,
                        withWarehouse,
                        refundTickets,
                        mappedTickets,
                        now,
                        myOptions
                    );
                }

y te ahorres fer if y else

``` if(group) ticketsIds = ticketsIds[0] for (let ticketId of ticketsIds) { await createTicketRefund( ticketId, withWarehouse, refundTickets, mappedTickets, now, myOptions ); } ``` y te ahorres fer if y else
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
Review

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
Outdated
Review

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);
}
};