From eaa7658b23088d7eeb844b40ec70a4a9074a39cf Mon Sep 17 00:00:00 2001 From: vicent Date: Tue, 12 Jul 2022 10:03:50 +0200 Subject: [PATCH 1/9] delete it.warehouseFk --- modules/entry/back/methods/entry/latestBuysFilter.js | 2 +- modules/item/back/methods/item/filter.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/entry/back/methods/entry/latestBuysFilter.js b/modules/entry/back/methods/entry/latestBuysFilter.js index 9a21d4472..bb0e4437c 100644 --- a/modules/entry/back/methods/entry/latestBuysFilter.js +++ b/modules/entry/back/methods/entry/latestBuysFilter.js @@ -201,7 +201,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 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 diff --git a/modules/item/back/methods/item/filter.js b/modules/item/back/methods/item/filter.js index 5755de69b..b8e856ba1 100644 --- a/modules/item/back/methods/item/filter.js +++ b/modules/item/back/methods/item/filter.js @@ -179,7 +179,7 @@ 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 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` From 6f3d4792d5c837c62c922fc7e1842d2c65a7ea09 Mon Sep 17 00:00:00 2001 From: vicent Date: Tue, 12 Jul 2022 10:03:58 +0200 Subject: [PATCH 2/9] update backTest --- .../entry/specs/latestBuysFilter.spec.js | 20 +++++++++---------- .../back/methods/item/specs/filter.spec.js | 8 ++++---- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/modules/entry/back/methods/entry/specs/latestBuysFilter.spec.js b/modules/entry/back/methods/entry/specs/latestBuysFilter.spec.js index 7c813ea89..cb1ed4793 100644 --- a/modules/entry/back/methods/entry/specs/latestBuysFilter.spec.js +++ b/modules/entry/back/methods/entry/specs/latestBuysFilter.spec.js @@ -15,7 +15,7 @@ describe('Entry latests buys filter()', () => { const results = await models.Buy.latestBuysFilter(ctx, options); const firstBuy = results[0]; - expect(results.length).toEqual(1); + expect(results.length).toEqual(3); expect(firstBuy.size).toEqual(70); await tx.rollback(); @@ -38,7 +38,7 @@ describe('Entry latests buys filter()', () => { const results = await models.Buy.latestBuysFilter(ctx, options); - expect(results.length).toEqual(1); + expect(results.length).toEqual(3); await tx.rollback(); } catch (e) { @@ -62,7 +62,7 @@ describe('Entry latests buys filter()', () => { const results = await models.Buy.latestBuysFilter(ctx, options); - expect(results.length).toBe(2); + expect(results.length).toBe(4); await tx.rollback(); } catch (e) { @@ -84,7 +84,7 @@ describe('Entry latests buys filter()', () => { const results = await models.Buy.latestBuysFilter(ctx, options); - expect(results.length).toBe(4); + expect(results.length).toBe(7); await tx.rollback(); } catch (e) { @@ -106,7 +106,7 @@ describe('Entry latests buys filter()', () => { const results = await models.Buy.latestBuysFilter(ctx, options); - expect(results.length).toBe(4); + expect(results.length).toBe(7); await tx.rollback(); } catch (e) { @@ -128,7 +128,7 @@ describe('Entry latests buys filter()', () => { const results = await models.Buy.latestBuysFilter(ctx, options); - expect(results.length).toBe(6); + expect(results.length).toBe(12); await tx.rollback(); } catch (e) { @@ -172,7 +172,7 @@ describe('Entry latests buys filter()', () => { const results = await models.Buy.latestBuysFilter(ctx, options); - expect(results.length).toBe(5); + expect(results.length).toBe(11); await tx.rollback(); } catch (e) { @@ -238,7 +238,7 @@ describe('Entry latests buys filter()', () => { const results = await models.Buy.latestBuysFilter(ctx, options); - expect(results.length).toBe(5); + expect(results.length).toBe(11); await tx.rollback(); } catch (e) { @@ -260,7 +260,7 @@ describe('Entry latests buys filter()', () => { const results = await models.Buy.latestBuysFilter(ctx, options); - expect(results.length).toBe(6); + expect(results.length).toBe(12); await tx.rollback(); } catch (e) { @@ -282,7 +282,7 @@ describe('Entry latests buys filter()', () => { const results = await models.Buy.latestBuysFilter(ctx, options); - expect(results.length).toBe(1); + expect(results.length).toBe(4); await tx.rollback(); } catch (e) { diff --git a/modules/item/back/methods/item/specs/filter.spec.js b/modules/item/back/methods/item/specs/filter.spec.js index 6a173576d..46c3c5dbe 100644 --- a/modules/item/back/methods/item/specs/filter.spec.js +++ b/modules/item/back/methods/item/specs/filter.spec.js @@ -1,7 +1,7 @@ const models = require('vn-loopback/server/server').models; describe('item filter()', () => { - it('should return 1 result filtering by id', async() => { + it('should return 3 result filtering by id', async() => { const tx = await models.Item.beginTransaction({}); const options = {transaction: tx}; @@ -10,7 +10,7 @@ describe('item filter()', () => { const ctx = {args: {filter: filter, search: 1}}; const result = await models.Item.filter(ctx, filter, options); - expect(result.length).toEqual(1); + expect(result.length).toEqual(3); expect(result[0].id).toEqual(1); await tx.rollback(); @@ -20,7 +20,7 @@ describe('item filter()', () => { } }); - it('should return 1 result filtering by barcode', async() => { + it('should return 2 result filtering by barcode', async() => { const tx = await models.Item.beginTransaction({}); const options = {transaction: tx}; @@ -29,7 +29,7 @@ describe('item filter()', () => { const ctx = {args: {filter: filter, search: 4444444444}}; const result = await models.Item.filter(ctx, filter, options); - expect(result.length).toEqual(1); + expect(result.length).toEqual(2); expect(result[0].id).toEqual(2); await tx.rollback(); From 7bf9a8c1002baf68a3d5d68db2df0fa298fbf4b2 Mon Sep 17 00:00:00 2001 From: vicent Date: Tue, 12 Jul 2022 11:52:47 +0200 Subject: [PATCH 3/9] delete itemType.warehouseFk --- db/changes/10480-june/00-itemType.sql | 5 +++++ db/dump/fixtures.sql | 18 ++++++++++-------- modules/item/back/methods/item/getCard.js | 2 +- modules/item/back/methods/item/getSummary.js | 2 +- 4 files changed, 17 insertions(+), 10 deletions(-) create mode 100644 db/changes/10480-june/00-itemType.sql 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 5a2188cb5..f8aade274 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 @@ -766,14 +768,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/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: { From 605da52286b59b4cfc70edcd45927e6ed87911b5 Mon Sep 17 00:00:00 2001 From: vicent Date: Fri, 29 Jul 2022 12:22:03 +0200 Subject: [PATCH 4/9] fix: replace it.warehouseFk by userConfig.warehouseFk --- modules/entry/back/methods/entry/latestBuysFilter.js | 4 +++- modules/item/back/methods/item/filter.js | 5 ++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/modules/entry/back/methods/entry/latestBuysFilter.js b/modules/entry/back/methods/entry/latestBuysFilter.js index bb0e4437c..42e44a31d 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 + JOIN itemType it ON it.id = i.typeFk AND lb.warehouse_id = ${userConfig.warehouseFk} 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 diff --git a/modules/item/back/methods/item/filter.js b/modules/item/back/methods/item/filter.js index b8e856ba1..724502601 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,7 +182,7 @@ 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 + LEFT JOIN cache.last_buy lb ON lb.item_id = i.id AND lb.warehouse_id = ${userConfig.warehouseFk} 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` From 840e792d13b5c7a310353cb9da2086f9f0ed10cc Mon Sep 17 00:00:00 2001 From: vicent Date: Fri, 29 Jul 2022 12:52:53 +0200 Subject: [PATCH 5/9] fix: backTest --- .../entry/specs/editLatestBuys.spec.js | 6 +- .../entry/specs/latestBuysFilter.spec.js | 65 ++++++++++++------- .../back/methods/item/specs/filter.spec.js | 20 +++--- 3 files changed, 54 insertions(+), 37 deletions(-) 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 cb1ed4793..9b1e60532 100644 --- a/modules/entry/back/methods/entry/specs/latestBuysFilter.spec.js +++ b/modules/entry/back/methods/entry/specs/latestBuysFilter.spec.js @@ -9,13 +9,14 @@ 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); const firstBuy = results[0]; - expect(results.length).toEqual(3); + expect(results.length).toEqual(1); expect(firstBuy.size).toEqual(70); await tx.rollback(); @@ -33,12 +34,13 @@ describe('Entry latests buys filter()', () => { const ctx = { args: { id: 1 - } + }, + req: {accessToken: {userId: 1}} }; const results = await models.Buy.latestBuysFilter(ctx, options); - expect(results.length).toEqual(3); + expect(results.length).toEqual(1); await tx.rollback(); } catch (e) { @@ -57,12 +59,13 @@ describe('Entry latests buys filter()', () => { tags: [ {tagFk: 27, value: '2m'} ] - } + }, + req: {accessToken: {userId: 1}} }; const results = await models.Buy.latestBuysFilter(ctx, options); - expect(results.length).toBe(4); + expect(results.length).toBe(2); await tx.rollback(); } catch (e) { @@ -79,12 +82,13 @@ describe('Entry latests buys filter()', () => { const ctx = { args: { categoryFk: 1 - } + }, + req: {accessToken: {userId: 1}} }; const results = await models.Buy.latestBuysFilter(ctx, options); - expect(results.length).toBe(7); + expect(results.length).toBe(4); await tx.rollback(); } catch (e) { @@ -101,12 +105,13 @@ describe('Entry latests buys filter()', () => { const ctx = { args: { typeFk: 2 - } + }, + req: {accessToken: {userId: 1}} }; const results = await models.Buy.latestBuysFilter(ctx, options); - expect(results.length).toBe(7); + expect(results.length).toBe(4); await tx.rollback(); } catch (e) { @@ -123,12 +128,13 @@ describe('Entry latests buys filter()', () => { const ctx = { args: { active: true - } + }, + req: {accessToken: {userId: 1}} }; const results = await models.Buy.latestBuysFilter(ctx, options); - expect(results.length).toBe(12); + expect(results.length).toBe(6); await tx.rollback(); } catch (e) { @@ -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,12 +174,13 @@ describe('Entry latests buys filter()', () => { const ctx = { args: { visible: true - } + }, + req: {accessToken: {userId: 1}} }; const results = await models.Buy.latestBuysFilter(ctx, options); - expect(results.length).toBe(11); + expect(results.length).toBe(5); await tx.rollback(); } catch (e) { @@ -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,12 +243,13 @@ describe('Entry latests buys filter()', () => { const ctx = { args: { floramondo: false - } + }, + req: {accessToken: {userId: 1}} }; const results = await models.Buy.latestBuysFilter(ctx, options); - expect(results.length).toBe(11); + expect(results.length).toBe(5); await tx.rollback(); } catch (e) { @@ -255,12 +266,13 @@ describe('Entry latests buys filter()', () => { const ctx = { args: { salesPersonFk: 35 - } + }, + req: {accessToken: {userId: 1}} }; const results = await models.Buy.latestBuysFilter(ctx, options); - expect(results.length).toBe(12); + expect(results.length).toBe(6); await tx.rollback(); } catch (e) { @@ -277,12 +289,13 @@ describe('Entry latests buys filter()', () => { const ctx = { args: { description: 'Increases block' - } + }, + req: {accessToken: {userId: 1}} }; const results = await models.Buy.latestBuysFilter(ctx, options); - expect(results.length).toBe(4); + expect(results.length).toBe(1); await tx.rollback(); } catch (e) { @@ -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/specs/filter.spec.js b/modules/item/back/methods/item/specs/filter.spec.js index 46c3c5dbe..14467d1d8 100644 --- a/modules/item/back/methods/item/specs/filter.spec.js +++ b/modules/item/back/methods/item/specs/filter.spec.js @@ -1,16 +1,16 @@ const models = require('vn-loopback/server/server').models; describe('item filter()', () => { - it('should return 3 result filtering by id', async() => { + it('should return 1 result filtering by id', async() => { const tx = await models.Item.beginTransaction({}); const options = {transaction: tx}; 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(3); + expect(result.length).toEqual(1); expect(result[0].id).toEqual(1); await tx.rollback(); @@ -20,16 +20,16 @@ describe('item filter()', () => { } }); - it('should return 2 result filtering by barcode', async() => { + it('should return 1 result filtering by barcode', async() => { const tx = await models.Item.beginTransaction({}); const options = {transaction: tx}; 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(2); + expect(result.length).toEqual(1); expect(result[0].id).toEqual(2); await tx.rollback(); @@ -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); From 224ea61a621e6ba73443eae5582205d3e12d74e6 Mon Sep 17 00:00:00 2001 From: vicent Date: Fri, 29 Jul 2022 13:07:25 +0200 Subject: [PATCH 6/9] fix: delete warehouseFk from itemType model --- modules/item/back/models/item-type.json | 5 ----- 1 file changed, 5 deletions(-) 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", From 8f5436535050d314e3a2b1a62138f36d7922db8f Mon Sep 17 00:00:00 2001 From: vicent Date: Wed, 10 Aug 2022 09:19:23 +0200 Subject: [PATCH 7/9] refator: parametrizardo con ? --- modules/entry/back/methods/entry/latestBuysFilter.js | 4 ++-- modules/item/back/methods/item/filter.js | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/modules/entry/back/methods/entry/latestBuysFilter.js b/modules/entry/back/methods/entry/latestBuysFilter.js index 42e44a31d..00f72ea14 100644 --- a/modules/entry/back/methods/entry/latestBuysFilter.js +++ b/modules/entry/back/methods/entry/latestBuysFilter.js @@ -203,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 = ${userConfig.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 @@ -211,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/item/back/methods/item/filter.js b/modules/item/back/methods/item/filter.js index 724502601..8b2a014e6 100644 --- a/modules/item/back/methods/item/filter.js +++ b/modules/item/back/methods/item/filter.js @@ -182,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 = ${userConfig.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; From 8c6c7345cd58630ce291569c5df983eae5ca497a Mon Sep 17 00:00:00 2001 From: vicent Date: Tue, 13 Sep 2022 10:27:08 +0200 Subject: [PATCH 8/9] fix: change GET by POST, to solve "Request Header Fields Too Large" --- modules/entry/back/methods/entry/importBuysPreview.js | 2 +- modules/entry/front/buy/import/index.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/entry/back/methods/entry/importBuysPreview.js b/modules/entry/back/methods/entry/importBuysPreview.js index 5b88b587c..730ecab0a 100644 --- a/modules/entry/back/methods/entry/importBuysPreview.js +++ b/modules/entry/back/methods/entry/importBuysPreview.js @@ -20,7 +20,7 @@ module.exports = Self => { }, http: { path: `/:id/importBuysPreview`, - verb: 'GET' + verb: 'POST' } }); diff --git a/modules/entry/front/buy/import/index.js b/modules/entry/front/buy/import/index.js index a2a28ef69..ba0a98e62 100644 --- a/modules/entry/front/buy/import/index.js +++ b/modules/entry/front/buy/import/index.js @@ -58,7 +58,7 @@ class Controller extends Section { fetchBuys(buys) { const params = {buys}; const query = `Entries/${this.$params.id}/importBuysPreview`; - this.$http.get(query, {params}).then(res => { + this.$http.post(query, params).then(res => { this.import.buys = res.data; }); } From b02aa8466c86087429082a2605ac219e2fef8700 Mon Sep 17 00:00:00 2001 From: vicent Date: Tue, 13 Sep 2022 10:27:17 +0200 Subject: [PATCH 9/9] fix: tfront --- modules/entry/front/buy/import/index.spec.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/modules/entry/front/buy/import/index.spec.js b/modules/entry/front/buy/import/index.spec.js index bf100dc83..036f52074 100644 --- a/modules/entry/front/buy/import/index.spec.js +++ b/modules/entry/front/buy/import/index.spec.js @@ -111,9 +111,8 @@ describe('Entry', () => { 'volume': 1125} ]; - const serializedParams = $httpParamSerializer({buys}); - const query = `Entries/1/importBuysPreview?${serializedParams}`; - $httpBackend.expectGET(query).respond(200, buys); + const query = `Entries/1/importBuysPreview`; + $httpBackend.expectPOST(query).respond(200, buys); controller.fetchBuys(buys); $httpBackend.flush();