diff --git a/loopback/locale/es.json b/loopback/locale/es.json
index 175b90ef0..171e376d2 100644
--- a/loopback/locale/es.json
+++ b/loopback/locale/es.json
@@ -111,9 +111,7 @@
"This phone already exists": "Este teléfono ya existe",
"You cannot move a parent to its own sons": "No puedes mover un elemento padre a uno de sus hijos",
"You can't create a claim for a removed ticket": "No puedes crear una reclamación para un ticket eliminado",
- "You cannot delete this ticket because is already invoiced, deleted or prepared": "No puedes eliminar este tiquet porque ya está facturado, eliminado o preparado",
"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 cannot remove this ticket because is already invoiced, deleted or prepared": "You cannot remove this ticket because is already invoiced, deleted or prepared"
+ "Has deleted the ticket id": "Ha eliminado el ticket id [#{{id}}]({{{url}}})"
}
\ No newline at end of file
diff --git a/modules/ticket/back/methods/sale/calculate.js b/modules/ticket/back/methods/sale/calculate.js
new file mode 100644
index 000000000..5a2ac39b8
--- /dev/null
+++ b/modules/ticket/back/methods/sale/calculate.js
@@ -0,0 +1,34 @@
+const UserError = require('vn-loopback/util/user-error');
+module.exports = Self => {
+ Self.remoteMethodCtx('calculate', {
+ description: 'Calculates the price of a sale and its components',
+ accessType: 'WRITE',
+ accepts: [{
+ arg: 'id',
+ description: 'The sale id',
+ type: 'number',
+ required: true,
+ http: {source: 'path'}
+ }],
+ returns: {
+ type: 'Number',
+ root: true
+ },
+ http: {
+ path: `/:id/calculate`,
+ verb: 'post'
+ }
+ });
+
+ Self.calculate = async(ctx, id) => {
+ const models = Self.app.models;
+
+ const sale = await Self.findById(id);
+ const isEditable = await models.Ticket.isEditable(ctx, sale.ticketFk);
+
+ if (!isEditable)
+ throw new UserError(`The sales of this ticket can't be modified`);
+
+ return Self.rawSql('CALL vn.ticketCalculateSale(?)', [id]);
+ };
+};
diff --git a/modules/ticket/back/methods/sale/specs/calculate.spec.js b/modules/ticket/back/methods/sale/specs/calculate.spec.js
new file mode 100644
index 000000000..48b14e972
--- /dev/null
+++ b/modules/ticket/back/methods/sale/specs/calculate.spec.js
@@ -0,0 +1,24 @@
+const app = require('vn-loopback/server/server');
+
+describe('sale calculate()', () => {
+ const saleId = 7;
+
+ it('should update the sale price', async() => {
+ const ctx = {req: {accessToken: {userId: 9}}};
+ const response = await app.models.Sale.calculate(ctx, saleId);
+
+ expect(response.affectedRows).toBeDefined();
+ });
+
+ it('should throw an error if the ticket is not editable', async() => {
+ const ctx = {req: {accessToken: {userId: 9}}};
+ const immutableSaleId = 1;
+ await app.models.Sale.calculate(ctx, immutableSaleId)
+ .catch(response => {
+ expect(response).toEqual(new Error(`The sales of this ticket can't be modified`));
+ error = response;
+ });
+
+ expect(error).toBeDefined();
+ });
+});
diff --git a/modules/ticket/back/methods/ticket/setDeleted.js b/modules/ticket/back/methods/ticket/setDeleted.js
index b9ac03560..fb72c7dbc 100644
--- a/modules/ticket/back/methods/ticket/setDeleted.js
+++ b/modules/ticket/back/methods/ticket/setDeleted.js
@@ -27,7 +27,7 @@ module.exports = Self => {
const $t = ctx.req.__; // $translate
if (!isEditable)
- throw new UserError('You cannot delete this ticket because is already invoiced, deleted or prepared');
+ throw new UserError(`The sales of this ticket can't be modified`);
// Check if has sales with shelving
const sales = await models.Sale.find({
diff --git a/modules/ticket/back/models/sale.js b/modules/ticket/back/models/sale.js
index b1fe82565..1b352bcff 100644
--- a/modules/ticket/back/models/sale.js
+++ b/modules/ticket/back/models/sale.js
@@ -5,6 +5,7 @@ module.exports = Self => {
require('../methods/sale/updatePrice')(Self);
require('../methods/sale/updateQuantity')(Self);
require('../methods/sale/updateConcept')(Self);
+ require('../methods/sale/calculate')(Self);
Self.validatesPresenceOf('concept', {
message: `Concept cannot be blank`
diff --git a/modules/ticket/front/basic-data/index.html b/modules/ticket/front/basic-data/index.html
index f492283b0..46e2ad6a9 100644
--- a/modules/ticket/front/basic-data/index.html
+++ b/modules/ticket/front/basic-data/index.html
@@ -11,4 +11,4 @@