#6276 createNewWarehouse methods migrated from silex to salix #1850

Merged
jorgep merged 158 commits from 6276-createNewWarehouse into dev 2024-03-06 11:32:11 +00:00
4 changed files with 66 additions and 3 deletions
Showing only changes of commit 36a9b0eee4 - Show all commits

View File

@ -0,0 +1,60 @@
const UserError = require('vn-loopback/util/user-error');
module.exports = Self => {
Self.remoteMethodCtx('addItem', {
description: 'Add a collection',
accessType: 'WRITE',
accepts: [
{
arg: 'code',
type: 'string',
required: true
},
{
arg: 'quantity',
type: 'number',
required: true
},
{
arg: 'ticketFk',
type: 'number',
required: true
},
{
arg: 'warehouseFk',
type: 'number',
required: true
},
],
http: {
path: `/addItem`,
verb: 'POST'
},
});
Self.addItem = async(ctx, code, quantity, ticketFk, warehouseFk, options) => {
const models = Self.app.models;
const myOptions = {};
let tx;
if (typeof options == 'object')
Object.assign(myOptions, options);
if (!myOptions.transaction) {
tx = await Self.beginTransaction({});
myOptions.transaction = tx;
}
try {
const [[item]] = await Self.rawSql('CALL vn.item_getInfo(?,?)', [code, warehouseFk]);
if (!item.available) throw new UserError('We do not have availability for the selected item');
await models.Ticket.addSale(ctx, ticketFk, item.id, quantity, myOptions);
if (tx) await tx.commit();
} catch (e) {
if (tx) await tx.rollback();
throw e;
}
};
};

View File

@ -5,4 +5,5 @@ module.exports = Self => {
require('../methods/collection/previousLabel')(Self); require('../methods/collection/previousLabel')(Self);
require('../methods/collection/getTickets')(Self); require('../methods/collection/getTickets')(Self);
require('../methods/collection/assignCollection')(Self); require('../methods/collection/assignCollection')(Self);
require('../methods/collection/addItem')(Self);
}; };

View File

@ -8,4 +8,5 @@ INSERT INTO `salix`.`ACL` (model, property, accessType, permission, principalTyp
('SaleTracking','deleteTracking','WRITE','ALLOW','ROLE','employee'), ('SaleTracking','deleteTracking','WRITE','ALLOW','ROLE','employee'),
('SaleTracking','updateTracking','WRITE','ALLOW','ROLE','employee'), ('SaleTracking','updateTracking','WRITE','ALLOW','ROLE','employee'),
('SaleTracking','mark','WRITE','ALLOW','ROLE','employee'), ('SaleTracking','mark','WRITE','ALLOW','ROLE','employee'),
('ItemBarcode','deleteByItemAndCode','WRITE','ALLOW','ROLE','employee'); ('ItemBarcode','deleteByItemAndCode','WRITE','ALLOW','ROLE','employee'),
('Collection','addItem','WRITE','ALLOW','ROLE','employee');

View File

@ -71,7 +71,8 @@ module.exports = Self => {
}, ctx.options); }, ctx.options);
if (item.family == 'EMB') return; if (item.family == 'EMB') return;
if (await models.ACL.checkAccessAcl(ctx, 'Sale', 'isInPreparing', '*')) return; const isInPreparing = await models.ACL.checkAccessAcl(ctx, 'Sale', 'isInPreparing', '*');
if (!ctx.isNEwInstance && isInPreparing) return;
await models.Sale.rawSql(`CALL catalog_calcFromItem(?,?,?,?)`, [ await models.Sale.rawSql(`CALL catalog_calcFromItem(?,?,?,?)`, [
ticket.landed, ticket.landed,
@ -89,7 +90,7 @@ module.exports = Self => {
if (await models.ACL.checkAccessAcl(ctx, 'Ticket', 'isRoleAdvanced', '*')) return; if (await models.ACL.checkAccessAcl(ctx, 'Ticket', 'isRoleAdvanced', '*')) return;
if (newQuantity < item.minQuantity && newQuantity != available) if (newQuantity < item.minQuantity && newQuantity != available && !isInPreparing)
throw new UserError('The amount cannot be less than the minimum'); throw new UserError('The amount cannot be less than the minimum');
if (ctx.isNewInstance || isReduction) return; if (ctx.isNewInstance || isReduction) return;