3979-abonarTicketsSinAlmacen #1910

Merged
jgallego merged 8 commits from 3979-abonarTicketsSinAlmacen into dev 2024-01-11 12:39:28 +00:00
8 changed files with 80 additions and 12 deletions

View File

@ -2911,8 +2911,7 @@ INSERT INTO `vn`.`workerConfig` (`id`, `businessUpdated`, `roleFk`, `payMethodFk
INSERT INTO `vn`.`ticketRefund`(`refundTicketFk`, `originalTicketFk`)
VALUES
(1, 12),
(8, 10);
(24, 7);
INSERT INTO `vn`.`deviceProductionModels` (`code`)
VALUES

View File

@ -225,7 +225,7 @@ describe('Ticket Edit sale path', () => {
});
it('should show error trying to delete a ticket with a refund', async() => {
await page.accessToSearchResult('16');
await page.accessToSearchResult('6');
await page.waitToClick(selectors.ticketDescriptor.moreMenu);
await page.waitToClick(selectors.ticketDescriptor.moreMenuDeleteTicket);
await page.waitToClick(selectors.globalItems.acceptButton);

View File

@ -78,7 +78,7 @@ module.exports = Self => {
const sales = await models.Sale.find(filterTicket, myOptions);
const salesIds = sales.map(sale => sale.id);
const clonedTickets = await models.Sale.clone(ctx, salesIds, servicesIds, null, false, false, myOptions);
const clonedTickets = await models.Sale.clone(ctx, salesIds, servicesIds, null, false, myOptions);
const clonedTicketIds = [];
for (const clonedTicket of clonedTickets) {

View File

@ -1,5 +1,5 @@
module.exports = Self => {
Self.clone = async(ctx, salesIds, servicesIds, withWarehouse, group, negative, options) => {
Self.clone = async(ctx, salesIds, servicesIds, withWarehouse, negative, options) => {
const models = Self.app.models;
const myOptions = {};
let tx;
@ -28,8 +28,6 @@ module.exports = Self => {
const mappedTickets = new Map();
if (group) ticketsIds = [ticketsIds[0]];
for (let ticketId of ticketsIds) {
const newTicket = await createTicket(
ctx,
@ -109,7 +107,10 @@ module.exports = Self => {
const newTicket = await models.Ticket.new(ctx, myOptions);
if (negative) {
const ticketRefund = await models.TicketRefund.findOne({
where: {refundTicketFk: ticketId}
}, myOptions);
if (negative && (withWarehouse || !ticketRefund?.id)) {
await models.TicketRefund.create({
originalTicketFk: ticketId,
refundTicketFk: newTicket.id

View File

@ -47,7 +47,6 @@ module.exports = Self => {
salesIds,
servicesIds,
withWarehouse,
false,
true,
myOptions
);

View File

@ -0,0 +1,70 @@
const models = require('vn-loopback/server/server').models;
const LoopBackContext = require('loopback-context');
describe('Ticket cloning - clone function', () => {
let ctx;
let options;
let tx;
beforeEach(async() => {
ctx = {
req: {
accessToken: {userId: 9},
headers: {origin: 'http://localhost'}
},
args: {}
};
spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({
active: ctx.req
});
options = {transaction: tx};
tx = await models.Sale.beginTransaction({});
options.transaction = tx;
});
afterEach(async() => {
await tx.rollback();
});
it('should create new tickets with cloned sales with warehouse', async() => {
const salesIds = [1, 2, 3];
const servicesIds = [];
const withWarehouse = true;
const negative = false;
const newTickets = await models.Sale.clone(ctx, salesIds, servicesIds, withWarehouse, negative, options);
expect(newTickets).toBeDefined();
expect(newTickets.length).toBeGreaterThan(0);
});
it('should handle negative quantities correctly', async() => {
const negative = true;
const salesIds = [7, 8];
const servicesIds = [];
const newTickets = await models.Sale.clone(ctx, salesIds, servicesIds, false, negative, options);
for (const ticket of newTickets) {
const sales = await models.Sale.find({where: {ticketFk: ticket.id}}, options);
sales.forEach(sale => {
expect(sale.quantity).toBeLessThan(0);
});
}
});
it('should create new components and services for cloned tickets', async() => {
const servicesIds = [2];
const salesIds = [5];
const newTickets = await models.Sale.clone(ctx, salesIds, servicesIds, false, false, options);
for (const ticket of newTickets) {
const sale = await models.Sale.findOne({where: {ticketFk: ticket.id}}, options);
const components = await models.SaleComponent.find({where: {saleFk: sale.id}}, options);
const services = await models.TicketService.find({where: {ticketFk: ticket.id}}, options);
expect(components.length).toBeGreaterThan(0);
expect(services.length).toBeGreaterThan(0);
}
});
});

View File

@ -3,7 +3,6 @@ const LoopBackContext = require('loopback-context');
describe('ticket setDeleted()', () => {
const userId = 1106;
const employeeUser = 1110;
const activeCtx = {
accessToken: {userId: userId},
};
@ -118,7 +117,7 @@ describe('ticket setDeleted()', () => {
return value;
};
const ticketId = 12;
const ticketId = 7;
await models.Ticket.setDeleted(ctx, ticketId, options);
await tx.rollback();

View File

@ -132,7 +132,7 @@ describe('sale model ', () => {
spyOn(LoopBackContext, 'getCurrentContext').and.returnValue(getActiveCtx(9));
const tx = await models.Sale.beginTransaction({});
const saleId = 13;
const saleId = 32;
const newQuantity = -10;
try {