refs #6287 apunta a ticket.new
gitea/salix/pipeline/head This commit looks good Details

This commit is contained in:
Javi Gallego 2023-10-19 14:14:44 +02:00
parent df51b0ca99
commit 699a24a20b
2 changed files with 22 additions and 24 deletions

View File

@ -90,24 +90,21 @@ module.exports = Self => {
where: {code: 'DELIVERED'}
}, myOptions);
const zone = await models.Zone.findOne({
where: {agencyModeFk: agencyMode.id}
}, myOptions);
const claim = await models.Claim.findOne(filter, myOptions);
const today = Date.vnNew();
const newRefundTicket = await models.Ticket.create({
clientFk: claim.ticket().clientFk,
ctx.args = {
clientId: claim.ticket().clientFk,
shipped: today,
landed: today,
nickname: claim.ticket().address().nickname,
warehouseFk: claim.ticket().warehouseFk,
companyFk: claim.ticket().companyFk,
addressFk: claim.ticket().addressFk,
agencyModeFk: agencyMode.id,
zoneFk: zone.id
}, myOptions);
warehouseId: claim.ticket().warehouseFk,
companyId: claim.ticket().companyFk,
addressId: claim.ticket().addressFk,
agencyModeId: agencyMode.id
};
const newRefundTicket = await models.Ticket.new(ctx, myOptions);
await models.TicketRefund.create({
refundTicketFk: newRefundTicket.id,

View File

@ -72,7 +72,7 @@ module.exports = Self => {
const [firstTicketId] = ticketsIds;
// eslint-disable-next-line max-len
refundTicket = await createTicketRefund(firstTicketId, now, refundAgencyMode, refoundZoneId, withWarehouse, myOptions);
refundTicket = await createTicketRefund(firstTicketId, now, refundAgencyMode, refoundZoneId, withWarehouse, myOptions, ctx);
for (const sale of sales) {
const createdSale = await models.Sale.create({
@ -103,7 +103,7 @@ module.exports = Self => {
const [firstTicketId] = ticketsIds;
// eslint-disable-next-line max-len
refundTicket = await createTicketRefund(firstTicketId, now, refundAgencyMode, refoundZoneId, withWarehouse, myOptions);
refundTicket = await createTicketRefund(firstTicketId, now, refundAgencyMode, refoundZoneId, withWarehouse, myOptions, ctx);
}
if (servicesIds && servicesIds.length > 0) {
@ -135,23 +135,24 @@ module.exports = Self => {
}
};
async function createTicketRefund(ticketId, now, refundAgencyMode, refoundZoneId, withWarehouse, myOptions) {
async function createTicketRefund(ticketId, now, refundAgencyMode, refoundZoneId, withWarehouse, myOptions, ctx) {
const models = Self.app.models;
const filter = {include: {relation: 'address'}};
const ticket = await models.Ticket.findById(ticketId, filter, myOptions);
const refundTicket = await models.Ticket.create({
clientFk: ticket.clientFk,
ctx.args = {
clientId: ticket.clientFk,
shipped: now,
addressFk: ticket.address().id,
agencyModeFk: refundAgencyMode.id,
addressId: ticket.address().id,
agencyModeId: refundAgencyMode.id,
nickname: ticket.address().nickname,
warehouseFk: withWarehouse ? ticket.warehouseFk : null,
companyFk: ticket.companyFk,
landed: now,
zoneFk: refoundZoneId
}, myOptions);
warehouseId: withWarehouse ? ticket.warehouseFk : null,
companyId: ticket.companyFk,
landed: now
};
const refundTicket = await models.Ticket.new(ctx, myOptions);
await models.TicketRefund.create({
refundTicketFk: refundTicket.id,