7152-devToTest_2414 #2228

Merged
alexm merged 636 commits from 7152-devToTest_2414 into test 2024-03-28 08:26:34 +00:00
3 changed files with 76 additions and 1 deletions
Showing only changes of commit 40236fdb7b - Show all commits

View File

@ -0,0 +1,74 @@
module.exports = Self => {
Self.remoteMethod('makeMulti', {
description: 'Add a record or update it if it already exists.',
accessType: 'WRITE',
accepts: [{
arg: 'shelvingFk',
type: 'number',
required: true,
},
{
arg: 'items',
type: ['number'],
required: true,
description: 'array of item foreign keys'
},
{
arg: 'warehouseFk',
type: 'number',
required: true
}],
http: {
path: `/makeMulti`,
verb: 'POST'
}
});
Self.makeMulti = async(shelvingFk, items, warehouseFk, options) => {
const myOptions = {};
let tx;
if (typeof options == 'object')
Object.assign(myOptions, options);
if (!myOptions.transaction) {
tx = await Self.beginTransaction({});
myOptions.transaction = tx;
}
const discardItems = [];
try {
for (let item of items) {
if (!discardItems.includes(item)) {
let quantity = items.reduce((acc, cur) => {
return acc + (cur === item ? 1 : 0);
}, 0);
discardItems.push(item);
let [result] = await Self.rawSql('SELECT vn.itemPacking(?, ?)', [item, warehouseFk]);
let packing;
if (result) packing = Object.values(result)[0];
if (!packing) packing = 1;
quantity = quantity * packing;
await Self.rawSql('CALL vn.itemShelving_add(?, ?, ?, NULL, NULL, ?, ?)',
[shelvingFk,
item,
quantity,
packing,
warehouseFk]
);
}
}
if (tx) await tx.commit();
} catch (e) {
if (tx) await tx.rollback();
throw e;
}
};
};

View File

@ -1,4 +1,5 @@
module.exports = Self => {
require('../methods/item-shelving/deleteItemShelvings')(Self);
require('../methods/item-shelving/getInventory')(Self);
require('../methods/item-shelving/makeMulti')(Self);
};

View File

@ -1,6 +1,6 @@
{
"name": "ItemShelving",
"base": "Loggable",
"base": "VnModel",
"options": {
"mysql": {
"table": "itemShelving"