#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 => {
Self.remoteMethodCtx('createFromSales', {
description: 'Create a claim',
@ -25,13 +27,19 @@ module.exports = Self => {
});
Self.createFromSales = async(ctx, params) => {
let model = Self.app.models;
let models = Self.app.models;
let userId = ctx.req.accessToken.userId;
let tx = await Self.beginTransaction({});
try {
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}
}, options);
@ -40,7 +48,7 @@ module.exports = Self => {
let promises = [];
for (const sale of params.sales) {
const newClaimBeginning = model.ClaimBeginning.create({
const newClaimBeginning = models.ClaimBeginning.create({
saleFk: sale.id,
claimFk: newClaim.id,
quantity: sale.quantity

View File

@ -11,11 +11,27 @@ class Controller {
this.$http = $http;
this.edit = {};
this.moreOptions = [
{callback: this.markAsReserved, name: 'Mark as reserved'},
{callback: this.unmarkAsReserved, name: 'Unmark as reserved'},
{callback: this.showEditDialog, name: 'Update discount', show: () => !this.hasInvoice()},
{callback: this.createClaim, name: 'Add claim'},
{callback: this.showSMSDialog, name: 'Send SMS'}
{name: 'Send SMS', callback: this.showSMSDialog},
{
name: 'Mark as reserved',
callback: this.markAsReserved,
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.imagesPath = '//verdnatura.es/vn-image-data/catalog';
@ -431,15 +447,6 @@ 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;
}
/**
* Inserts a new instance
*/