7167-testToMaster_2414 #2244
|
@ -19,6 +19,10 @@ BEGIN
|
|||
DECLARE vItemFk INT;
|
||||
|
||||
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
|
||||
|
||||
|
|
|
@ -28,7 +28,7 @@ BEGIN
|
|||
MAKETIME(pb.HH,pb.mm,0) etd,
|
||||
pb.routeFk,
|
||||
FLOOR(s.quantity / ish.packing) stickers,
|
||||
ish.packing,
|
||||
IF(i.isBoxPickingMode, ish.packing, i.packingOut) packing,
|
||||
b.packagingFk
|
||||
FROM sale s
|
||||
JOIN item i ON i.id = s.itemFk
|
||||
|
|
|
@ -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');
|
|
@ -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);
|
||||
});
|
||||
});
|
|
@ -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;
|
||||
}
|
||||
};
|
||||
};
|
|
@ -1,5 +1,6 @@
|
|||
module.exports = Self => {
|
||||
require('../methods/item-shelving/deleteItemShelvings')(Self);
|
||||
require('../methods/item-shelving/upsertItem')(Self);
|
||||
require('../methods/item-shelving/getInventory')(Self);
|
||||
require('../methods/item-shelving/getAlternative')(Self);
|
||||
require('../methods/item-shelving/updateFromSale')(Self);
|
||||
|
|
|
@ -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]);
|
||||
};
|
||||
};
|
|
@ -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);
|
||||
});
|
||||
});
|
|
@ -45,4 +45,5 @@ module.exports = function(Self) {
|
|||
require('../methods/ticket/invoiceTickets')(Self);
|
||||
require('../methods/ticket/invoiceTicketsAndPdf')(Self);
|
||||
require('../methods/ticket/docuwareDownload')(Self);
|
||||
require('../methods/ticket/myLastModified')(Self);
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue