#6492 refactor vn2008 procedures #2159
|
@ -3068,8 +3068,6 @@ INSERT INTO `vn`.`cmr` (id,truckPlate,observations,senderInstruccions,paymentIns
|
||||||
UPDATE vn.department
|
UPDATE vn.department
|
||||||
SET workerFk = null;
|
SET workerFk = null;
|
||||||
|
|
||||||
-- NEW WAREHOUSE
|
|
||||||
|
|
||||||
INSERT INTO vn.packaging
|
INSERT INTO vn.packaging
|
||||||
VALUES('--', 2745600.00, 100.00, 120.00, 220.00, 0.00, 1, '2001-01-01 00:00:00.000', NULL, NULL, NULL, 0.00, 16, 0.00, 0, NULL, 0.00, NULL, NULL, 0, NULL, 0, 0);
|
VALUES('--', 2745600.00, 100.00, 120.00, 220.00, 0.00, 1, '2001-01-01 00:00:00.000', NULL, NULL, NULL, 0.00, 16, 0.00, 0, NULL, 0.00, NULL, NULL, 0, NULL, 0, 0);
|
||||||
|
|
||||||
|
@ -3734,6 +3732,9 @@ INSERT INTO vn.report (name) VALUES ('LabelCollection');
|
||||||
INSERT INTO vn.parkingLog(originFk, userFk, `action`, creationDate, description, changedModel,oldInstance, newInstance, changedModelId, changedModelValue)
|
INSERT INTO vn.parkingLog(originFk, userFk, `action`, creationDate, description, changedModel,oldInstance, newInstance, changedModelId, changedModelValue)
|
||||||
VALUES(1, 18, 'update', util.VN_CURDATE(), NULL, 'SaleGroup', '{"parkingFk":null}', '{"parkingFk":1}', 1, NULL);
|
VALUES(1, 18, 'update', util.VN_CURDATE(), NULL, 'SaleGroup', '{"parkingFk":null}', '{"parkingFk":1}', 1, NULL);
|
||||||
|
|
||||||
|
INSERT INTO vn.ticketLog (originFk,userFk,`action`,creationDate,changedModel,newInstance,changedModelId,changedModelValue)
|
||||||
|
VALUES (18,9,'insert','2001-01-01 11:01:00.000','Ticket','{"isDeleted":true}',45,'Super Man');
|
||||||
|
|
||||||
INSERT INTO `vn`.`accountReconciliation` (
|
INSERT INTO `vn`.`accountReconciliation` (
|
||||||
supplierAccountFk,
|
supplierAccountFk,
|
||||||
operationDated,
|
operationDated,
|
||||||
|
|
|
@ -9,8 +9,8 @@ describe('ticketLog getChanges()', () => {
|
||||||
it('should return the changes in the sales of a ticket', async() => {
|
it('should return the changes in the sales of a ticket', async() => {
|
||||||
const ticketId = 16;
|
const ticketId = 16;
|
||||||
|
|
||||||
const changues = await models.TicketLog.getChanges(ctx, ticketId);
|
const changes = await models.TicketLog.getChanges(ctx, ticketId);
|
||||||
|
|
||||||
expect(changues).toContain(`Change quantity`);
|
expect(changes).toContain(`Change quantity`);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -29,6 +29,15 @@ module.exports = Self => {
|
||||||
if (typeof options == 'object')
|
if (typeof options == 'object')
|
||||||
Object.assign(myOptions, options);
|
Object.assign(myOptions, options);
|
||||||
|
|
||||||
|
const ticketLog = await models.TicketLog.findOne({
|
||||||
|
fields: ['originFk', 'creationDate', 'newInstance'],
|
||||||
|
where: {
|
||||||
|
originFk: id,
|
||||||
|
newInstance: {like: '%"isDeleted":true%'}
|
||||||
|
},
|
||||||
|
order: 'creationDate DESC'
|
||||||
|
}, myOptions);
|
||||||
|
|
||||||
const ticket = await models.Ticket.findById(id, {
|
const ticket = await models.Ticket.findById(id, {
|
||||||
include: [{
|
include: [{
|
||||||
relation: 'client',
|
relation: 'client',
|
||||||
|
@ -39,10 +48,9 @@ module.exports = Self => {
|
||||||
}, myOptions);
|
}, myOptions);
|
||||||
|
|
||||||
const now = Date.vnNew();
|
const now = Date.vnNew();
|
||||||
const maxDate = new Date(ticket.updated);
|
const maxDate = new Date(ticketLog?.creationDate);
|
||||||
maxDate.setHours(maxDate.getHours() + 1);
|
maxDate.setHours(maxDate.getHours() + 1);
|
||||||
|
if (!ticketLog || now > maxDate)
|
||||||
if (now > maxDate)
|
|
||||||
throw new UserError(`You can only restore a ticket within the first hour after deletion`);
|
throw new UserError(`You can only restore a ticket within the first hour after deletion`);
|
||||||
|
|
||||||
// Send notification to salesPerson
|
// Send notification to salesPerson
|
||||||
|
|
|
@ -4,7 +4,7 @@ const models = app.models;
|
||||||
|
|
||||||
describe('ticket restore()', () => {
|
describe('ticket restore()', () => {
|
||||||
const employeeUser = 1110;
|
const employeeUser = 1110;
|
||||||
const ticketId = 18;
|
const ticketId = 9;
|
||||||
const activeCtx = {
|
const activeCtx = {
|
||||||
accessToken: {userId: employeeUser},
|
accessToken: {userId: employeeUser},
|
||||||
headers: {
|
headers: {
|
||||||
|
@ -30,10 +30,21 @@ describe('ticket restore()', () => {
|
||||||
try {
|
try {
|
||||||
const options = {transaction: tx};
|
const options = {transaction: tx};
|
||||||
const ticket = await models.Ticket.findById(ticketId, null, options);
|
const ticket = await models.Ticket.findById(ticketId, null, options);
|
||||||
|
|
||||||
await ticket.updateAttributes({
|
await ticket.updateAttributes({
|
||||||
isDeleted: true,
|
isDeleted: true,
|
||||||
updated: now
|
updated: now
|
||||||
}, options);
|
}, options);
|
||||||
|
|
||||||
|
await models.TicketLog.create({
|
||||||
|
originFk: ticketId,
|
||||||
|
userFk: employeeUser,
|
||||||
|
action: 'update',
|
||||||
|
changedModel: 'Ticket',
|
||||||
|
creationDate: new Date('2001-01-01 10:59:00'),
|
||||||
|
newInstance: '{"isDeleted":true}'
|
||||||
|
}, options);
|
||||||
|
|
||||||
await app.models.Ticket.restore(ctx, ticketId, options);
|
await app.models.Ticket.restore(ctx, ticketId, options);
|
||||||
await tx.rollback();
|
await tx.rollback();
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
@ -52,11 +63,21 @@ describe('ticket restore()', () => {
|
||||||
const options = {transaction: tx};
|
const options = {transaction: tx};
|
||||||
|
|
||||||
const ticketBeforeUpdate = await models.Ticket.findById(ticketId, null, options);
|
const ticketBeforeUpdate = await models.Ticket.findById(ticketId, null, options);
|
||||||
|
|
||||||
await ticketBeforeUpdate.updateAttributes({
|
await ticketBeforeUpdate.updateAttributes({
|
||||||
isDeleted: true,
|
isDeleted: true,
|
||||||
updated: now
|
updated: now
|
||||||
}, options);
|
}, options);
|
||||||
|
|
||||||
|
await models.TicketLog.create({
|
||||||
|
originFk: ticketId,
|
||||||
|
userFk: employeeUser,
|
||||||
|
action: 'update',
|
||||||
|
changedModel: 'Ticket',
|
||||||
|
creationDate: new Date('2001-01-01 11:01:00'),
|
||||||
|
newInstance: '{"isDeleted":true}'
|
||||||
|
}, options);
|
||||||
|
|
||||||
const ticketAfterUpdate = await models.Ticket.findById(ticketId, null, options);
|
const ticketAfterUpdate = await models.Ticket.findById(ticketId, null, options);
|
||||||
|
|
||||||
expect(ticketAfterUpdate.isDeleted).toBeTruthy();
|
expect(ticketAfterUpdate.isDeleted).toBeTruthy();
|
||||||
|
@ -65,7 +86,9 @@ describe('ticket restore()', () => {
|
||||||
const ticketAfterRestore = await models.Ticket.findById(ticketId, null, options);
|
const ticketAfterRestore = await models.Ticket.findById(ticketId, null, options);
|
||||||
|
|
||||||
const fullYear = now.getFullYear();
|
const fullYear = now.getFullYear();
|
||||||
|
|
||||||
const shippedFullYear = ticketAfterRestore.shipped.getFullYear();
|
const shippedFullYear = ticketAfterRestore.shipped.getFullYear();
|
||||||
|
|
||||||
const landedFullYear = ticketAfterRestore.landed.getFullYear();
|
const landedFullYear = ticketAfterRestore.landed.getFullYear();
|
||||||
|
|
||||||
expect(ticketAfterRestore.isDeleted).toBeFalsy();
|
expect(ticketAfterRestore.isDeleted).toBeFalsy();
|
||||||
|
|
|
@ -5,5 +5,40 @@
|
||||||
"mysql": {
|
"mysql": {
|
||||||
"table": "ticketLog"
|
"table": "ticketLog"
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
"properties": {
|
||||||
|
"id": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"originFk": {
|
||||||
|
"type": "number"
|
||||||
|
},
|
||||||
|
"userFk": {
|
||||||
|
"type":"number"
|
||||||
|
},
|
||||||
|
"action": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"creationDate": {
|
||||||
|
"type": "date"
|
||||||
|
},
|
||||||
|
"description": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"changedModel": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"oldInstance": {
|
||||||
|
"type": "any"
|
||||||
|
},
|
||||||
|
"newInstance": {
|
||||||
|
"type": "any"
|
||||||
|
},
|
||||||
|
"changedModelId": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"changedModelValue": {
|
||||||
|
"type": "string"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,6 +35,29 @@ class Controller extends Section {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const filter = {
|
||||||
|
fields: ['originFk', 'creationDate', 'newInstance'],
|
||||||
|
where: {
|
||||||
|
originFk: value,
|
||||||
|
newInstance: {like: '%"isDeleted":true%'}
|
||||||
|
},
|
||||||
|
order: 'creationDate DESC'
|
||||||
|
};
|
||||||
|
this.$http.get(`TicketLogs/findOne`, {filter})
|
||||||
|
.then(res => {
|
||||||
|
if (res && res.data) {
|
||||||
|
const now = Date.vnNew();
|
||||||
|
const maxDate = new Date(res.data.creationDate);
|
||||||
|
maxDate.setHours(maxDate.getHours() + 1);
|
||||||
|
if (now <= maxDate)
|
||||||
|
return this.canRestoreTicket = true;
|
||||||
|
}
|
||||||
|
this.canRestoreTicket = false;
|
||||||
|
})
|
||||||
|
.catch(() => {
|
||||||
|
this.canRestoreTicket = false;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
get isInvoiced() {
|
get isInvoiced() {
|
||||||
|
@ -171,15 +194,6 @@ class Controller extends Section {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
get canRestoreTicket() {
|
|
||||||
const isDeleted = this.ticket.isDeleted;
|
|
||||||
const now = Date.vnNew();
|
|
||||||
const maxDate = new Date(this.ticket.updated);
|
|
||||||
maxDate.setHours(maxDate.getHours() + 1);
|
|
||||||
|
|
||||||
return isDeleted && (now <= maxDate);
|
|
||||||
}
|
|
||||||
|
|
||||||
restoreTicket() {
|
restoreTicket() {
|
||||||
return this.$http.post(`Tickets/${this.id}/restore`)
|
return this.$http.post(`Tickets/${this.id}/restore`)
|
||||||
.then(() => this.reload())
|
.then(() => this.reload())
|
||||||
|
|
|
@ -40,29 +40,6 @@ describe('Ticket Component vnTicketDescriptorMenu', () => {
|
||||||
controller.ticket = ticket;
|
controller.ticket = ticket;
|
||||||
}));
|
}));
|
||||||
|
|
||||||
describe('canRestoreTicket() getter', () => {
|
|
||||||
it('should return true for a ticket deleted within the last hour', () => {
|
|
||||||
controller.ticket.isDeleted = true;
|
|
||||||
controller.ticket.updated = Date.vnNew();
|
|
||||||
|
|
||||||
const result = controller.canRestoreTicket;
|
|
||||||
|
|
||||||
expect(result).toBeTruthy();
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should return false for a ticket deleted more than one hour ago', () => {
|
|
||||||
const pastHour = Date.vnNew();
|
|
||||||
pastHour.setHours(pastHour.getHours() - 2);
|
|
||||||
|
|
||||||
controller.ticket.isDeleted = true;
|
|
||||||
controller.ticket.updated = pastHour;
|
|
||||||
|
|
||||||
const result = controller.canRestoreTicket;
|
|
||||||
|
|
||||||
expect(result).toBeFalsy();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('addTurn()', () => {
|
describe('addTurn()', () => {
|
||||||
it('should make a query and call $.addTurn.hide() and vnApp.showSuccess()', () => {
|
it('should make a query and call $.addTurn.hide() and vnApp.showSuccess()', () => {
|
||||||
controller.$.addTurn = {hide: () => {}};
|
controller.$.addTurn = {hide: () => {}};
|
||||||
|
@ -105,20 +82,6 @@ describe('Ticket Component vnTicketDescriptorMenu', () => {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('restoreTicket()', () => {
|
|
||||||
it('should make a query to restore the ticket and call vnApp.showSuccess()', () => {
|
|
||||||
jest.spyOn(controller, 'reload').mockReturnThis();
|
|
||||||
jest.spyOn(controller.vnApp, 'showSuccess');
|
|
||||||
|
|
||||||
$httpBackend.expectPOST(`Tickets/${ticket.id}/restore`).respond();
|
|
||||||
controller.restoreTicket();
|
|
||||||
$httpBackend.flush();
|
|
||||||
|
|
||||||
expect(controller.reload).toHaveBeenCalled();
|
|
||||||
expect(controller.vnApp.showSuccess).toHaveBeenCalled();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('showPdfDeliveryNote()', () => {
|
describe('showPdfDeliveryNote()', () => {
|
||||||
it('should open a new window showing a delivery note PDF document', () => {
|
it('should open a new window showing a delivery note PDF document', () => {
|
||||||
jest.spyOn(window, 'open').mockReturnThis();
|
jest.spyOn(window, 'open').mockReturnThis();
|
||||||
|
|
Loading…
Reference in New Issue