refs #4131 changeStateRefactor #1753
|
@ -1,5 +1,6 @@
|
||||||
UPDATE `salix`.`ACL`
|
UPDATE `salix`.`ACL`
|
||||||
SET property = 'state'
|
SET property = 'state',
|
||||||
|
model = 'Ticket'
|
||||||
WHERE property = 'changeState';
|
WHERE property = 'changeState';
|
||||||
|
|
||||||
REVOKE INSERT, UPDATE, DELETE ON `vn`.`ticketTracking` FROM 'productionboss'@;
|
REVOKE INSERT, UPDATE, DELETE ON `vn`.`ticketTracking` FROM 'productionboss'@;
|
||||||
|
|
|
@ -44,6 +44,40 @@ module.exports = Self => {
|
||||||
myOptions.transaction = tx;
|
myOptions.transaction = tx;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
for (const ticketId of tickets) {
|
||||||
|
const ticketState = await models.TicketState.findOne(
|
||||||
|
{where: {ticketFk: ticketId},
|
||||||
|
fields: ['alertLevel']
|
||||||
|
}, myOptions);
|
||||||
|
|
||||||
|
const packedAlertLevel = await models.AlertLevel.findOne({where: {code: 'PACKED'},
|
||||||
|
fields: ['id']
|
||||||
|
}, myOptions);
|
||||||
|
|
||||||
|
if (!ticketState)
|
||||||
|
throw new UserError('Ticket does not exist');
|
||||||
|
if (ticketState.alertLevel < packedAlertLevel.id)
|
||||||
|
throw new UserError('This ticket cannot be signed because it has not been boxed');
|
||||||
|
if (await gestDocExists(ticketId))
|
||||||
|
throw new UserError('Ticket is already signed');
|
||||||
|
|
||||||
|
if (location) setLocation(ticketId);
|
||||||
|
if (!gestDocCreated) await createGestDoc(ticketId);
|
||||||
|
await models.TicketDms.create({ticketFk: ticketId, dmsFk: dms[0].id}, myOptions);
|
||||||
|
const ticket = await models.Ticket.findById(ticketId, null, myOptions);
|
||||||
|
await ticket.updateAttribute('isSigned', true, myOptions);
|
||||||
|
const params = {ticketFk: ticketId, code: 'DELIVERED'};
|
||||||
|
await models.Ticket.state(ctx, params, options);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (tx) await tx.commit();
|
||||||
|
return;
|
||||||
|
} catch (e) {
|
||||||
|
if (tx) await tx.rollback();
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
|
||||||
async function setLocation(ticketId) {
|
async function setLocation(ticketId) {
|
||||||
await models.Delivery.create({
|
await models.Delivery.create({
|
||||||
ticketFk: ticketId,
|
ticketFk: ticketId,
|
||||||
|
@ -103,41 +137,9 @@ module.exports = Self => {
|
||||||
description: `Firma del cliente - Ruta ${ticket.route().id}`,
|
description: `Firma del cliente - Ruta ${ticket.route().id}`,
|
||||||
hasFile: false
|
hasFile: false
|
||||||
};
|
};
|
||||||
|
|
||||||
dms = await models.Dms.uploadFile(ctxUploadFile, myOptions);
|
dms = await models.Dms.uploadFile(ctxUploadFile, myOptions);
|
||||||
gestDocCreated = true;
|
gestDocCreated = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
|
||||||
for (const ticketId of tickets) {
|
|
||||||
const ticketState = await models.TicketState.findOne(
|
|
||||||
{where: {ticketFk: ticketId},
|
|
||||||
fields: ['alertLevel']
|
|
||||||
}, myOptions);
|
|
||||||
|
|
||||||
const packedAlertLevel = await models.AlertLevel.findOne({where: {code: 'PACKED'},
|
|
||||||
fields: ['id']
|
|
||||||
}, myOptions);
|
|
||||||
|
|
||||||
if (!ticketState)
|
|
||||||
throw new UserError('Ticket does not exist');
|
|
||||||
if (ticketState.alertLevel < packedAlertLevel.id)
|
|
||||||
throw new UserError('This ticket cannot be signed because it has not been boxed');
|
|
||||||
if (await gestDocExists(ticketId))
|
|
||||||
throw new UserError('Ticket is already signed');
|
|
||||||
|
|
||||||
if (location) setLocation(ticketId);
|
|
||||||
if (!gestDocCreated) await createGestDoc(ticketId);
|
|
||||||
await models.TicketDms.create({ticketFk: ticketId, dmsFk: dms[0].id}, myOptions);
|
|
||||||
const ticket = await models.Ticket.findById(ticketId, null, myOptions);
|
|
||||||
await ticket.updateAttribute('isSigned', true, myOptions);
|
|
||||||
await Self.rawSql(`CALL vn.ticket_setState(?, ?)`, [ticketId, 'DELIVERED'], myOptions);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (tx) await tx.commit();
|
|
||||||
return;
|
|
||||||
} catch (e) {
|
|
||||||
if (tx) await tx.rollback();
|
|
||||||
throw e;
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
module.exports = Self => {
|
module.exports = Self => {
|
||||||
// Methods
|
|
||||||
require('./ticket-methods')(Self);
|
require('./ticket-methods')(Self);
|
||||||
require('../methods/ticket/state')(Self);
|
require('../methods/ticket/state')(Self);
|
||||||
};
|
};
|
||||||
|
|
|
@ -173,7 +173,7 @@ class Controller extends Section {
|
||||||
|
|
||||||
state(value) {
|
state(value) {
|
||||||
const params = {ticketFk: this.$params.id, code: value};
|
const params = {ticketFk: this.$params.id, code: value};
|
||||||
return this.$http.post('TicketTrackings/state', params).then(() => {
|
return this.$http.post('Tickets/state', params).then(() => {
|
||||||
this.vnApp.showSuccess(this.$t('Data saved!'));
|
this.vnApp.showSuccess(this.$t('Data saved!'));
|
||||||
this.card.reload();
|
this.card.reload();
|
||||||
}).finally(() => this.resetChanges());
|
}).finally(() => this.resetChanges());
|
||||||
|
|
|
@ -229,13 +229,14 @@ describe('Ticket', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('state()', () => {
|
describe('state()', () => {
|
||||||
it('should make an HTTP post query, then call the showSuccess(), reload() and resetChanges() methods', () => {
|
it('should make an HTTP post query, then call the showSuccess(),' +
|
||||||
|
' reload() and resetChanges() methods', () => {
|
||||||
jest.spyOn(controller.card, 'reload').mockReturnThis();
|
jest.spyOn(controller.card, 'reload').mockReturnThis();
|
||||||
jest.spyOn(controller.vnApp, 'showSuccess').mockReturnThis();
|
jest.spyOn(controller.vnApp, 'showSuccess').mockReturnThis();
|
||||||
jest.spyOn(controller, 'resetChanges').mockReturnThis();
|
jest.spyOn(controller, 'resetChanges').mockReturnThis();
|
||||||
|
|
||||||
const expectedParams = {ticketFk: 1, code: 'OK'};
|
const expectedParams = {ticketFk: 1, code: 'OK'};
|
||||||
$httpBackend.expect('POST', `TicketTrackings/state`, expectedParams).respond(200);
|
$httpBackend.expect('POST', `Tickets/state`, expectedParams).respond(200);
|
||||||
controller.state('OK');
|
controller.state('OK');
|
||||||
$httpBackend.flush();
|
$httpBackend.flush();
|
||||||
|
|
||||||
|
@ -246,7 +247,8 @@ describe('Ticket', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('removeSales()', () => {
|
describe('removeSales()', () => {
|
||||||
it('should make an HTTP post query, then call the showSuccess(), removeSelectedSales() and resetChanges() methods', () => {
|
it('should make an HTTP post query, then call the showSuccess(),' +
|
||||||
|
' removeSelectedSales() and resetChanges() methods', () => {
|
||||||
jest.spyOn(controller.vnApp, 'showSuccess').mockReturnThis();
|
jest.spyOn(controller.vnApp, 'showSuccess').mockReturnThis();
|
||||||
jest.spyOn(controller, 'removeSelectedSales').mockReturnThis();
|
jest.spyOn(controller, 'removeSelectedSales').mockReturnThis();
|
||||||
jest.spyOn(controller, 'resetChanges').mockReturnThis();
|
jest.spyOn(controller, 'resetChanges').mockReturnThis();
|
||||||
|
@ -352,7 +354,8 @@ describe('Ticket', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('updatePrice()', () => {
|
describe('updatePrice()', () => {
|
||||||
it('should make an HTTP POST query, update the sale price and then call to the resetChanges() method', () => {
|
it('should make an HTTP POST query, update the sale price ' +
|
||||||
|
'and then call to the resetChanges() method', () => {
|
||||||
jest.spyOn(controller.vnApp, 'showSuccess').mockReturnThis();
|
jest.spyOn(controller.vnApp, 'showSuccess').mockReturnThis();
|
||||||
jest.spyOn(controller, 'resetChanges').mockReturnThis();
|
jest.spyOn(controller, 'resetChanges').mockReturnThis();
|
||||||
|
|
||||||
|
@ -418,7 +421,8 @@ describe('Ticket', () => {
|
||||||
expect(controller.$.editDiscount.hide).toHaveBeenCalledWith();
|
expect(controller.$.editDiscount.hide).toHaveBeenCalledWith();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should not call to the updateDiscount() method and then to the editDiscountDialog hide() method', () => {
|
it('should not call to the updateDiscount() method and then' +
|
||||||
|
' to the editDiscountDialog hide() method', () => {
|
||||||
jest.spyOn(controller, 'updateDiscount').mockReturnThis();
|
jest.spyOn(controller, 'updateDiscount').mockReturnThis();
|
||||||
|
|
||||||
const firstSelectedSale = controller.sales[0];
|
const firstSelectedSale = controller.sales[0];
|
||||||
|
@ -444,7 +448,8 @@ describe('Ticket', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('updateDiscount()', () => {
|
describe('updateDiscount()', () => {
|
||||||
it('should make an HTTP POST query, update the sales discount and then call to the resetChanges() method', () => {
|
it('should make an HTTP POST query, update the sales discount ' +
|
||||||
|
'and then call to the resetChanges() method', () => {
|
||||||
jest.spyOn(controller, 'resetChanges').mockReturnThis();
|
jest.spyOn(controller, 'resetChanges').mockReturnThis();
|
||||||
jest.spyOn(controller.vnApp, 'showSuccess').mockReturnThis();
|
jest.spyOn(controller.vnApp, 'showSuccess').mockReturnThis();
|
||||||
|
|
||||||
|
|
|
@ -64,8 +64,8 @@ class Controller extends Summary {
|
||||||
ticketFk: 'id' in this.ticket ? this.ticket.id : this.$params.id,
|
ticketFk: 'id' in this.ticket ? this.ticket.id : this.$params.id,
|
||||||
code: value
|
code: value
|
||||||
};
|
};
|
||||||
|
console.log('entra');
|
||||||
pablone marked this conversation as resolved
|
|||||||
this.$http.post(`TicketTrackings/state`, params)
|
this.$http.post(`Tickets/state`, params)
|
||||||
.then(() => {
|
.then(() => {
|
||||||
if ('id' in this.$params) this.reload();
|
if ('id' in this.$params) this.reload();
|
||||||
})
|
})
|
||||||
|
|
|
@ -50,7 +50,7 @@ describe('Ticket', () => {
|
||||||
|
|
||||||
let res = {id: 1, nickname: 'myNickname'};
|
let res = {id: 1, nickname: 'myNickname'};
|
||||||
$httpBackend.when('GET', `Tickets/1/summary`).respond(200, res);
|
$httpBackend.when('GET', `Tickets/1/summary`).respond(200, res);
|
||||||
$httpBackend.expectPOST(`TicketTrackings/state`).respond(200, 'ok');
|
$httpBackend.expectPOST(`Tickets/state`).respond(200, 'ok');
|
||||||
controller.state(value);
|
controller.state(value);
|
||||||
$httpBackend.flush();
|
$httpBackend.flush();
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
<mg-ajax path="TicketTrackings/state" options="vnPost"></mg-ajax>
|
<mg-ajax path="Tickets/state" options="vnPost"></mg-ajax>
|
||||||
<vn-watcher
|
<vn-watcher
|
||||||
vn-id="watcher"
|
vn-id="watcher"
|
||||||
data="$ctrl.params"
|
data="$ctrl.params"
|
||||||
|
|
|
@ -53,7 +53,7 @@ class Controller extends Section {
|
||||||
}
|
}
|
||||||
|
|
||||||
onSubmit() {
|
onSubmit() {
|
||||||
this.$http.post(`TicketTrackings/state`, this.params).then(() => {
|
this.$http.post(`Tickets/state`, this.params).then(() => {
|
||||||
this.$.watcher.updateOriginalData();
|
this.$.watcher.updateOriginalData();
|
||||||
this.card.reload();
|
this.card.reload();
|
||||||
this.vnApp.showSuccess(this.$t('Data saved!'));
|
this.vnApp.showSuccess(this.$t('Data saved!'));
|
||||||
|
|
|
@ -61,7 +61,7 @@ describe('Ticket', () => {
|
||||||
jest.spyOn(controller.vnApp, 'showSuccess');
|
jest.spyOn(controller.vnApp, 'showSuccess');
|
||||||
jest.spyOn(controller.$state, 'go');
|
jest.spyOn(controller.$state, 'go');
|
||||||
|
|
||||||
$httpBackend.expectPOST(`TicketTrackings/state`, controller.params).respond({});
|
$httpBackend.expectPOST(`Tickets/state`, controller.params).respond({});
|
||||||
controller.onSubmit();
|
controller.onSubmit();
|
||||||
$httpBackend.flush();
|
$httpBackend.flush();
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
llevar