8062-testToMaster_2 #3059

Merged
alexm merged 293 commits from 8062-testToMaster_2 into master 2024-10-03 05:43:41 +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,
description: 'The weight value',
}],
returns: {
type: 'boolean',
root: true
},
http: {
path: `/:id/setWeight`,
verb: 'POST'
}
});
Self.setWeight = async(ctx, ticketId, weight, invoiceable, options) => {
Self.setWeight = async(ctx, ticketId, weight, options) => {
const models = Self.app.models;
const userId = ctx.req.accessToken.userId;
const myOptions = {userId};
@ -36,10 +40,10 @@ module.exports = Self => {
}
try {
const ticket = await Self.findById(ticketId, null, myOptions);
if (ticket.weight) throw new UserError('Weight already set');
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, {
include: {relation: 'salesPersonUser'}},
myOptions);
@ -51,7 +55,10 @@ module.exports = Self => {
where: {workerFk: {inq: [userId, salesPersonUser.id]}}
}, 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');
}
@ -63,10 +70,12 @@ module.exports = Self => {
const [{taxArea}] = await Self.rawSql('SELECT clientTaxArea(?,?) taxArea',
[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);
return true;
}
if (tx) await tx.commit();
return false;
} catch (e) {
if (tx) await tx.rollback();
throw e;