diff --git a/modules/ticket/back/methods/sale/updateDiscount.js b/modules/ticket/back/methods/sale/updateDiscount.js
index 18ad5eb33..6eaf2cb12 100644
--- a/modules/ticket/back/methods/sale/updateDiscount.js
+++ b/modules/ticket/back/methods/sale/updateDiscount.js
@@ -26,24 +26,20 @@ module.exports = Self => {
throw new UserError(`The value should be a number`);
let model = Self.app.models;
- let ticket = await model.Ticket.find({
- where: {
- id: params.editLines[0].ticketFk
- },
- include: [{
+ let ticket = await model.Ticket.findById(params.editLines[0].ticketFk, {
+ include: {
relation: 'client',
scope: {
fields: ['salesPersonFk']
}
- }],
- fields: ['id', 'clientFk', 'refFk']
+ },
});
if (ticket.refFk)
throw new UserError(`The sales of this ticket can't be modified`);
let componentToUse;
- let usesMana = await model.WorkerMana.findOne({where: {workerFk: ticket[0].client().salesPersonFk}, fields: 'amount'});
+ let usesMana = await model.WorkerMana.findOne({where: {workerFk: ticket.client().salesPersonFk}, fields: 'amount'});
if (usesMana)
componentToUse = 37;
@@ -61,7 +57,7 @@ module.exports = Self => {
if (usesMana) {
query = `
call vn.manaSpellersRequery(?)`;
- await Self.rawSql(query, [ticket[0].client().salesPersonFk]);
+ await Self.rawSql(query, [ticket.client().salesPersonFk]);
}
};
};
diff --git a/modules/ticket/front/sale/editDiscount.js b/modules/ticket/front/sale/editDiscount.js
index 34dc0c48e..3df684ff3 100644
--- a/modules/ticket/front/sale/editDiscount.js
+++ b/modules/ticket/front/sale/editDiscount.js
@@ -44,13 +44,14 @@ class Controller {
}
if (modified) {
this.$http.post(`/ticket/api/Sales/updateDiscount`, {editLines}).then(() => {
- this.onHide();
this.vnApp.showSuccess(this.$translate.instant('Data saved!'));
this.clear();
modified = false;
}).catch(e => {
this.vnApp.showError(e.data.error.message);
});
+
+ this.onHide();
} else
this.vnApp.showError(this.$translate.instant('There is no changes to save'));
}
diff --git a/modules/ticket/front/sale/index.html b/modules/ticket/front/sale/index.html
index d57c0b7c2..8cd345e79 100644
--- a/modules/ticket/front/sale/index.html
+++ b/modules/ticket/front/sale/index.html
@@ -134,7 +134,7 @@
{{sale.price | currency: 'EUR':2}}
-
+
diff --git a/modules/ticket/front/sale/index.js b/modules/ticket/front/sale/index.js
index 16b668c4e..9ebebf7b5 100644
--- a/modules/ticket/front/sale/index.js
+++ b/modules/ticket/front/sale/index.js
@@ -14,7 +14,7 @@ class Controller {
this.moreOptions = [
{callback: this.markAsReserved, name: 'Mark as reserved'},
{callback: this.unmarkAsReserved, name: 'Unmark as reserved'},
- {callback: this.showEditDialog, name: 'Update discount'},
+ {callback: this.showEditDialog, name: 'Update discount', show: () => !this.hasInvoice()},
{callback: this.createClaim, name: 'Add claim'},
{callback: this.showSMSDialog, name: 'Send SMS'}
];
@@ -60,7 +60,13 @@ class Controller {
}
onMoreOpen() {
- let options = this.moreOptions.filter(o => o.always || this.isChecked);
+ let options = this.moreOptions.filter(option => {
+ const hasShowProperty = Object.hasOwnProperty.call(option, 'show');
+ const shouldShow = !hasShowProperty || option.show === true ||
+ typeof option.show === 'function' && option.show();
+
+ return (shouldShow && (option.always || this.isChecked));
+ });
this.$scope.moreButton.data = options;
}
@@ -337,6 +343,15 @@ class Controller {
};
this.$scope.sms.open();
}
+
+ /**
+ * Returns if the current ticket
+ * is already invoiced
+ * @return {Boolean} - True if invoiced
+ */
+ hasInvoice() {
+ return this.ticket.refFk !== null;
+ }
}
Controller.$inject = ['$scope', '$state', '$http', 'vnApp', '$translate'];