fixed claim refund
gitea/salix/master This commit looks good
Details
gitea/salix/master This commit looks good
Details
This commit is contained in:
parent
7b40fe2942
commit
81072ce7e8
|
@ -30,7 +30,13 @@ module.exports = Self => {
|
||||||
{
|
{
|
||||||
relation: 'ticket',
|
relation: 'ticket',
|
||||||
scope: {
|
scope: {
|
||||||
fields: ['id', 'clientFk', 'warehouseFk', 'companyFk', 'addressFk']
|
fields: ['id', 'clientFk', 'warehouseFk', 'companyFk', 'addressFk'],
|
||||||
|
include: {
|
||||||
|
relation: 'address',
|
||||||
|
scope: {
|
||||||
|
fields: ['nickname']
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
@ -67,7 +73,7 @@ module.exports = Self => {
|
||||||
where: {description: 'comercial'}
|
where: {description: 'comercial'}
|
||||||
}, options);
|
}, options);
|
||||||
|
|
||||||
const agency = await models.AgencyMode.findOne({
|
const agencyMode = await models.AgencyMode.findOne({
|
||||||
where: {code: 'refund'}
|
where: {code: 'refund'}
|
||||||
}, options);
|
}, options);
|
||||||
|
|
||||||
|
@ -75,19 +81,23 @@ module.exports = Self => {
|
||||||
where: {code: 'DELIVERED'}
|
where: {code: 'DELIVERED'}
|
||||||
}, options);
|
}, options);
|
||||||
|
|
||||||
|
const zone = await models.Zone.findOne({
|
||||||
|
where: {agencyModeFk: agencyMode.id}
|
||||||
|
}, options);
|
||||||
|
|
||||||
const claim = await models.Claim.findOne(filter, options);
|
const claim = await models.Claim.findOne(filter, options);
|
||||||
const today = new Date();
|
const today = new Date();
|
||||||
|
|
||||||
const newRefundTicket = await models.Ticket.new(ctx, {
|
const newRefundTicket = await models.Ticket.create({
|
||||||
clientFk: claim.ticket().clientFk,
|
clientFk: claim.ticket().clientFk,
|
||||||
shipped: today,
|
shipped: today,
|
||||||
landed: today,
|
landed: today,
|
||||||
|
nickname: claim.ticket().address().nickname,
|
||||||
warehouseFk: claim.ticket().warehouseFk,
|
warehouseFk: claim.ticket().warehouseFk,
|
||||||
companyFk: claim.ticket().companyFk,
|
companyFk: claim.ticket().companyFk,
|
||||||
addressFk: claim.ticket().addressFk,
|
addressFk: claim.ticket().addressFk,
|
||||||
agencyModeFk: agency.id,
|
agencyModeFk: agencyMode.id,
|
||||||
userId: userId
|
zoneFk: zone.id
|
||||||
}, options);
|
}, options);
|
||||||
|
|
||||||
await saveObservation({
|
await saveObservation({
|
||||||
|
|
|
@ -2,7 +2,6 @@ const app = require('vn-loopback/server/server');
|
||||||
|
|
||||||
describe('claimBeginning', () => {
|
describe('claimBeginning', () => {
|
||||||
let ticket;
|
let ticket;
|
||||||
let refundTicketObservations;
|
|
||||||
let refundTicketSales;
|
let refundTicketSales;
|
||||||
let salesInsertedInClaimEnd;
|
let salesInsertedInClaimEnd;
|
||||||
|
|
||||||
|
@ -16,7 +15,7 @@ describe('claimBeginning', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('importToNewRefundTicket()', () => {
|
describe('importToNewRefundTicket()', () => {
|
||||||
it('should create a new ticket with negative sales, save an observation, update the state and insert the negative sales into claimEnd', async() => {
|
it('should create a new ticket with negative sales and insert the negative sales into claimEnd', async() => {
|
||||||
let ctxOfSalesAssistant = {req: {accessToken: {userId: 21}}};
|
let ctxOfSalesAssistant = {req: {accessToken: {userId: 21}}};
|
||||||
let claimId = 1;
|
let claimId = 1;
|
||||||
ticket = await app.models.ClaimBeginning.importToNewRefundTicket(ctxOfSalesAssistant, claimId);
|
ticket = await app.models.ClaimBeginning.importToNewRefundTicket(ctxOfSalesAssistant, claimId);
|
||||||
|
@ -24,14 +23,10 @@ describe('claimBeginning', () => {
|
||||||
await app.models.Ticket.findById(ticket.id);
|
await app.models.Ticket.findById(ticket.id);
|
||||||
|
|
||||||
refundTicketSales = await app.models.Sale.find({where: {ticketFk: ticket.id}});
|
refundTicketSales = await app.models.Sale.find({where: {ticketFk: ticket.id}});
|
||||||
refundTicketObservations = await app.models.TicketObservation.find({where: {ticketFk: ticket.id}});
|
|
||||||
let refundTicketState = await app.models.TicketState.findById(ticket.id);
|
|
||||||
salesInsertedInClaimEnd = await app.models.ClaimEnd.find({where: {claimFk: claimId}});
|
salesInsertedInClaimEnd = await app.models.ClaimEnd.find({where: {claimFk: claimId}});
|
||||||
|
|
||||||
expect(refundTicketSales.length).toEqual(1);
|
expect(refundTicketSales.length).toEqual(1);
|
||||||
expect(refundTicketSales[0].quantity).toEqual(-5);
|
expect(refundTicketSales[0].quantity).toEqual(-5);
|
||||||
expect(refundTicketObservations[0].description).toEqual('Reclama ticket: 11');
|
|
||||||
expect(refundTicketState.stateFk).toEqual(16);
|
|
||||||
expect(salesInsertedInClaimEnd[0].saleFk).toEqual(refundTicketSales[0].id);
|
expect(salesInsertedInClaimEnd[0].saleFk).toEqual(refundTicketSales[0].id);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue