From ff5e601a1e37cf5813dfed3a8cb4346f026ea291 Mon Sep 17 00:00:00 2001 From: Pau Navarro Date: Mon, 31 Oct 2022 14:43:31 +0100 Subject: [PATCH 1/5] Item islaid and test --- modules/item/back/methods/item/new.js | 10 ++++++++++ modules/item/back/methods/item/specs/new.spec.js | 10 ++++++++++ modules/item/back/models/item-type.json | 3 +++ 3 files changed, 23 insertions(+) diff --git a/modules/item/back/methods/item/new.js b/modules/item/back/methods/item/new.js index 0771b6b14..26ec32a9a 100644 --- a/modules/item/back/methods/item/new.js +++ b/modules/item/back/methods/item/new.js @@ -51,6 +51,16 @@ module.exports = Self => { const item = await models.Item.create(params, myOptions); + // set the item.isLaid to be the same as itemType.isLaid (itemType comes from item.typeFk) + + const itemType = await models.ItemType.findById(item.typeFk, myOptions); + + // Update the item with the new isLaid value + + item.isLaid = itemType.isLaid; + + await item.save(myOptions); + const typeTags = await models.ItemTypeTag.find({ where: {itemTypeFk: item.typeFk} }, myOptions); diff --git a/modules/item/back/methods/item/specs/new.spec.js b/modules/item/back/methods/item/specs/new.spec.js index 049ad0ff2..b9dd8d3ac 100644 --- a/modules/item/back/methods/item/specs/new.spec.js +++ b/modules/item/back/methods/item/specs/new.spec.js @@ -15,6 +15,11 @@ describe('item new()', () => { }; let item = await models.Item.new(itemParams, options); + + let itemType = await models.ItemType.findById(item.typeFk, options); + + item.isLaid = itemType.isLaid; + const temporalNameTag = await models.Tag.findOne({where: {name: 'Nombre temporal'}}, options); const temporalName = await models.ItemTag.findOne({ @@ -26,9 +31,14 @@ describe('item new()', () => { item = await models.Item.findById(item.id, null, options); + itemType = await models.ItemType.findById(item.typeFk, options); + + item.isLaid = itemType.isLaid; + expect(item.intrastatFk).toEqual(5080000); expect(item.originFk).toEqual(1); expect(item.typeFk).toEqual(2); + expect(item.isLaid).toEqual(0); expect(item.name).toEqual('planta'); expect(temporalName.value).toEqual('planta'); diff --git a/modules/item/back/models/item-type.json b/modules/item/back/models/item-type.json index 74cdf3fc8..df80463e0 100644 --- a/modules/item/back/models/item-type.json +++ b/modules/item/back/models/item-type.json @@ -26,6 +26,9 @@ }, "isUnconventionalSize": { "type": "number" + }, + "isLaid": { + "type": "number" } }, "relations": { From 7d7af6eb495e59599772c37b58278e762774a261 Mon Sep 17 00:00:00 2001 From: Pau Navarro Date: Fri, 4 Nov 2022 07:42:21 +0100 Subject: [PATCH 2/5] Modified model to allow modifications to isLaid --- modules/item/back/models/item.json | 3 +++ 1 file changed, 3 insertions(+) diff --git a/modules/item/back/models/item.json b/modules/item/back/models/item.json index 704c97434..2f58c30a9 100644 --- a/modules/item/back/models/item.json +++ b/modules/item/back/models/item.json @@ -143,6 +143,9 @@ }, "packingShelve": { "type": "number" + }, + "isLaid": { + "type": "boolean" } }, "relations": { From 11cf1ba414c13983be899f9b93c2bc838c21fced Mon Sep 17 00:00:00 2001 From: Pau Navarro Date: Fri, 4 Nov 2022 07:50:54 +0100 Subject: [PATCH 3/5] fix back test error --- modules/item/back/methods/item/specs/new.spec.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/item/back/methods/item/specs/new.spec.js b/modules/item/back/methods/item/specs/new.spec.js index b9dd8d3ac..7364faa7d 100644 --- a/modules/item/back/methods/item/specs/new.spec.js +++ b/modules/item/back/methods/item/specs/new.spec.js @@ -38,7 +38,7 @@ describe('item new()', () => { expect(item.intrastatFk).toEqual(5080000); expect(item.originFk).toEqual(1); expect(item.typeFk).toEqual(2); - expect(item.isLaid).toEqual(0); + expect(item.isLaid).toBeFalse(); expect(item.name).toEqual('planta'); expect(temporalName.value).toEqual('planta'); From 37292cee89db9578a6587cb6121d3fc19d05dabc Mon Sep 17 00:00:00 2001 From: Pau Navarro Date: Fri, 4 Nov 2022 08:12:46 +0100 Subject: [PATCH 4/5] remove comments --- modules/item/back/methods/item/new.js | 4 ---- 1 file changed, 4 deletions(-) diff --git a/modules/item/back/methods/item/new.js b/modules/item/back/methods/item/new.js index 26ec32a9a..d6a176b46 100644 --- a/modules/item/back/methods/item/new.js +++ b/modules/item/back/methods/item/new.js @@ -51,12 +51,8 @@ module.exports = Self => { const item = await models.Item.create(params, myOptions); - // set the item.isLaid to be the same as itemType.isLaid (itemType comes from item.typeFk) - const itemType = await models.ItemType.findById(item.typeFk, myOptions); - // Update the item with the new isLaid value - item.isLaid = itemType.isLaid; await item.save(myOptions); From 638fd62aae298cf1349620d71f3b9b2cd671cdfd Mon Sep 17 00:00:00 2001 From: Pau Navarro Date: Thu, 10 Nov 2022 07:17:54 +0100 Subject: [PATCH 5/5] added requested changes, refs #4492 @40m --- modules/item/back/methods/item/new.js | 10 ++++------ modules/item/back/models/item-type.json | 2 +- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/modules/item/back/methods/item/new.js b/modules/item/back/methods/item/new.js index d6a176b46..fae37836f 100644 --- a/modules/item/back/methods/item/new.js +++ b/modules/item/back/methods/item/new.js @@ -49,14 +49,12 @@ module.exports = Self => { const provisionalName = params.provisionalName; delete params.provisionalName; + const itemType = await models.ItemType.findById(params.typeFk, myOptions); + + params.isLaid = itemType.isLaid; + const item = await models.Item.create(params, myOptions); - const itemType = await models.ItemType.findById(item.typeFk, myOptions); - - item.isLaid = itemType.isLaid; - - await item.save(myOptions); - const typeTags = await models.ItemTypeTag.find({ where: {itemTypeFk: item.typeFk} }, myOptions); diff --git a/modules/item/back/models/item-type.json b/modules/item/back/models/item-type.json index df80463e0..c5c920b2f 100644 --- a/modules/item/back/models/item-type.json +++ b/modules/item/back/models/item-type.json @@ -28,7 +28,7 @@ "type": "number" }, "isLaid": { - "type": "number" + "type": "boolean" } }, "relations": {