diff --git a/db/changes/230201/00-validPriorities_ItemConfig.sql b/db/changes/230201/00-validPriorities_ItemConfig.sql new file mode 100644 index 0000000000..2e22352fe3 --- /dev/null +++ b/db/changes/230201/00-validPriorities_ItemConfig.sql @@ -0,0 +1,8 @@ +ALTER TABLE `vn`.`itemConfig` ADD defaultTag INT DEFAULT 56 NOT NULL; +ALTER TABLE `vn`.`itemConfig` ADD CONSTRAINT itemConfig_FK FOREIGN KEY (defaultTag) REFERENCES vn.tag(id); +ALTER TABLE `vn`.`itemConfig` ADD validPriorities varchar(50) DEFAULT '[1,2,3]' NOT NULL; +ALTER TABLE `vn`.`itemConfig` ADD defaultPriority INT DEFAULT 2 NOT NULL; + +INSERT INTO `salix`.`ACL` +(model, property, accessType, permission, principalType, principalId) +VALUES('ItemConfig', '*', 'READ', 'ALLOW', 'ROLE', 'buyer'); diff --git a/db/dump/fixtures.sql b/db/dump/fixtures.sql index fba094ef47..5d6849cef0 100644 --- a/db/dump/fixtures.sql +++ b/db/dump/fixtures.sql @@ -2719,6 +2719,10 @@ INSERT INTO `vn`.`collection` (`id`, `created`, `workerFk`, `stateFk`, `itemPack VALUES (3, util.VN_NOW(), 1107, 5, NULL, 0, 0, 1, NULL, NULL); +INSERT INTO `vn`.`itemConfig` (`id`, `isItemTagTriggerDisabled`, `monthToDeactivate`, `wasteRecipients`, `validPriorities`, `defaultPriority`, `defaultTag`) + VALUES + (0, 0, 24, '', '[1,2,3]', 2, 56); + INSERT INTO `vn`.`ticketCollection` (`ticketFk`, `collectionFk`, `created`, `level`, `wagon`, `smartTagFk`, `usedShelves`, `itemCount`, `liters`) VALUES (9, 3, util.VN_NOW(), NULL, 0, NULL, NULL, NULL, NULL); diff --git a/e2e/helpers/selectors.js b/e2e/helpers/selectors.js index 04f2d45692..c2ad63484c 100644 --- a/e2e/helpers/selectors.js +++ b/e2e/helpers/selectors.js @@ -522,7 +522,7 @@ export default { }, itemLog: { anyLineCreated: 'vn-item-log > vn-log vn-tbody > vn-tr', - fourthLineCreatedProperty: 'vn-item-log > vn-log vn-tbody > vn-tr:nth-child(4) table tr:nth-child(3) td.after', + fifthLineCreatedProperty: 'vn-item-log > vn-log vn-tbody > vn-tr:nth-child(5) table tr:nth-child(2) td.after', }, ticketSummary: { header: 'vn-ticket-summary > vn-card > h5', diff --git a/e2e/paths/04-item/10_item_log.spec.js b/e2e/paths/04-item/10_item_log.spec.js index f3ff6001cc..2a885fe6f6 100644 --- a/e2e/paths/04-item/10_item_log.spec.js +++ b/e2e/paths/04-item/10_item_log.spec.js @@ -48,17 +48,17 @@ describe('Item log path', () => { await page.accessToSection('item.card.log'); }); - it(`should confirm the log is showing 4 entries`, async() => { + it(`should confirm the log is showing 5 entries`, async() => { await page.waitForSelector(selectors.itemLog.anyLineCreated); const anyLineCreatedCount = await page.countElement(selectors.itemLog.anyLineCreated); - expect(anyLineCreatedCount).toEqual(4); + expect(anyLineCreatedCount).toEqual(5); }); it(`should confirm the log is showing the intrastat for the created item`, async() => { - const fourthLineCreatedProperty = await page - .waitToGetProperty(selectors.itemLog.fourthLineCreatedProperty, 'innerText'); + const fifthLineCreatedProperty = await page + .waitToGetProperty(selectors.itemLog.fifthLineCreatedProperty, 'innerText'); - expect(fourthLineCreatedProperty).toEqual('Coral y materiales similares'); + expect(fifthLineCreatedProperty).toEqual('Coral y materiales similares'); }); }); diff --git a/modules/item/back/methods/item/new.js b/modules/item/back/methods/item/new.js index b84072a8a7..0057cb50f8 100644 --- a/modules/item/back/methods/item/new.js +++ b/modules/item/back/methods/item/new.js @@ -37,7 +37,6 @@ module.exports = Self => { 'typeFk', 'intrastatFk', 'originFk', - 'relevancy', 'priority', 'tag' ]; @@ -48,9 +47,9 @@ module.exports = Self => { } try { - const validPriorities = new Set([1, 2, 3]); - if (!validPriorities.has(params.priority)) - throw new UserError(`Valid priorities: ${[...validPriorities]}`); + const itemConfig = await models.ItemConfig.findOne({fields: ['validPriorities']}, myOptions); + if (!itemConfig.validPriorities.includes(params.priority)) + throw new UserError(`Valid priorities: ${[...itemConfig.validPriorities]}`); const provisionalName = params.provisionalName; delete params.provisionalName; diff --git a/modules/item/back/models/item-config.json b/modules/item/back/models/item-config.json index 364879986b..36d25e0bb0 100644 --- a/modules/item/back/models/item-config.json +++ b/modules/item/back/models/item-config.json @@ -16,6 +16,22 @@ "wasteRecipients": { "type": "string", "description": "Buyers waste report recipients" + }, + "validPriorities": { + "type": "array" + }, + "defaultPriority": { + "type": "int" + }, + "defaultTag": { + "type": "int" + } + }, + "relations": { + "tag": { + "type": "belongsTo", + "model": "Tag", + "foreignKey": "defaultTag" } } -} \ No newline at end of file +} diff --git a/modules/item/front/create/index.js b/modules/item/front/create/index.js index c3082ffd75..c9a121cd4e 100644 --- a/modules/item/front/create/index.js +++ b/modules/item/front/create/index.js @@ -4,11 +4,20 @@ import Section from 'salix/components/section'; class Controller extends Section { constructor($element, $) { super($element, $); - this.item = { - relevancy: 0, - priority: 2, - tag: 1 - }; + this.fetchDefaultPriorityTag(); + } + + fetchDefaultPriorityTag() { + const filter = {fields: ['defaultPriority', 'defaultTag'], limit: 1}; + this.$http.get(`ItemConfigs`, {filter}) + .then(res => { + if (res.data) { + this.item = { + priority: res.data[0].defaultPriority, + tag: res.data[0].defaultTag + }; + } + }); } onSubmit() {