8032-devToTest_2440 #3009

Merged
alexm merged 262 commits from 8032-devToTest_2440 into test 2024-09-24 09:34:49 +00:00
1 changed files with 14 additions and 5 deletions
Showing only changes of commit 52d62710e6 - Show all commits

View File

@ -16,13 +16,17 @@ module.exports = Self => {
required: true, required: true,
description: 'The weight value', description: 'The weight value',
}], }],
returns: {
type: 'boolean',
root: true
},
http: { http: {
path: `/:id/setWeight`, path: `/:id/setWeight`,
verb: 'POST' verb: 'POST'
} }
}); });
Self.setWeight = async(ctx, ticketId, weight, invoiceable, options) => { Self.setWeight = async(ctx, ticketId, weight, options) => {
const models = Self.app.models; const models = Self.app.models;
const userId = ctx.req.accessToken.userId; const userId = ctx.req.accessToken.userId;
const myOptions = {userId}; const myOptions = {userId};
@ -36,10 +40,10 @@ module.exports = Self => {
} }
try { try {
const ticket = await Self.findById(ticketId, null, myOptions);
if (ticket.weight) throw new UserError('Weight already set'); if (ticket.weight) throw new UserError('Weight already set');
const canEdit = await models.ACL.checkAccessAcl(ctx, 'Ticket', 'updateAttributes'); const canEdit = await models.ACL.checkAccessAcl(ctx, 'Ticket', 'updateAttributes');
const ticket = await Self.findById(ticketId, null, myOptions);
const client = await models.Client.findById(ticket.clientFk, { const client = await models.Client.findById(ticket.clientFk, {
include: {relation: 'salesPersonUser'}}, include: {relation: 'salesPersonUser'}},
myOptions); myOptions);
@ -51,7 +55,10 @@ module.exports = Self => {
where: {workerFk: {inq: [userId, salesPersonUser.id]}} where: {workerFk: {inq: [userId, salesPersonUser.id]}}
}, myOptions); }, myOptions);
if (workerDepartments[0].departmentFk != workerDepartments[1].departmentFk) if (
workerDepartments.length == 2 &&
workerDepartments[0].departmentFk != workerDepartments[1].departmentFk
)
throw new UserError('You don\'t have enough privileges'); throw new UserError('You don\'t have enough privileges');
} }
@ -63,10 +70,12 @@ module.exports = Self => {
const [{taxArea}] = await Self.rawSql('SELECT clientTaxArea(?,?) taxArea', const [{taxArea}] = await Self.rawSql('SELECT clientTaxArea(?,?) taxArea',
[ticket.clientFk, ticket.warehouseFk], myOptions); [ticket.clientFk, ticket.warehouseFk], myOptions);
if (ticketState.alertLevel >= packedState.alertLevel && taxArea == 'WORLD' && client.hasDailyInvoice) if (ticketState.alertLevel >= packedState.alertLevel && taxArea == 'WORLD' && client.hasDailyInvoice) {
await Self.invoiceTicketsAndPdf(ctx, [ticketId], null, myOptions); await Self.invoiceTicketsAndPdf(ctx, [ticketId], null, myOptions);
return true;
}
if (tx) await tx.commit(); if (tx) await tx.commit();
return false;
} catch (e) { } catch (e) {
if (tx) await tx.rollback(); if (tx) await tx.rollback();
throw e; throw e;