#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
9 changed files with 164 additions and 1 deletions
Showing only changes of commit e9f7fbed86 - Show all commits

View File

@ -20,6 +20,10 @@ BEGIN
SELECT barcodeToItem(vBarcode) INTO vItemFk; SELECT barcodeToItem(vBarcode) INTO vItemFk;
SET vPacking = COALESCE(vPacking, GREATEST(vn.itemPacking(vBarcode,vWarehouseFk), 1));
SET vQuantity = vQuantity * vPacking;
IF (SELECT COUNT(*) FROM shelving WHERE code = vShelvingFk COLLATE utf8_unicode_ci) = 0 THEN IF (SELECT COUNT(*) FROM shelving WHERE code = vShelvingFk COLLATE utf8_unicode_ci) = 0 THEN
INSERT IGNORE INTO parking(code) VALUES(vShelvingFk); INSERT IGNORE INTO parking(code) VALUES(vShelvingFk);

View File

@ -28,7 +28,7 @@ BEGIN
MAKETIME(pb.HH,pb.mm,0) etd, MAKETIME(pb.HH,pb.mm,0) etd,
pb.routeFk, pb.routeFk,
FLOOR(s.quantity / ish.packing) stickers, FLOOR(s.quantity / ish.packing) stickers,
ish.packing, IF(i.isBoxPickingMode, ish.packing, i.packingOut) packing,
b.packagingFk b.packagingFk
FROM sale s FROM sale s
JOIN item i ON i.id = s.itemFk JOIN item i ON i.id = s.itemFk

View File

@ -0,0 +1,3 @@
-- Place your SQL code here
INSERT INTO salix.ACL (model, property, accessType, permission, principalType, principalId)
VALUES( 'Ticket', 'myLastModified', '*', 'ALLOW', 'ROLE', 'production');

View File

@ -0,0 +1,55 @@
const {models} = require('vn-loopback/server/server');
const LoopBackContext = require('loopback-context');
describe('ItemShelving upsertItem()', () => {
const warehouseFk = 1;
let ctx;
let options;
let tx;
beforeEach(async() => {
ctx = {
req: {
accessToken: {userId: 9},
headers: {origin: 'http://localhost'}
},
args: {}
};
spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({
active: ctx.req
});
options = {transaction: tx};
tx = await models.ItemShelving.beginTransaction({});
options.transaction = tx;
});
afterEach(async() => {
await tx.rollback();
});
it('should add two new records', async() => {
const shelvingFk = 'ZPP';
const items = [1, 1, 1, 2];
await models.ItemShelving.upsertItem(ctx, shelvingFk, items, warehouseFk, options);
const itemShelvings = await models.ItemShelving.find({where: {shelvingFk}}, options);
expect(itemShelvings.length).toEqual(2);
});
it('should update the visible items', async() => {
const shelvingFk = 'GVC';
const items = [2, 2];
const {visible: itemsBefore} = await models.ItemShelving.findOne({
where: {shelvingFk, itemFk: items[0]}
}, options);
await models.ItemShelving.upsertItem(ctx, shelvingFk, items, warehouseFk, options);
const {visible: itemsAfter} = await models.ItemShelving.findOne({
where: {shelvingFk, itemFk: items[0]}
}, options);
expect(itemsAfter).toEqual(itemsBefore + 2);
});
});

View File

@ -0,0 +1,64 @@
module.exports = Self => {
Self.remoteMethodCtx('upsertItem', {
description: 'Add a record or update it if it already exists.',
accessType: 'WRITE',
accepts: [{
arg: 'shelvingFk',
type: 'string',
required: true,
},
{
arg: 'items',
type: ['number'],
required: true,
description: 'array of item foreign keys'
},
{
arg: 'warehouseFk',
type: 'number',
required: true
}],
http: {
path: `/upsertItem`,
verb: 'POST'
}
});
Self.upsertItem = async(ctx, shelvingFk, items, warehouseFk, options) => {
const myOptions = {userId: ctx.req.accessToken.userId};
let tx;
if (typeof options == 'object')
Object.assign(myOptions, options);
if (!myOptions.transaction) {
tx = await Self.beginTransaction({});
myOptions.transaction = tx;
}
const discardItems = new Set();
const itemCounts = items.reduce((acc, item) => {
acc[item] = (acc[item] || 0) + 1;
return acc;
}, {});
try {
for (let item of items) {
if (!discardItems.has(item)) {
let quantity = itemCounts[item];
discardItems.add(item);
await Self.rawSql('CALL vn.itemShelving_add(?, ?, ?, NULL, NULL, NULL, ?)',
[shelvingFk, item, quantity, warehouseFk], myOptions
);
}
}
if (tx) await tx.commit();
} catch (e) {
if (tx) await tx.rollback();
throw e;
}
};
};

View File

@ -1,5 +1,6 @@
module.exports = Self => { module.exports = Self => {
require('../methods/item-shelving/deleteItemShelvings')(Self); require('../methods/item-shelving/deleteItemShelvings')(Self);
require('../methods/item-shelving/upsertItem')(Self);
require('../methods/item-shelving/getInventory')(Self); require('../methods/item-shelving/getInventory')(Self);
require('../methods/item-shelving/getAlternative')(Self); require('../methods/item-shelving/getAlternative')(Self);
require('../methods/item-shelving/updateFromSale')(Self); require('../methods/item-shelving/updateFromSale')(Self);

View File

@ -0,0 +1,25 @@
module.exports = Self => {
Self.remoteMethodCtx('myLastModified', {
description: 'Get list of last tickets which user has modified',
accessType: 'READ',
returns: {
type: 'object',
root: true
},
http: {
path: `/myLastModified`,
verb: 'GET'
}
});
Self.myLastModified = async ctx => {
const userId = ctx.req.accessToken.userId;
const query =
`SELECT ticketFk, MAX(created) created
FROM ticketTracking tt
WHERE tt.userFk = ?
GROUP BY ticketFk
LIMIT 5;`;
return await Self.rawSql(query, [userId]);
};
};

View File

@ -0,0 +1,10 @@
const {models} = require('vn-loopback/server/server');
describe('myLastModified()', () => {
it('return list of last tickets which user has modified', async() => {
let ctx = {req: {accessToken: {userId: 100}}};
let response = await models.Ticket.myLastModified(ctx);
expect(response.length).toBeGreaterThan(0);
});
});

View File

@ -45,4 +45,5 @@ module.exports = function(Self) {
require('../methods/ticket/invoiceTickets')(Self); require('../methods/ticket/invoiceTickets')(Self);
require('../methods/ticket/invoiceTicketsAndPdf')(Self); require('../methods/ticket/invoiceTicketsAndPdf')(Self);
require('../methods/ticket/docuwareDownload')(Self); require('../methods/ticket/docuwareDownload')(Self);
require('../methods/ticket/myLastModified')(Self);
}; };