#1755 create claim only for non removed tickets
gitea/salix/dev This commit looks good Details

This commit is contained in:
Joan Sanchez 2019-10-14 11:44:54 +02:00
parent 4a6ff9ca20
commit 81097287fa
2 changed files with 32 additions and 17 deletions

View File

@ -1,3 +1,5 @@
const UserError = require('vn-loopback/util/user-error');
module.exports = Self => { module.exports = Self => {
Self.remoteMethodCtx('createFromSales', { Self.remoteMethodCtx('createFromSales', {
description: 'Create a claim', description: 'Create a claim',
@ -25,13 +27,19 @@ module.exports = Self => {
}); });
Self.createFromSales = async(ctx, params) => { Self.createFromSales = async(ctx, params) => {
let model = Self.app.models; let models = Self.app.models;
let userId = ctx.req.accessToken.userId; let userId = ctx.req.accessToken.userId;
let tx = await Self.beginTransaction({}); let tx = await Self.beginTransaction({});
try { try {
let options = {transaction: tx}; let options = {transaction: tx};
const worker = await Self.app.models.Worker.findOne({
const ticketId = params.claim.ticketFk;
const ticket = await models.Ticket.findById(ticketId, null, options);
if (ticket.isDeleted)
throw new UserError(`You can't create a claim for a removed ticket`);
const worker = await models.Worker.findOne({
where: {userFk: userId} where: {userFk: userId}
}, options); }, options);
@ -40,7 +48,7 @@ module.exports = Self => {
let promises = []; let promises = [];
for (const sale of params.sales) { for (const sale of params.sales) {
const newClaimBeginning = model.ClaimBeginning.create({ const newClaimBeginning = models.ClaimBeginning.create({
saleFk: sale.id, saleFk: sale.id,
claimFk: newClaim.id, claimFk: newClaim.id,
quantity: sale.quantity quantity: sale.quantity

View File

@ -11,11 +11,27 @@ class Controller {
this.$http = $http; this.$http = $http;
this.edit = {}; this.edit = {};
this.moreOptions = [ this.moreOptions = [
{callback: this.markAsReserved, name: 'Mark as reserved'}, {name: 'Send SMS', callback: this.showSMSDialog},
{callback: this.unmarkAsReserved, name: 'Unmark as reserved'}, {
{callback: this.showEditDialog, name: 'Update discount', show: () => !this.hasInvoice()}, name: 'Mark as reserved',
{callback: this.createClaim, name: 'Add claim'}, callback: this.markAsReserved,
{callback: this.showSMSDialog, name: 'Send SMS'} show: () => this.isEditable
},
{
name: 'Unmark as reserved',
callback: this.unmarkAsReserved,
show: () => this.isEditable
},
{
name: 'Update discount',
callback: this.showEditDialog,
show: () => this.isEditable
},
{
name: 'Add claim',
callback: this.createClaim,
show: () => this.isEditable
},
]; ];
this._sales = []; this._sales = [];
this.imagesPath = '//verdnatura.es/vn-image-data/catalog'; this.imagesPath = '//verdnatura.es/vn-image-data/catalog';
@ -431,15 +447,6 @@ class Controller {
this.$scope.sms.open(); this.$scope.sms.open();
} }
/**
* Returns if the current ticket
* is already invoiced
* @return {Boolean} - True if invoiced
*/
hasInvoice() {
return this.ticket.refFk !== null;
}
/** /**
* Inserts a new instance * Inserts a new instance
*/ */