2473 - Added restore method + ese #408
|
@ -56,7 +56,6 @@
|
|||
"Value has an invalid format": "Value has an invalid format",
|
||||
"The postcode doesn't exist. Please enter a correct one": "The postcode doesn't exist. Please enter a correct one",
|
||||
"Can't create stowaway for this ticket": "Can't create stowaway for this ticket",
|
||||
"Has deleted the ticket id": "Has deleted the ticket id [#{{id}}]({{{url}}})",
|
||||
"Swift / BIC can't be empty": "Swift / BIC can't be empty",
|
||||
"MESSAGE_BOUGHT_UNITS": "Bought {{quantity}} units of {{concept}} (#{{itemId}}) for the ticket id [#{{ticketId}}]({{{url}}})",
|
||||
"MESSAGE_INSURANCE_CHANGE": "I have changed the insurence credit of client [{{clientName}} (#{{clientId}})]({{{url}}}) to *{{credit}} €*",
|
||||
|
@ -68,7 +67,9 @@
|
|||
"Incoterms is required for a non UEE member": "Incoterms is required for a non UEE member",
|
||||
"Client checked as validated despite of duplication": "Client checked as validated despite of duplication from client id {{clientId}}",
|
||||
"Landing cannot be lesser than shipment": "Landing cannot be lesser than shipment",
|
||||
"NOT_ZONE_WITH_THIS_PARAMETERS": "NOT_ZONE_WITH_THIS_PARAMETERS",
|
||||
"NOT_ZONE_WITH_THIS_PARAMETERS": "There's no zone available for this day",
|
||||
"Created absence": "The worker <strong>{{author}}</strong> has added an absence of type '{{absenceType}}' to <a href='{{{workerUrl}}}'><strong>{{employee}}</strong></a> for day {{dated}}.",
|
||||
"Deleted absence": "The worker <strong>{{author}}</strong> has deleted an absence of type '{{absenceType}}' to <a href='{{{workerUrl}}}'><strong>{{employee}}</strong></a> for day {{dated}}."
|
||||
"Deleted absence": "The worker <strong>{{author}}</strong> has deleted an absence of type '{{absenceType}}' to <a href='{{{workerUrl}}}'><strong>{{employee}}</strong></a> for day {{dated}}.",
|
||||
"I have deleted the ticket id": "I have deleted the ticket id [#{{id}}]({{{url}}})",
|
||||
"I have restored the ticket id": "I have restored the ticket id [#{{id}}]({{{url}}})"
|
||||
}
|
|
@ -114,7 +114,6 @@
|
|||
"You can't create a claim for a removed ticket": "No puedes crear una reclamación para un ticket eliminado",
|
||||
"You cannot delete a ticket that part of it is being prepared": "No puedes eliminar un ticket en el que una parte que está siendo preparada",
|
||||
"You must delete all the buy requests first": "Debes eliminar todas las peticiones de compra primero",
|
||||
"Has deleted the ticket id": "Ha eliminado el ticket id [#{{id}}]({{{url}}})",
|
||||
"You should specify a date": "Debes especificar una fecha",
|
||||
"You should specify at least a start or end date": "Debes especificar al menos una fecha de inicio o de fín",
|
||||
"Start date should be lower than end date": "La fecha de inicio debe ser menor que la fecha de fín",
|
||||
|
@ -146,5 +145,8 @@
|
|||
"User already exists": "User already exists",
|
||||
"Absence change notification on the labour calendar": "Notificacion de cambio de ausencia en el calendario laboral",
|
||||
"Created absence": "El empleado <strong>{{author}}</strong> ha añadido una ausencia de tipo '{{absenceType}}' a <a href='{{{workerUrl}}}'><strong>{{employee}}</strong></a> para el día {{dated}}.",
|
||||
"Deleted absence": "El empleado <strong>{{author}}</strong> ha eliminado una ausencia de tipo '{{absenceType}}' a <a href='{{{workerUrl}}}'><strong>{{employee}}</strong></a> del día {{dated}}."
|
||||
"Deleted absence": "El empleado <strong>{{author}}</strong> ha eliminado una ausencia de tipo '{{absenceType}}' a <a href='{{{workerUrl}}}'><strong>{{employee}}</strong></a> del día {{dated}}.",
|
||||
"I have deleted the ticket id": "He eliminado el ticket id [#{{id}}]({{{url}}})",
|
||||
"I have restored the ticket id": "He restaurado el ticket id [#{{id}}]({{{url}}})",
|
||||
"You can only restore a ticket within the first hour after deletion": "Únicamente puedes restaurar el ticket dentro de la primera hora después de su eliminación"
|
||||
}
|
|
@ -23,16 +23,7 @@ module.exports = Self => {
|
|||
|
||||
Self.restore = async(ctx, id) => {
|
||||
const models = Self.app.models;
|
||||
const userId = ctx.req.accessToken.userId;
|
||||
const isEditable = await Self.isEditable(ctx, id);
|
||||
const $t = ctx.req.__; // $translate
|
||||
|
||||
/* if (!isEditable)
|
||||
throw new UserError(`The sales of this ticket can't be modified`);
|
||||
*/
|
||||
// Check if has sales with shelving
|
||||
// const isSalesAssistant = await models.Account.hasRole(userId, 'salesAssistant');
|
||||
|
||||
const ticket = await models.Ticket.findById(id, {
|
||||
include: [{
|
||||
relation: 'client',
|
||||
|
@ -42,11 +33,18 @@ module.exports = Self => {
|
|||
}]
|
||||
});
|
||||
|
||||
const now = new Date();
|
||||
const maxDate = new Date(ticket.updated);
|
||||
maxDate.setHours(maxDate.getHours() + 1);
|
||||
|
||||
if (now > maxDate)
|
||||
throw new UserError(`You can only restore a ticket within the first hour after deletion`);
|
||||
|
||||
// Send notification to salesPerson
|
||||
const salesPersonId = ticket.client().salesPersonFk;
|
||||
if (salesPersonId) {
|
||||
const origin = ctx.req.headers.origin;
|
||||
const message = $t(`Has restored the ticket id`, {
|
||||
const message = $t(`I have restored the ticket id`, {
|
||||
id: id,
|
||||
url: `${origin}/#!/ticket/${id}/summary`
|
||||
});
|
||||
|
|
|
@ -121,7 +121,7 @@ module.exports = Self => {
|
|||
const salesPersonUser = ticket.client().salesPersonUser();
|
||||
if (salesPersonUser) {
|
||||
const origin = ctx.req.headers.origin;
|
||||
const message = $t(`Has deleted the ticket id`, {
|
||||
const message = $t(`I have deleted the ticket id`, {
|
||||
id: id,
|
||||
url: `${origin}/#!/ticket/${id}/summary`
|
||||
});
|
||||
|
|
|
@ -0,0 +1,71 @@
|
|||
const app = require('vn-loopback/server/server');
|
||||
const models = app.models;
|
||||
|
||||
describe('ticket restore()', () => {
|
||||
const employeeUser = 110;
|
||||
const ctx = {
|
||||
req: {
|
||||
accessToken: {userId: employeeUser},
|
||||
headers: {
|
||||
origin: 'http://localhost:5000'
|
||||
},
|
||||
__: () => {}
|
||||
}
|
||||
};
|
||||
let createdTicket;
|
||||
|
||||
beforeEach(async done => {
|
||||
try {
|
||||
const sampleTicket = await models.Ticket.findById(11);
|
||||
sampleTicket.id = undefined;
|
||||
|
||||
createdTicket = await models.Ticket.create(sampleTicket);
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
}
|
||||
|
||||
done();
|
||||
});
|
||||
|
||||
afterEach(async done => {
|
||||
try {
|
||||
await models.Ticket.destroyById(createdTicket.id);
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
}
|
||||
|
||||
done();
|
||||
});
|
||||
|
||||
it('should throw an error if the given ticket has past the deletion time', async() => {
|
||||
let error;
|
||||
|
||||
const now = new Date();
|
||||
now.setHours(now.getHours() - 1);
|
||||
|
||||
try {
|
||||
const ticket = await models.Ticket.findById(createdTicket.id);
|
||||
await ticket.updateAttributes({isDeleted: true, updated: now});
|
||||
await app.models.Ticket.restore(ctx, createdTicket.id);
|
||||
} catch (e) {
|
||||
error = e;
|
||||
}
|
||||
|
||||
expect(error.message).toContain('You can only restore a ticket within the first hour after deletion');
|
||||
});
|
||||
|
||||
it('should restore the ticket making its state no longer deleted', async() => {
|
||||
const now = new Date();
|
||||
const ticketBeforeUpdate = await models.Ticket.findById(createdTicket.id);
|
||||
await ticketBeforeUpdate.updateAttributes({isDeleted: true, updated: now});
|
||||
|
||||
const ticketAfterUpdate = await models.Ticket.findById(createdTicket.id);
|
||||
|
||||
expect(ticketAfterUpdate.isDeleted).toBeTruthy();
|
||||
|
||||
await models.Ticket.restore(ctx, createdTicket.id);
|
||||
const ticketAfterRestore = await models.Ticket.findById(createdTicket.id);
|
||||
|
||||
expect(ticketAfterRestore.isDeleted).toBeFalsy();
|
||||
});
|
||||
});
|
|
@ -12,6 +12,7 @@ module.exports = Self => {
|
|||
require('../methods/ticket/new')(Self);
|
||||
require('../methods/ticket/isEditable')(Self);
|
||||
require('../methods/ticket/setDeleted')(Self);
|
||||
require('../methods/ticket/restore')(Self);
|
||||
require('../methods/ticket/getVAT')(Self);
|
||||
require('../methods/ticket/getSales')(Self);
|
||||
require('../methods/ticket/getSalesPersonMana')(Self);
|
||||
|
|
|
@ -34,8 +34,11 @@
|
|||
"packages": {
|
||||
"type": "Number"
|
||||
},
|
||||
"created": {
|
||||
"type": "Date"
|
||||
"updated": {
|
||||
"type": "Date",
|
||||
"mysql": {
|
||||
"columnName": "created"
|
||||
}
|
||||
},
|
||||
"isDeleted": {
|
||||
"type": "boolean"
|
||||
|
|
|
@ -30,7 +30,7 @@
|
|||
</vn-item>
|
||||
<vn-item
|
||||
ng-click="restoreConfirmation.show()"
|
||||
ng-show="$ctrl.ticket.isDeleted"
|
||||
ng-show="$ctrl.canRestoreTicket"
|
||||
name="restoreTicket"
|
||||
translate>
|
||||
Restore ticket
|
||||
|
@ -250,7 +250,7 @@
|
|||
vn-id="restoreConfirmation"
|
||||
on-accept="$ctrl.restoreTicket()"
|
||||
question="You are going to restore this ticket"
|
||||
message="You can only restore a ticket within the first hour after deletion! Continue anyway?">
|
||||
message="Are you sure you want to restore this ticket?">
|
||||
</vn-confirm>
|
||||
<vn-confirm
|
||||
vn-id="deleteStowaway"
|
||||
|
|
|
@ -44,6 +44,15 @@ class Controller extends Descriptor {
|
|||
return null;
|
||||
}
|
||||
|
||||
get canRestoreTicket() {
|
||||
const isDeleted = this.ticket.isDeleted;
|
||||
const now = new Date();
|
||||
const maxDate = new Date(this.ticket.updated);
|
||||
maxDate.setHours(maxDate.getHours() + 1);
|
||||
|
||||
return isDeleted && (now <= maxDate);
|
||||
}
|
||||
|
||||
isTicketEditable() {
|
||||
if (!this.ticket) return;
|
||||
this.$http.get(`Tickets/${this.id}/isEditable`).then(res => {
|
||||
|
@ -86,14 +95,14 @@ class Controller extends Descriptor {
|
|||
return this.$http.post(`Tickets/${this.id}/setDeleted`)
|
||||
.then(() => {
|
||||
this.$state.go('ticket.index');
|
||||
this.vnApp.showSuccess(this.$t('Ticket deleted'));
|
||||
this.vnApp.showSuccess(this.$t('Ticket deleted. You can undo this action within the first hour'));
|
||||
});
|
||||
}
|
||||
|
||||
restoreTicket() {
|
||||
return this.$http.post(`Tickets/${this.id}/restore`)
|
||||
.then(() => {
|
||||
this.vnApp.showSuccess(this.$t('Ticket restored'));
|
||||
this.vnApp.showSuccess(this.$t('Data saved!'));
|
||||
this.cardReload();
|
||||
});
|
||||
}
|
||||
|
@ -132,7 +141,7 @@ class Controller extends Descriptor {
|
|||
sendImportSms() {
|
||||
const params = {
|
||||
ticketId: this.id,
|
||||
created: this.ticket.created
|
||||
created: this.ticket.updated
|
||||
};
|
||||
this.showSMSDialog({
|
||||
message: this.$params.message || this.$t('Minimum is needed', params)
|
||||
|
|
|
@ -24,8 +24,11 @@ You are going to regenerate the invoice: Vas a regenerar la factura
|
|||
Are you sure you want to regenerate the invoice?: ¿Seguro que quieres regenerar la factura?
|
||||
Invoice sent for a regeneration, will be available in a few minutes: La factura ha sido enviada para ser regenerada, estará disponible en unos minutos
|
||||
Shipped hour updated: Hora de envio modificada
|
||||
Deleted ticket: Ticket eliminado
|
||||
Deleted ticket: Ticket eliminado
|
||||
Recalculate components: Recalcular componentes
|
||||
Are you sure you want to recalculate the components?: ¿Seguro que quieres recalcular los componentes?
|
||||
SMS Minimum import: 'SMS Importe minimo'
|
||||
SMS Pending payment: 'SMS Pago pendiente'
|
||||
SMS Pending payment: 'SMS Pago pendiente'
|
||||
Restore ticket: Restaurar ticket
|
||||
You are going to restore this ticket: Vas a restaurar este ticket
|
||||
Are you sure you want to restore this ticket?: ¿Seguro que quieres restaurar el ticket?
|
|
@ -59,7 +59,7 @@ Freezed: Congelado
|
|||
Risk: Riesgo
|
||||
Invoice: Factura
|
||||
You are going to delete this ticket: Vas a eliminar este ticket
|
||||
Ticket deleted: Ticket borrado
|
||||
Ticket deleted. You can undo this action within the first hour: Ticket eliminado. Puedes deshacer esta acción durante la primera hora
|
||||
Search ticket by id or alias: Buscar tickets por identificador o alias
|
||||
ticket: ticket
|
||||
|
||||
|
|
|
@ -363,7 +363,7 @@ class Controller extends Section {
|
|||
const notAvailables = items.join(', ');
|
||||
const params = {
|
||||
ticketFk: this.ticket.id,
|
||||
created: this.ticket.created,
|
||||
created: this.ticket.updated,
|
||||
notAvailables
|
||||
};
|
||||
this.newSMS = {
|
||||
|
|
Loading…
Reference in New Issue