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',
|
||||
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'}
|
||||
}, options);
|
||||
|
||||
const agency = await models.AgencyMode.findOne({
|
||||
const agencyMode = await models.AgencyMode.findOne({
|
||||
where: {code: 'refund'}
|
||||
}, options);
|
||||
|
||||
|
@ -75,19 +81,23 @@ module.exports = Self => {
|
|||
where: {code: 'DELIVERED'}
|
||||
}, options);
|
||||
|
||||
const zone = await models.Zone.findOne({
|
||||
where: {agencyModeFk: agencyMode.id}
|
||||
}, options);
|
||||
|
||||
const claim = await models.Claim.findOne(filter, options);
|
||||
const today = new Date();
|
||||
|
||||
const newRefundTicket = await models.Ticket.new(ctx, {
|
||||
const newRefundTicket = await models.Ticket.create({
|
||||
clientFk: 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: agency.id,
|
||||
userId: userId
|
||||
agencyModeFk: agencyMode.id,
|
||||
zoneFk: zone.id
|
||||
}, options);
|
||||
|
||||
await saveObservation({
|
||||
|
|
|
@ -2,7 +2,6 @@ const app = require('vn-loopback/server/server');
|
|||
|
||||
describe('claimBeginning', () => {
|
||||
let ticket;
|
||||
let refundTicketObservations;
|
||||
let refundTicketSales;
|
||||
let salesInsertedInClaimEnd;
|
||||
|
||||
|
@ -16,7 +15,7 @@ describe('claimBeginning', () => {
|
|||
});
|
||||
|
||||
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 claimId = 1;
|
||||
ticket = await app.models.ClaimBeginning.importToNewRefundTicket(ctxOfSalesAssistant, claimId);
|
||||
|
@ -24,14 +23,10 @@ describe('claimBeginning', () => {
|
|||
await app.models.Ticket.findById(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}});
|
||||
|
||||
expect(refundTicketSales.length).toEqual(1);
|
||||
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);
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue