diff --git a/db/changes/10480-june/00-itemType.sql b/db/changes/10480-june/00-itemType.sql new file mode 100644 index 000000000..d201acf37 --- /dev/null +++ b/db/changes/10480-june/00-itemType.sql @@ -0,0 +1,5 @@ +ALTER TABLE `vn`.`itemType` CHANGE `transaction` transaction__ tinyint(4) DEFAULT 0 NOT NULL; +ALTER TABLE `vn`.`itemType` CHANGE location location__ varchar(10) CHARACTER SET utf8mb3 COLLATE utf8mb3_unicode_ci DEFAULT NULL NULL; +ALTER TABLE `vn`.`itemType` CHANGE hasComponents hasComponents__ tinyint(1) DEFAULT 1 NOT NULL; +ALTER TABLE `vn`.`itemType` CHANGE warehouseFk warehouseFk__ smallint(6) unsigned DEFAULT 60 NOT NULL; +ALTER TABLE `vn`.`itemType` CHANGE compression compression__ decimal(5,2) DEFAULT 1.00 NULL; \ No newline at end of file diff --git a/db/dump/fixtures.sql b/db/dump/fixtures.sql index 78899b82d..e6c7cb3d3 100644 --- a/db/dump/fixtures.sql +++ b/db/dump/fixtures.sql @@ -146,7 +146,9 @@ INSERT INTO `vn`.`warehouse`(`id`, `name`, `code`, `isComparative`, `isInventory (3, 'Warehouse Three', NULL, 1, 1, 1, 1, 0, 0, 2, 1, 1), (4, 'Warehouse Four', NULL, 1, 1, 1, 1, 0, 0, 2, 1, 1), (5, 'Warehouse Five', NULL, 1, 1, 1, 1, 0, 0, 2, 1, 1), - (13, 'Inventory', NULL, 1, 1, 1, 0, 0, 0, 2, 1, 0); + (13, 'Inventory', NULL, 1, 1, 1, 0, 0, 0, 2, 1, 0), + (60, 'Algemesi', NULL, 1, 1, 1, 0, 0, 0, 2, 1, 0); + INSERT INTO `vn`.`sector`(`id`, `description`, `warehouseFk`, `isPreviousPreparedByPacking`, `code`) VALUES @@ -795,14 +797,14 @@ INSERT INTO `vn`.`temperature`(`code`, `name`, `description`) ('warm', 'Warm', 'Warm'), ('cool', 'Cool', 'Cool'); -INSERT INTO `vn`.`itemType`(`id`, `code`, `name`, `categoryFk`, `warehouseFk`, `life`,`workerFk`, `isPackaging`, `temperatureFk`) +INSERT INTO `vn`.`itemType`(`id`, `code`, `name`, `categoryFk`, `life`, `workerFk`, `isPackaging`, `temperatureFk`) VALUES - (1, 'CRI', 'Crisantemo', 2, 1, 31, 35, 0, 'cool'), - (2, 'ITG', 'Anthurium', 1, 1, 31, 35, 0, 'cool'), - (3, 'WPN', 'Paniculata', 2, 1, 31, 35, 0, 'cool'), - (4, 'PRT', 'Delivery ports', 3, 1, NULL, 35, 1, 'warm'), - (5, 'CON', 'Container', 3, 1, NULL, 35, 1, 'warm'), - (6, 'ALS', 'Alstroemeria', 1, 1, 31, 16, 0, 'warm'); + (1, 'CRI', 'Crisantemo', 2, 31, 35, 0, 'cool'), + (2, 'ITG', 'Anthurium', 1, 31, 35, 0, 'cool'), + (3, 'WPN', 'Paniculata', 2, 31, 35, 0, 'cool'), + (4, 'PRT', 'Delivery ports', 3, NULL, 35, 1, 'warm'), + (5, 'CON', 'Container', 3, NULL, 35, 1, 'warm'), + (6, 'ALS', 'Alstroemeria', 1, 31, 16, 0, 'warm'); INSERT INTO `vn`.`ink`(`id`, `name`, `picture`, `showOrder`, `hex`) VALUES diff --git a/modules/entry/back/methods/entry/latestBuysFilter.js b/modules/entry/back/methods/entry/latestBuysFilter.js index 9a21d4472..00f72ea14 100644 --- a/modules/entry/back/methods/entry/latestBuysFilter.js +++ b/modules/entry/back/methods/entry/latestBuysFilter.js @@ -148,6 +148,8 @@ module.exports = Self => { stmt = new ParameterizedSQL(`CALL cache.visible_refresh(@calc_id, FALSE, ?)`, [warehouse.id]); stmts.push(stmt); + const userConfig = await models.UserConfig.getUserConfig(ctx, myOptions); + const date = new Date(); date.setHours(0, 0, 0, 0); stmt = new ParameterizedSQL(` @@ -201,7 +203,7 @@ module.exports = Self => { LEFT JOIN cache.visible v ON v.item_id = lb.item_id AND v.calc_id = @calc_id JOIN item i ON i.id = lb.item_id - JOIN itemType it ON it.id = i.typeFk AND lb.warehouse_id = it.warehouseFk + JOIN itemType it ON it.id = i.typeFk AND lb.warehouse_id = ? JOIN buy b ON b.id = lb.buy_id LEFT JOIN itemCategory ic ON ic.id = it.categoryFk LEFT JOIN itemType t ON t.id = i.typeFk @@ -209,7 +211,7 @@ module.exports = Self => { LEFT JOIN origin ori ON ori.id = i.originFk LEFT JOIN entry e ON e.id = b.entryFk AND e.created >= DATE_SUB(? ,INTERVAL 1 YEAR) LEFT JOIN supplier s ON s.id = e.supplierFk` - , [date]); + , [userConfig.warehouseFk, date]); if (ctx.args.tags) { let i = 1; diff --git a/modules/entry/back/methods/entry/specs/editLatestBuys.spec.js b/modules/entry/back/methods/entry/specs/editLatestBuys.spec.js index 2413c18f6..8e1921a0e 100644 --- a/modules/entry/back/methods/entry/specs/editLatestBuys.spec.js +++ b/modules/entry/back/methods/entry/specs/editLatestBuys.spec.js @@ -9,7 +9,8 @@ describe('Buy editLatestsBuys()', () => { const ctx = { args: { search: 'Ranged weapon longbow 2m' - } + }, + req: {accessToken: {userId: 1}} }; const [original] = await models.Buy.latestBuysFilter(ctx, null, options); @@ -40,7 +41,8 @@ describe('Buy editLatestsBuys()', () => { const ctx = { args: { filter: filter - } + }, + req: {accessToken: {userId: 1}} }; const field = 'size'; diff --git a/modules/entry/back/methods/entry/specs/latestBuysFilter.spec.js b/modules/entry/back/methods/entry/specs/latestBuysFilter.spec.js index 7c813ea89..9b1e60532 100644 --- a/modules/entry/back/methods/entry/specs/latestBuysFilter.spec.js +++ b/modules/entry/back/methods/entry/specs/latestBuysFilter.spec.js @@ -9,7 +9,8 @@ describe('Entry latests buys filter()', () => { const ctx = { args: { search: 'Ranged weapon longbow 2m' - } + }, + req: {accessToken: {userId: 1}} }; const results = await models.Buy.latestBuysFilter(ctx, options); @@ -33,7 +34,8 @@ describe('Entry latests buys filter()', () => { const ctx = { args: { id: 1 - } + }, + req: {accessToken: {userId: 1}} }; const results = await models.Buy.latestBuysFilter(ctx, options); @@ -57,7 +59,8 @@ describe('Entry latests buys filter()', () => { tags: [ {tagFk: 27, value: '2m'} ] - } + }, + req: {accessToken: {userId: 1}} }; const results = await models.Buy.latestBuysFilter(ctx, options); @@ -79,7 +82,8 @@ describe('Entry latests buys filter()', () => { const ctx = { args: { categoryFk: 1 - } + }, + req: {accessToken: {userId: 1}} }; const results = await models.Buy.latestBuysFilter(ctx, options); @@ -101,7 +105,8 @@ describe('Entry latests buys filter()', () => { const ctx = { args: { typeFk: 2 - } + }, + req: {accessToken: {userId: 1}} }; const results = await models.Buy.latestBuysFilter(ctx, options); @@ -123,7 +128,8 @@ describe('Entry latests buys filter()', () => { const ctx = { args: { active: true - } + }, + req: {accessToken: {userId: 1}} }; const results = await models.Buy.latestBuysFilter(ctx, options); @@ -145,7 +151,8 @@ describe('Entry latests buys filter()', () => { const ctx = { args: { active: false - } + }, + req: {accessToken: {userId: 1}} }; const results = await models.Buy.latestBuysFilter(ctx, options); @@ -167,7 +174,8 @@ describe('Entry latests buys filter()', () => { const ctx = { args: { visible: true - } + }, + req: {accessToken: {userId: 1}} }; const results = await models.Buy.latestBuysFilter(ctx, options); @@ -189,7 +197,8 @@ describe('Entry latests buys filter()', () => { const ctx = { args: { visible: false - } + }, + req: {accessToken: {userId: 1}} }; const results = await models.Buy.latestBuysFilter(ctx, options); @@ -211,7 +220,8 @@ describe('Entry latests buys filter()', () => { const ctx = { args: { floramondo: true - } + }, + req: {accessToken: {userId: 1}} }; const results = await models.Buy.latestBuysFilter(ctx, options); @@ -233,7 +243,8 @@ describe('Entry latests buys filter()', () => { const ctx = { args: { floramondo: false - } + }, + req: {accessToken: {userId: 1}} }; const results = await models.Buy.latestBuysFilter(ctx, options); @@ -255,7 +266,8 @@ describe('Entry latests buys filter()', () => { const ctx = { args: { salesPersonFk: 35 - } + }, + req: {accessToken: {userId: 1}} }; const results = await models.Buy.latestBuysFilter(ctx, options); @@ -277,7 +289,8 @@ describe('Entry latests buys filter()', () => { const ctx = { args: { description: 'Increases block' - } + }, + req: {accessToken: {userId: 1}} }; const results = await models.Buy.latestBuysFilter(ctx, options); @@ -299,7 +312,8 @@ describe('Entry latests buys filter()', () => { const ctx = { args: { supplierFk: 1 - } + }, + req: {accessToken: {userId: 1}} }; const results = await models.Buy.latestBuysFilter(ctx, options); @@ -328,7 +342,8 @@ describe('Entry latests buys filter()', () => { args: { from: from, to: to - } + }, + req: {accessToken: {userId: 1}} }; const results = await models.Buy.latestBuysFilter(ctx, options); diff --git a/modules/item/back/methods/item/filter.js b/modules/item/back/methods/item/filter.js index 5755de69b..8b2a014e6 100644 --- a/modules/item/back/methods/item/filter.js +++ b/modules/item/back/methods/item/filter.js @@ -86,6 +86,7 @@ module.exports = Self => { Self.filter = async(ctx, filter, options) => { const conn = Self.dataSource.connector; + const models = Self.app.models; const myOptions = {}; if (typeof options == 'object') @@ -140,6 +141,8 @@ module.exports = Self => { filter = mergeFilters(filter, {where}); + const userConfig = await models.UserConfig.getUserConfig(ctx, myOptions); + const stmts = []; const stmt = new ParameterizedSQL( `SELECT @@ -179,11 +182,11 @@ module.exports = Self => { LEFT JOIN intrastat intr ON intr.id = i.intrastatFk LEFT JOIN producer pr ON pr.id = i.producerFk LEFT JOIN origin ori ON ori.id = i.originFk - LEFT JOIN cache.last_buy lb ON lb.item_id = i.id AND lb.warehouse_id = it.warehouseFk + LEFT JOIN cache.last_buy lb ON lb.item_id = i.id AND lb.warehouse_id = ? LEFT JOIN buy b ON b.id = lb.buy_id LEFT JOIN entry e ON e.id = b.entryFk LEFT JOIN supplier s ON s.id = e.supplierFk` - ); + , [userConfig.warehouseFk]); if (ctx.args.tags) { let i = 1; diff --git a/modules/item/back/methods/item/getCard.js b/modules/item/back/methods/item/getCard.js index 8bb88fc86..c4ee09d95 100644 --- a/modules/item/back/methods/item/getCard.js +++ b/modules/item/back/methods/item/getCard.js @@ -30,7 +30,7 @@ module.exports = Self => { { relation: 'itemType', scope: { - fields: ['id', 'name', 'workerFk', 'warehouseFk'], + fields: ['id', 'name', 'workerFk'], include: [{ relation: 'worker', scope: { diff --git a/modules/item/back/methods/item/getSummary.js b/modules/item/back/methods/item/getSummary.js index ffcfc806e..738976e60 100644 --- a/modules/item/back/methods/item/getSummary.js +++ b/modules/item/back/methods/item/getSummary.js @@ -34,7 +34,7 @@ module.exports = Self => { include: [ {relation: 'itemType', scope: { - fields: ['id', 'name', 'workerFk', 'warehouseFk'], + fields: ['id', 'name', 'workerFk'], include: [{ relation: 'worker', scope: { diff --git a/modules/item/back/methods/item/specs/filter.spec.js b/modules/item/back/methods/item/specs/filter.spec.js index 6a173576d..14467d1d8 100644 --- a/modules/item/back/methods/item/specs/filter.spec.js +++ b/modules/item/back/methods/item/specs/filter.spec.js @@ -7,7 +7,7 @@ describe('item filter()', () => { try { const filter = {}; - const ctx = {args: {filter: filter, search: 1}}; + const ctx = {args: {filter: filter, search: 1}, req: {accessToken: {userId: 1}}}; const result = await models.Item.filter(ctx, filter, options); expect(result.length).toEqual(1); @@ -26,7 +26,7 @@ describe('item filter()', () => { try { const filter = {}; - const ctx = {args: {filter: filter, search: 4444444444}}; + const ctx = {args: {filter: filter, search: 4444444444}, req: {accessToken: {userId: 1}}}; const result = await models.Item.filter(ctx, filter, options); expect(result.length).toEqual(1); @@ -49,7 +49,7 @@ describe('item filter()', () => { limit: 8 }; const tags = [{value: 'medical box', tagFk: 58}]; - const ctx = {args: {filter: filter, typeFk: 5, tags: tags}}; + const ctx = {args: {filter: filter, typeFk: 5, tags: tags}, req: {accessToken: {userId: 1}}}; const result = await models.Item.filter(ctx, filter, options); expect(result.length).toEqual(2); @@ -67,7 +67,7 @@ describe('item filter()', () => { try { const filter = {}; - const ctx = {args: {filter: filter, isFloramondo: true}}; + const ctx = {args: {filter: filter, isFloramondo: true}, req: {accessToken: {userId: 1}}}; const result = await models.Item.filter(ctx, filter, options); expect(result.length).toEqual(3); @@ -86,7 +86,7 @@ describe('item filter()', () => { try { const filter = {}; - const ctx = {args: {filter: filter, buyerFk: 16}}; + const ctx = {args: {filter: filter, buyerFk: 16}, req: {accessToken: {userId: 1}}}; const result = await models.Item.filter(ctx, filter, options); expect(result.length).toEqual(2); @@ -106,7 +106,7 @@ describe('item filter()', () => { try { const filter = {}; - const ctx = {args: {filter: filter, supplierFk: 1}}; + const ctx = {args: {filter: filter, supplierFk: 1}, req: {accessToken: {userId: 1}}}; const result = await models.Item.filter(ctx, filter, options); expect(result.length).toEqual(2); diff --git a/modules/item/back/models/item-type.json b/modules/item/back/models/item-type.json index 843d9877f..74cdf3fc8 100644 --- a/modules/item/back/models/item-type.json +++ b/modules/item/back/models/item-type.json @@ -34,11 +34,6 @@ "model": "Worker", "foreignKey": "workerFk" }, - "warehouse": { - "type": "belongsTo", - "model": "Warehouse", - "foreignKey": "warehouseFk" - }, "category": { "type": "belongsTo", "model": "ItemCategory",