From 8a4d9bd2bf88743e44f1d9bac6d9506034be3bf9 Mon Sep 17 00:00:00 2001 From: pablone Date: Fri, 10 Mar 2023 12:52:51 +0100 Subject: [PATCH 01/34] refs #5211 --- modules/item/back/models/item-shelving.json | 3 +++ 1 file changed, 3 insertions(+) diff --git a/modules/item/back/models/item-shelving.json b/modules/item/back/models/item-shelving.json index 0890350da..339b9ab6e 100644 --- a/modules/item/back/models/item-shelving.json +++ b/modules/item/back/models/item-shelving.json @@ -20,6 +20,9 @@ }, "created": { "type": "date" + }, + "isChecked": { + "type": "boolean" } }, "relations": { From fde854f5c2e078f4a277ad0ea649f6f01a744604 Mon Sep 17 00:00:00 2001 From: carlossa Date: Wed, 22 Mar 2023 10:21:15 +0100 Subject: [PATCH 02/34] refs #5250 campo de notes --- db/changes/231201/00-workerNotes.sql | 10 +++++ e2e/helpers/selectors.js | 6 +++ e2e/paths/03-worker/08_add_notes.spec.js | 42 +++++++++++++++++++ modules/worker/front/index.js | 3 ++ modules/worker/front/locale/es.yml | 2 + modules/worker/front/note/create/index.html | 30 +++++++++++++ modules/worker/front/note/create/index.js | 21 ++++++++++ .../worker/front/note/create/index.spec.js | 22 ++++++++++ .../worker/front/note/create/locale/es.yml | 2 + modules/worker/front/note/index/index.html | 31 ++++++++++++++ modules/worker/front/note/index/index.js | 22 ++++++++++ modules/worker/front/note/index/style.scss | 5 +++ modules/worker/front/routes.json | 19 +++++++++ 13 files changed, 215 insertions(+) create mode 100644 db/changes/231201/00-workerNotes.sql create mode 100644 e2e/paths/03-worker/08_add_notes.spec.js create mode 100644 modules/worker/front/note/create/index.html create mode 100644 modules/worker/front/note/create/index.js create mode 100644 modules/worker/front/note/create/index.spec.js create mode 100644 modules/worker/front/note/create/locale/es.yml create mode 100644 modules/worker/front/note/index/index.html create mode 100644 modules/worker/front/note/index/index.js create mode 100644 modules/worker/front/note/index/style.scss diff --git a/db/changes/231201/00-workerNotes.sql b/db/changes/231201/00-workerNotes.sql new file mode 100644 index 000000000..602ea3296 --- /dev/null +++ b/db/changes/231201/00-workerNotes.sql @@ -0,0 +1,10 @@ +CREATE TABLE `vn`.`workerObservation` ( + `id` mediumint(8) unsigned NOT NULL AUTO_INCREMENT, + `workerFk` int(10) unsigned DEFAULT NULL, + `userFk` int(10) unsigned DEFAULT NULL, + `text` text COLLATE utf8mb3_unicode_ci NOT NULL, + `created` timestamp NOT NULL DEFAULT current_timestamp(), + PRIMARY KEY (`id`), + CONSTRAINT `workerFk_workerObservation_FK` FOREIGN KEY (`workerFk`) REFERENCES `vn`.`worker` (`id`) ON UPDATE CASCADE, + CONSTRAINT `userFk_workerObservation_FK` FOREIGN KEY (`userFk`) REFERENCES `account`.`user`(`id`) ON UPDATE CASCADE +) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='Todas las observaciones referentes a un trabajador'; \ No newline at end of file diff --git a/e2e/helpers/selectors.js b/e2e/helpers/selectors.js index f20d75310..ad5ff2692 100644 --- a/e2e/helpers/selectors.js +++ b/e2e/helpers/selectors.js @@ -988,6 +988,12 @@ export default { locker: 'vn-worker-basic-data vn-input-number[ng-model="$ctrl.worker.locker"]', saveButton: 'vn-worker-basic-data button[type=submit]' }, + workerNotes: { + addNoteFloatButton: 'vn-float-button', + note: 'vn-textarea[ng-model="$ctrl.note.text"]', + saveButton: 'button[type=submit]', + firstNoteText: 'vn-worker-note .text' + }, workerPbx: { extension: 'vn-worker-pbx vn-textfield[ng-model="$ctrl.worker.sip.extension"]', saveButton: 'vn-worker-pbx button[type=submit]' diff --git a/e2e/paths/03-worker/08_add_notes.spec.js b/e2e/paths/03-worker/08_add_notes.spec.js new file mode 100644 index 000000000..eb2e4c041 --- /dev/null +++ b/e2e/paths/03-worker/08_add_notes.spec.js @@ -0,0 +1,42 @@ +import selectors from '../../helpers/selectors'; +import getBrowser from '../../helpers/puppeteer'; + +describe('Worker Add notes path', () => { + let browser; + let page; + beforeAll(async() => { + browser = await getBrowser(); + page = browser.page; + await page.loginAndModule('employee', 'worker'); + await page.accessToSearchResult('Bruce Banner'); + await page.accessToSection('worker.card.note.index'); + }); + + afterAll(async() => { + await browser.close(); + }); + + it(`should reach the notes index`, async() => { + await page.waitForState('worker.card.note.index'); + }); + + it(`should click on the add note button`, async() => { + await page.waitToClick(selectors.workerNotes.addNoteFloatButton); + await page.waitForState('worker.card.note.create'); + }); + + it(`should create a note`, async() => { + await page.waitForSelector(selectors.workerNotes.note); + await page.type(`${selectors.workerNotes.note} textarea`, 'Meeting with Black Widow 21st 9am'); + await page.waitToClick(selectors.workerNotes.saveButton); + const message = await page.waitForSnackbar(); + + expect(message.text).toContain('Data saved!'); + }); + + it('should confirm the note was created', async() => { + const result = await page.waitToGetProperty(selectors.workerNotes.firstNoteText, 'innerText'); + + expect(result).toEqual('Meeting with Black Widow 21st 9am'); + }); +}); diff --git a/modules/worker/front/index.js b/modules/worker/front/index.js index 657f6a8c6..8fad2c0df 100644 --- a/modules/worker/front/index.js +++ b/modules/worker/front/index.js @@ -18,3 +18,6 @@ import './log'; import './dms/index'; import './dms/create'; import './dms/edit'; +import './note/index'; +import './note/create'; + diff --git a/modules/worker/front/locale/es.yml b/modules/worker/front/locale/es.yml index b5bcfefa4..a25377122 100644 --- a/modules/worker/front/locale/es.yml +++ b/modules/worker/front/locale/es.yml @@ -31,3 +31,5 @@ Deallocate PDA: Desasignar PDA PDA deallocated: PDA desasignada PDA allocated: PDA asignada New PDA: Nueva PDA +Notes: Notas +New note: Nueva nota diff --git a/modules/worker/front/note/create/index.html b/modules/worker/front/note/create/index.html new file mode 100644 index 000000000..d09fc2da5 --- /dev/null +++ b/modules/worker/front/note/create/index.html @@ -0,0 +1,30 @@ + + +
+ + + + + + + + + + + + +
\ No newline at end of file diff --git a/modules/worker/front/note/create/index.js b/modules/worker/front/note/create/index.js new file mode 100644 index 000000000..81ee247db --- /dev/null +++ b/modules/worker/front/note/create/index.js @@ -0,0 +1,21 @@ +import ngModule from '../../module'; +import Section from 'salix/components/section'; + +export default class Controller extends Section { + constructor($element, $) { + super($element, $); + this.note = { + workerFk: parseInt(this.$params.id), + text: null + }; + } + + cancel() { + this.$state.go('worker.card.note.index', {id: this.$params.id}); + } +} + +ngModule.vnComponent('vnNoteWorkerCreate', { + template: require('./index.html'), + controller: Controller +}); diff --git a/modules/worker/front/note/create/index.spec.js b/modules/worker/front/note/create/index.spec.js new file mode 100644 index 000000000..d900c8ee0 --- /dev/null +++ b/modules/worker/front/note/create/index.spec.js @@ -0,0 +1,22 @@ +import './index'; + +describe('Worker', () => { + describe('Component vnNoteWorkerCreate', () => { + let $state; + let controller; + + beforeEach(ngModule('worker')); + + beforeEach(inject(($componentController, _$state_) => { + $state = _$state_; + $state.params.id = '1234'; + const $element = angular.element(''); + controller = $componentController('vnNoteWorkerCreate', {$element, $state}); + })); + + it('should define workerFk using $state.params.id', () => { + expect(controller.note.workerFk).toBe(1234); + expect(controller.note.worker).toBe(undefined); + }); + }); +}); diff --git a/modules/worker/front/note/create/locale/es.yml b/modules/worker/front/note/create/locale/es.yml new file mode 100644 index 000000000..bfe773f48 --- /dev/null +++ b/modules/worker/front/note/create/locale/es.yml @@ -0,0 +1,2 @@ +New note: Nueva nota +Note: Nota \ No newline at end of file diff --git a/modules/worker/front/note/index/index.html b/modules/worker/front/note/index/index.html new file mode 100644 index 000000000..4b72d60ab --- /dev/null +++ b/modules/worker/front/note/index/index.html @@ -0,0 +1,31 @@ + + + + +
+ + {{::note.worker.user.nickname}} + {{::note.created | date:'dd/MM/yyyy HH:mm'}} + + + {{::note.text}} + +
+
+
+ + + diff --git a/modules/worker/front/note/index/index.js b/modules/worker/front/note/index/index.js new file mode 100644 index 000000000..d20971413 --- /dev/null +++ b/modules/worker/front/note/index/index.js @@ -0,0 +1,22 @@ +import ngModule from '../../module'; +import Section from 'salix/components/section'; +import './style.scss'; + +export default class Controller extends Section { + constructor($element, $) { + super($element, $); + this.filter = { + order: 'created DESC', + }; + } +} + +Controller.$inject = ['$element', '$scope']; + +ngModule.vnComponent('vnWorkerNote', { + template: require('./index.html'), + controller: Controller, + bindings: { + worker: '<' + } +}); diff --git a/modules/worker/front/note/index/style.scss b/modules/worker/front/note/index/style.scss new file mode 100644 index 000000000..5ff6baf4f --- /dev/null +++ b/modules/worker/front/note/index/style.scss @@ -0,0 +1,5 @@ +vn-worker-note { + .note:last-child { + margin-bottom: 0; + } +} \ No newline at end of file diff --git a/modules/worker/front/routes.json b/modules/worker/front/routes.json index 64b98bfca..64cb186d6 100644 --- a/modules/worker/front/routes.json +++ b/modules/worker/front/routes.json @@ -11,6 +11,7 @@ ], "card": [ {"state": "worker.card.basicData", "icon": "settings"}, + {"state": "worker.card.note.index", "icon": "insert_drive_file"}, {"state": "worker.card.timeControl", "icon": "access_time"}, {"state": "worker.card.calendar", "icon": "icon-calendar"}, {"state": "worker.card.pda", "icon": "phone_android"}, @@ -72,6 +73,24 @@ "component": "vn-worker-log", "description": "Log", "acl": ["salesAssistant"] + }, { + "url": "/note", + "state": "worker.card.note", + "component": "ui-view", + "abstract": true + }, { + "url": "/index", + "state": "worker.card.note.index", + "component": "vn-worker-note", + "description": "Notes", + "params": { + "worker": "$ctrl.worker" + } + }, { + "url": "/create", + "state": "worker.card.note.create", + "component": "vn-note-worker-create", + "description": "New note" }, { "url": "/pbx", "state": "worker.card.pbx", From c68c78cc5b80fb7f935e86862e52d0c5479a344f Mon Sep 17 00:00:00 2001 From: carlossa Date: Fri, 24 Mar 2023 12:11:42 +0100 Subject: [PATCH 03/34] refs #5250 solucion error WorkerObserv --- db/changes/231201/00-workerNotes.sql | 6 ++- modules/worker/back/model-config.json | 3 ++ .../worker/back/models/worker-observation.js | 13 +++++++ .../back/models/worker-observation.json | 39 +++++++++++++++++++ modules/worker/front/note/index/index.html | 5 ++- 5 files changed, 63 insertions(+), 3 deletions(-) create mode 100644 modules/worker/back/models/worker-observation.js create mode 100644 modules/worker/back/models/worker-observation.json diff --git a/db/changes/231201/00-workerNotes.sql b/db/changes/231201/00-workerNotes.sql index 602ea3296..0d9eaae7e 100644 --- a/db/changes/231201/00-workerNotes.sql +++ b/db/changes/231201/00-workerNotes.sql @@ -7,4 +7,8 @@ CREATE TABLE `vn`.`workerObservation` ( PRIMARY KEY (`id`), CONSTRAINT `workerFk_workerObservation_FK` FOREIGN KEY (`workerFk`) REFERENCES `vn`.`worker` (`id`) ON UPDATE CASCADE, CONSTRAINT `userFk_workerObservation_FK` FOREIGN KEY (`userFk`) REFERENCES `account`.`user`(`id`) ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='Todas las observaciones referentes a un trabajador'; \ No newline at end of file +) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='Todas las observaciones referentes a un trabajador'; + +INSERT INTO `salix`.`ACL` (`model`, `property`, `accessType`, `permission`, `principalType`, `principalId`) + VALUES + ('WorkerObservation', '*', '*', 'ALLOW', 'ROLE', 'hr'); diff --git a/modules/worker/back/model-config.json b/modules/worker/back/model-config.json index 63fc65827..145934700 100644 --- a/modules/worker/back/model-config.json +++ b/modules/worker/back/model-config.json @@ -53,6 +53,9 @@ "Worker": { "dataSource": "vn" }, + "WorkerObservation": { + "dataSource": "vn" + }, "WorkerConfig": { "dataSource": "vn" }, diff --git a/modules/worker/back/models/worker-observation.js b/modules/worker/back/models/worker-observation.js new file mode 100644 index 000000000..3a4480265 --- /dev/null +++ b/modules/worker/back/models/worker-observation.js @@ -0,0 +1,13 @@ +module.exports = function(Self) { + Self.validate('text', isEnabled, {message: 'Description cannot be blank'}); + function isEnabled(err) { + if (!this.text) err(); + } + + Self.observe('before save', async function(ctx) { + ctx.instance.created = new Date(); + let token = ctx.options.accessToken; + let userId = token && token.userId; + ctx.instance.userFk = userId; + }); +}; diff --git a/modules/worker/back/models/worker-observation.json b/modules/worker/back/models/worker-observation.json new file mode 100644 index 000000000..90eb35837 --- /dev/null +++ b/modules/worker/back/models/worker-observation.json @@ -0,0 +1,39 @@ +{ + "name": "WorkerObservation", + "base": "VnModel", + "options": { + "mysql": { + "table": "workerObservation" + } + }, + "properties": { + "id": { + "id": true, + "type": "number" + }, + "workerFk": { + "type": "number" + }, + "userFk": { + "type": "number" + }, + "text": { + "type": "string" + }, + "created": { + "type": "date" + } + }, + "relations": { + "worker": { + "type": "belongsTo", + "model": "Worker", + "foreignKey": "workerFk" + }, + "user":{ + "type": "belongsTo", + "model": "Account", + "foreignKey": "userFk" + } + } +} diff --git a/modules/worker/front/note/index/index.html b/modules/worker/front/note/index/index.html index 4b72d60ab..9f5c27008 100644 --- a/modules/worker/front/note/index/index.html +++ b/modules/worker/front/note/index/index.html @@ -1,8 +1,9 @@ @@ -14,7 +15,7 @@ ng-repeat="note in notes" class="note vn-pa-sm border-solid border-radius vn-mb-md"> - {{::note.worker.user.nickname}} + {{::note.user.nickname}} {{::note.created | date:'dd/MM/yyyy HH:mm'}} From 06ac8f9910991c4991d3c10359233e78af4ca02c Mon Sep 17 00:00:00 2001 From: vicent Date: Tue, 28 Mar 2023 09:41:39 +0200 Subject: [PATCH 04/34] refs #5275 fix: si tenia valor el minPrice el checkbox siempre se marcaba. El checkbox no funcionaba cuando le pulsabas --- modules/item/back/methods/fixed-price/upsertFixedPrice.js | 2 +- modules/item/front/fixed-price/index.html | 3 ++- modules/item/front/fixed-price/index.js | 2 -- 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/modules/item/back/methods/fixed-price/upsertFixedPrice.js b/modules/item/back/methods/fixed-price/upsertFixedPrice.js index eb3eec1bd..edbd23604 100644 --- a/modules/item/back/methods/fixed-price/upsertFixedPrice.js +++ b/modules/item/back/methods/fixed-price/upsertFixedPrice.js @@ -87,7 +87,7 @@ module.exports = Self => { await targetItem.updateAttributes({ minPrice: args.minPrice, - hasMinPrice: args.minPrice ? true : false + hasMinPrice: args.hasMinPrice }, myOptions); const itemFields = [ diff --git a/modules/item/front/fixed-price/index.html b/modules/item/front/fixed-price/index.html index ce7cefe7a..43fe89552 100644 --- a/modules/item/front/fixed-price/index.html +++ b/modules/item/front/fixed-price/index.html @@ -140,7 +140,8 @@ + ng-model="price.hasMinPrice" + on-change="$ctrl.upsertPrice(price)"> Date: Tue, 28 Mar 2023 10:07:14 +0200 Subject: [PATCH 05/34] refs #5250 Self.validatesPresenceOf --- modules/worker/back/models/worker-observation.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/worker/back/models/worker-observation.js b/modules/worker/back/models/worker-observation.js index 3a4480265..413d9a2ba 100644 --- a/modules/worker/back/models/worker-observation.js +++ b/modules/worker/back/models/worker-observation.js @@ -1,5 +1,5 @@ module.exports = function(Self) { - Self.validate('text', isEnabled, {message: 'Description cannot be blank'}); + Self.validatesPresenceOf('text', isEnabled, {message: 'Description cannot be blank'}); function isEnabled(err) { if (!this.text) err(); } From fb1b39da175c107b1bc0cbee14dc177ffed5c518 Mon Sep 17 00:00:00 2001 From: vicent Date: Tue, 28 Mar 2023 10:30:02 +0200 Subject: [PATCH 06/34] =?UTF-8?q?refs=20#5275=20fix:=20al=20a=C3=B1adir=20?= =?UTF-8?q?art=C3=ADculo=20desde=20cero=20se=20muestra=20el=20nombre=20y?= =?UTF-8?q?=20se=20establecen=20las=20fechas=20por=20defecto?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../back/methods/fixed-price/upsertFixedPrice.js | 2 +- modules/item/front/fixed-price/index.html | 3 ++- modules/item/front/fixed-price/index.js | 12 +++++++++++- 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/modules/item/back/methods/fixed-price/upsertFixedPrice.js b/modules/item/back/methods/fixed-price/upsertFixedPrice.js index edbd23604..d815ed426 100644 --- a/modules/item/back/methods/fixed-price/upsertFixedPrice.js +++ b/modules/item/back/methods/fixed-price/upsertFixedPrice.js @@ -87,7 +87,7 @@ module.exports = Self => { await targetItem.updateAttributes({ minPrice: args.minPrice, - hasMinPrice: args.hasMinPrice + hasMinPrice: args.hasMinPrice ? args.hasMinPrice : false }, myOptions); const itemFields = [ diff --git a/modules/item/front/fixed-price/index.html b/modules/item/front/fixed-price/index.html index 43fe89552..584c4b14e 100644 --- a/modules/item/front/fixed-price/index.html +++ b/modules/item/front/fixed-price/index.html @@ -64,6 +64,7 @@ - {{price.name}} + {{itemFk.selection.name}}

{{price.subName}}

diff --git a/modules/item/front/fixed-price/index.js b/modules/item/front/fixed-price/index.js index 2eb53cfbd..1a7bf6466 100644 --- a/modules/item/front/fixed-price/index.js +++ b/modules/item/front/fixed-price/index.js @@ -36,7 +36,17 @@ export default class Controller extends Section { if (!this.$.model.data || this.$.model.data.length == 0) { this.$.model.data = []; this.$.model.proxiedData = []; - this.$.model.insert({}); + + const today = Date.vnNew(); + + const millisecsInDay = 86400000; + const daysInWeek = 7; + const nextWeek = new Date(today.getTime() + daysInWeek * millisecsInDay); + + this.$.model.insert({ + started: today, + ended: nextWeek + }); return; } From b4e04fcdad29c33815329b4c7492bb69cc8eff17 Mon Sep 17 00:00:00 2001 From: vicent Date: Tue, 28 Mar 2023 14:40:14 +0200 Subject: [PATCH 07/34] refs #5275 feat: colorear fechas --- modules/item/front/fixed-price/index.html | 24 +++++++----- modules/item/front/fixed-price/index.js | 22 +++++++++++ modules/item/front/fixed-price/style.scss | 46 +++++++++++++++-------- 3 files changed, 66 insertions(+), 26 deletions(-) diff --git a/modules/item/front/fixed-price/index.html b/modules/item/front/fixed-price/index.html index 584c4b14e..0bc53aa3f 100644 --- a/modules/item/front/fixed-price/index.html +++ b/modules/item/front/fixed-price/index.html @@ -152,18 +152,22 @@
- - + + + + - - + + + + 0) return 'warning'; + } + add() { if (!this.$.model.data || this.$.model.data.length == 0) { this.$.model.data = []; diff --git a/modules/item/front/fixed-price/style.scss b/modules/item/front/fixed-price/style.scss index ba3878dba..d1f968c37 100644 --- a/modules/item/front/fixed-price/style.scss +++ b/modules/item/front/fixed-price/style.scss @@ -1,20 +1,34 @@ @import "variables"; -smart-table table{ - [shrink-field]{ - width: 80px; - max-width: 80px; +vn-fixed-price{ + smart-table table{ + [shrink-field]{ + width: 80px; + max-width: 80px; + } + [shrink-field-expand]{ + width: 150px; + max-width: 150px; + } } - [shrink-field-expand]{ - width: 150px; - max-width: 150px; + + .minPrice { + align-items: center; + text-align: center; + vn-input-number { + width: 90px; + max-width: 90px; + } + } + + smart-table table tbody > * > td .chip { + padding: 0px; + } + + smart-table table tbody > * > td .chip.warning { + color: $color-font-bg + } + + .vn-field > .container > .infix > .control > input { + color: inherit; } } - -.minPrice { - align-items: center; - text-align: center; - vn-input-number { - width: 90px; - max-width: 90px; - } -} \ No newline at end of file From c53c54b6cd1f18b8c9c0f16e7c72272f4274b8ed Mon Sep 17 00:00:00 2001 From: vicent Date: Tue, 28 Mar 2023 14:59:08 +0200 Subject: [PATCH 08/34] refs #5275 feat: modificar masivamente --- modules/item/front/fixed-price/index.html | 113 ++++++++++++++++--- modules/item/front/fixed-price/index.js | 99 +++++++++++++++- modules/item/front/fixed-price/locale/es.yml | 2 + modules/item/front/fixed-price/style.scss | 12 ++ 4 files changed, 209 insertions(+), 17 deletions(-) diff --git a/modules/item/front/fixed-price/index.html b/modules/item/front/fixed-price/index.html index 0bc53aa3f..af41b1bc8 100644 --- a/modules/item/front/fixed-price/index.html +++ b/modules/item/front/fixed-price/index.html @@ -31,15 +31,21 @@ + - + + - +
+ + + Item ID Description - Warehouse - Grouping price @@ -57,11 +63,21 @@ Ended + Warehouse +
+ + + - - - - {{price.rate2 | currency: 'EUR':2}} + + {{price.rate2 | currency: 'EUR':2}} + - {{price.rate3 | currency: 'EUR':2}} + + {{price.rate3 | currency: 'EUR':2}} + @@ -169,6 +180,15 @@ + + + + +
+ + + + +
+ + + Edit + + {{::$ctrl.totalChecked}} + + buy(s) + + + + + + + + + + + + + + + + + + + diff --git a/modules/item/front/fixed-price/index.js b/modules/item/front/fixed-price/index.js index 0decf7275..eacd54ff6 100644 --- a/modules/item/front/fixed-price/index.js +++ b/modules/item/front/fixed-price/index.js @@ -5,6 +5,9 @@ import './style.scss'; export default class Controller extends Section { constructor($element, $) { super($element, $); + this.editedColumn; + this.checkAll = false; + this.checkedFixedPrices = []; this.smartTableOptions = { activeButtons: { @@ -30,6 +33,98 @@ export default class Controller extends Section { } ] }; + + this.filterParams = { + warehouseFk: this.vnConfig.warehouseFk + }; + } + + getFilterParams() { + return { + warehouseFk: this.vnConfig.warehouseFk + }; + } + + get columns() { + if (this._columns) return this._columns; + + this._columns = [ + {field: 'rate2', displayName: this.$t('Grouping price')}, + {field: 'rate3', displayName: this.$t('Packing price')}, + {field: 'hasMinPrice', displayName: this.$t('Has min price')}, + {field: 'minPrice', displayName: this.$t('Min price')}, + {field: 'started', displayName: this.$t('Started')}, + {field: 'ended', displayName: this.$t('Ended')}, + {field: 'warehouseFk', displayName: this.$t('Warehouse')} + ]; + + return this._columns; + } + + get checked() { + const fixedPrices = this.$.model.data || []; + const checkedBuys = []; + for (let fixedPrice of fixedPrices) { + if (fixedPrice.checked) + checkedBuys.push(fixedPrice); + } + + return checkedBuys; + } + + uncheck() { + this.checkAll = false; + this.checkedFixedPrices = []; + } + + get totalChecked() { + if (this.checkedDummyCount) + return this.checkedDummyCount; + + return this.checked.length; + } + + saveChecked(fixedPriceId) { + const index = this.checkedFixedPrices.indexOf(fixedPriceId); + if (index !== -1) + return this.checkedFixedPrices.splice(index, 1); + return this.checkedFixedPrices.push(fixedPriceId); + } + + reCheck() { + if (!this.$.model.data) return; + if (!this.checkedFixedPrices.length) return; + + this.$.model.data.forEach(fixedPrice => { + if (this.checkedFixedPrices.includes(fixedPrice.id)) + fixedPrice.checked = true; + }); + } + + onEditAccept() { + for (const fixedPrice of this.checked) { + fixedPrice[this.editedColumn.field] = this.editedColumn.newValue; + console.log(fixedPrice); + + this.upsertPrice(fixedPrice, false); + } + + // if (this.checkedDummyCount && this.checkedDummyCount > 0) { + // const params = {}; + // if (this.$.model.userParams) { + // const userParams = this.$.model.userParams; + // for (let param in userParams) { + // let newParam = this.exprBuilder(param, userParams[param]); + // if (!newParam) + // newParam = {[param]: userParams[param]}; + // Object.assign(params, newParam); + // } + // } + // if (this.$.model.userFilter) + // Object.assign(params, this.$.model.userFilter.where); + + // data.filter = params; + // } } isBigger(date) { @@ -98,8 +193,8 @@ export default class Controller extends Section { if (resetMinPrice) delete price['minPrice']; - let requiredFields = ['itemFk', 'started', 'ended', 'rate2', 'rate3']; - for (let field of requiredFields) + const requiredFields = ['itemFk', 'started', 'ended', 'rate2', 'rate3']; + for (const field of requiredFields) if (price[field] == undefined) return; const query = 'FixedPrices/upsertFixedPrice'; diff --git a/modules/item/front/fixed-price/locale/es.yml b/modules/item/front/fixed-price/locale/es.yml index 6bdfcb678..6dacf96c9 100644 --- a/modules/item/front/fixed-price/locale/es.yml +++ b/modules/item/front/fixed-price/locale/es.yml @@ -3,3 +3,5 @@ Search prices by item ID or code: Buscar por ID de artículo o código Search fixed prices: Buscar precios fijados Add fixed price: Añadir precio fijado This row will be removed: Esta linea se eliminará +Edit fixed price(s): Editar precio(s) fijado(s) +Has min price: Tiene precio mínimo diff --git a/modules/item/front/fixed-price/style.scss b/modules/item/front/fixed-price/style.scss index d1f968c37..97ceaf7cd 100644 --- a/modules/item/front/fixed-price/style.scss +++ b/modules/item/front/fixed-price/style.scss @@ -24,6 +24,12 @@ vn-fixed-price{ padding: 0px; } + smart-table table tbody > * > td{ + padding: 0px; + padding-left: 5px; + padding-right: 5px; + } + smart-table table tbody > * > td .chip.warning { color: $color-font-bg } @@ -31,4 +37,10 @@ vn-fixed-price{ .vn-field > .container > .infix > .control > input { color: inherit; } + + vn-input-number.inactive{ + input { + color: $color-font-light !important; + } + } } From 3b615d98796b7e95445f77bf3b72233012df6d82 Mon Sep 17 00:00:00 2001 From: vicent Date: Wed, 29 Mar 2023 09:11:40 +0200 Subject: [PATCH 09/34] refs #5275 fix: actualiza correctamete los elementos del checkedDummy --- .../methods/fixed-price/editFixedPrice.js | 96 +++++++++++++++++++ .../item/back/methods/fixed-price/filter.js | 3 +- modules/item/back/models/fixed-price.js | 1 + modules/item/front/fixed-price/index.js | 49 ++++++---- 4 files changed, 127 insertions(+), 22 deletions(-) create mode 100644 modules/item/back/methods/fixed-price/editFixedPrice.js diff --git a/modules/item/back/methods/fixed-price/editFixedPrice.js b/modules/item/back/methods/fixed-price/editFixedPrice.js new file mode 100644 index 000000000..13e0fc41b --- /dev/null +++ b/modules/item/back/methods/fixed-price/editFixedPrice.js @@ -0,0 +1,96 @@ +module.exports = Self => { + Self.remoteMethodCtx('editFixedPrice', { + description: 'Updates a column for one or more fixed price', + accessType: 'WRITE', + accepts: [{ + arg: 'field', + type: 'string', + required: true, + description: `the column to edit` + }, + { + arg: 'newValue', + type: 'any', + required: true, + description: `The new value to save` + }, + { + arg: 'lines', + type: ['object'], + required: true, + description: `the buys which will be modified` + }, + { + arg: 'filter', + type: 'object', + description: 'Filter defining where, order, offset, and limit - must be a JSON-encoded string' + }], + returns: { + type: 'object', + root: true + }, + http: { + path: `/editFixedPrice`, + verb: 'POST' + } + }); + + Self.editFixedPrice = async(ctx, field, newValue, lines, filter, options) => { + let tx; + const myOptions = {}; + + if (typeof options == 'object') + Object.assign(myOptions, options); + + if (!myOptions.transaction) { + tx = await Self.beginTransaction({}); + myOptions.transaction = tx; + } + + let modelName; + let identifier; + + switch (field) { + case 'hasMinPrice': + case 'minPrice': + modelName = 'Item'; + identifier = 'itemFk'; + break; + case 'rate2': + case 'rate3': + case 'started': + case 'ended': + case 'warehouseFk': + modelName = 'FixedPrice'; + identifier = 'id'; + } + + const models = Self.app.models; + const model = models[modelName]; + try { + const promises = []; + const value = {}; + value[field] = newValue; + + if (filter) { + filter = {where: filter}; + lines = await models.FixedPrice.filter(ctx, filter, myOptions); + } + + const targets = lines.map(line => { + return line[identifier]; + }); + for (let target of targets) + promises.push(model.upsertWithWhere({id: target}, value, myOptions)); + + const result = await Promise.all(promises); + + if (tx) await tx.commit(); + + return result; + } catch (e) { + if (tx) await tx.rollback(); + throw e; + } + }; +}; diff --git a/modules/item/back/methods/fixed-price/filter.js b/modules/item/back/methods/fixed-price/filter.js index c15ae67f0..9c91886c1 100644 --- a/modules/item/back/methods/fixed-price/filter.js +++ b/modules/item/back/methods/fixed-price/filter.js @@ -184,8 +184,7 @@ module.exports = Self => { } } - stmt.merge(conn.makeWhere(filter.where)); - stmt.merge(conn.makePagination(filter)); + stmt.merge(conn.makeSuffix(filter)); const fixedPriceIndex = stmts.push(stmt) - 1; const sql = ParameterizedSQL.join(stmts, ';'); diff --git a/modules/item/back/models/fixed-price.js b/modules/item/back/models/fixed-price.js index 91010805f..45f8d79ef 100644 --- a/modules/item/back/models/fixed-price.js +++ b/modules/item/back/models/fixed-price.js @@ -2,4 +2,5 @@ module.exports = Self => { require('../methods/fixed-price/filter')(Self); require('../methods/fixed-price/upsertFixedPrice')(Self); require('../methods/fixed-price/getRate2')(Self); + require('../methods/fixed-price/editFixedPrice')(Self); }; diff --git a/modules/item/front/fixed-price/index.js b/modules/item/front/fixed-price/index.js index eacd54ff6..a39cd6602 100644 --- a/modules/item/front/fixed-price/index.js +++ b/modules/item/front/fixed-price/index.js @@ -102,29 +102,38 @@ export default class Controller extends Section { } onEditAccept() { - for (const fixedPrice of this.checked) { - fixedPrice[this.editedColumn.field] = this.editedColumn.newValue; - console.log(fixedPrice); + const rowsToEdit = []; + for (let row of this.checked) + rowsToEdit.push({id: row.id, itemFk: row.itemFk}); - this.upsertPrice(fixedPrice, false); + const data = { + field: this.editedColumn.field, + newValue: this.editedColumn.newValue, + lines: rowsToEdit + }; + + if (this.checkedDummyCount && this.checkedDummyCount > 0) { + const params = {}; + if (this.$.model.userParams) { + const userParams = this.$.model.userParams; + for (let param in userParams) { + let newParam = this.exprBuilder(param, userParams[param]); + if (!newParam) + newParam = {[param]: userParams[param]}; + Object.assign(params, newParam); + } + } + if (this.$.model.userFilter) + Object.assign(params, this.$.model.userFilter.where); + + data.filter = params; } - // if (this.checkedDummyCount && this.checkedDummyCount > 0) { - // const params = {}; - // if (this.$.model.userParams) { - // const userParams = this.$.model.userParams; - // for (let param in userParams) { - // let newParam = this.exprBuilder(param, userParams[param]); - // if (!newParam) - // newParam = {[param]: userParams[param]}; - // Object.assign(params, newParam); - // } - // } - // if (this.$.model.userFilter) - // Object.assign(params, this.$.model.userFilter.where); - - // data.filter = params; - // } + return this.$http.post('FixedPrices/editFixedPrice', data) + .then(() => { + this.uncheck(); + this.$.model.refresh(); + }); } isBigger(date) { From d066c4ea0be719ff48948c5b3349b9f104862108 Mon Sep 17 00:00:00 2001 From: vicent Date: Wed, 29 Mar 2023 11:27:48 +0200 Subject: [PATCH 10/34] refs #4856 feat: se envia el registro a todos los teletrabajadores. Tmb se pone estado 'SENDED' cuando se da a 'Reenviar' --- .../back/methods/worker-time-control/sendMail.js | 14 ++------------ modules/worker/front/time-control/index.js | 15 +++++++++++++++ 2 files changed, 17 insertions(+), 12 deletions(-) diff --git a/modules/worker/back/methods/worker-time-control/sendMail.js b/modules/worker/back/methods/worker-time-control/sendMail.js index 579a83112..7aff9e790 100644 --- a/modules/worker/back/methods/worker-time-control/sendMail.js +++ b/modules/worker/back/methods/worker-time-control/sendMail.js @@ -131,20 +131,10 @@ module.exports = Self => { JOIN business b ON b.id = tb.businessFk LEFT JOIN tmp.timeControlCalculate tc ON tc.userFk = tb.userFk AND tc.dated = tb.dated LEFT JOIN worker w ON w.id = u.id - JOIN (SELECT tb.userFk, - SUM(IF(tb.type IS NULL, - IF(tc.timeWorkDecimal > 0, FALSE, IF(tb.timeWorkDecimal > 0, TRUE, FALSE)), - TRUE))isTeleworkingWeek - FROM tmp.timeBusinessCalculate tb - LEFT JOIN tmp.timeControlCalculate tc ON tc.userFk = tb.userFk - AND tc.dated = tb.dated - GROUP BY tb.userFk - HAVING isTeleworkingWeek > 0 - )sub ON sub.userFk = u.id - WHERE d.hasToRefill - AND IFNULL(?, u.id) = u.id + WHERE IFNULL(?, u.id) = u.id AND b.companyCodeFk = 'VNL' AND w.businessFk + AND d.isTeleworking ORDER BY u.id, tb.dated `, [args.workerId]); const index = stmts.push(stmt) - 1; diff --git a/modules/worker/front/time-control/index.js b/modules/worker/front/time-control/index.js index 9ed454d31..3e4aeaa5c 100644 --- a/modules/worker/front/time-control/index.js +++ b/modules/worker/front/time-control/index.js @@ -379,6 +379,20 @@ class Controller extends Section { }); } + isSended() { + const params = { + workerId: this.worker.id, + year: this.date.getFullYear(), + week: this.weekNumber, + state: 'SENDED' + }; + const query = `WorkerTimeControls/updateWorkerTimeControlMail`; + this.$http.post(query, params).then(() => { + this.getMailStates(this.date); + this.getWeekData(); + }); + } + changeState(state, reason) { this.state = state; this.reason = reason; @@ -412,6 +426,7 @@ class Controller extends Section { }; this.$http.post(`WorkerTimeControls/weekly-hour-hecord-email`, params) .then(() => { + this.isSended(); this.vnApp.showSuccess(this.$t('Email sended')); }); } From 5a67f473054fbf1ad2bec943b45366fd3e4217bd Mon Sep 17 00:00:00 2001 From: vicent Date: Thu, 30 Mar 2023 08:14:17 +0200 Subject: [PATCH 11/34] refs #4856 fix: actualizar estado a 'SENDED' movido al back --- .../updateWorkerTimeControlMail.js | 6 +++++ .../weeklyHourRecordEmail.js | 24 +++++++++++-------- .../back/models/worker-time-control-mail.json | 3 +++ modules/worker/front/time-control/index.html | 2 +- modules/worker/front/time-control/index.js | 18 +++----------- 5 files changed, 27 insertions(+), 26 deletions(-) diff --git a/modules/worker/back/methods/worker-time-control/updateWorkerTimeControlMail.js b/modules/worker/back/methods/worker-time-control/updateWorkerTimeControlMail.js index 642ff90d2..3c44bda40 100644 --- a/modules/worker/back/methods/worker-time-control/updateWorkerTimeControlMail.js +++ b/modules/worker/back/methods/worker-time-control/updateWorkerTimeControlMail.js @@ -69,6 +69,12 @@ module.exports = Self => { reason: args.reason || null }, myOptions); + if (args.state == 'SENDED') { + await workerTimeControlMail.updateAttributes({ + sendedCounter: workerTimeControlMail.sendedCounter + 1 + }, myOptions); + } + const logRecord = { originFk: args.workerId, userFk: userId, diff --git a/modules/worker/back/methods/worker-time-control/weeklyHourRecordEmail.js b/modules/worker/back/methods/worker-time-control/weeklyHourRecordEmail.js index 6feadb936..8e9b325a6 100644 --- a/modules/worker/back/methods/worker-time-control/weeklyHourRecordEmail.js +++ b/modules/worker/back/methods/worker-time-control/weeklyHourRecordEmail.js @@ -25,6 +25,16 @@ module.exports = Self => { arg: 'url', type: 'string', required: true + }, + { + arg: 'workerId', + type: 'number', + required: true + }, + { + arg: 'state', + type: 'string', + required: true } ], returns: { @@ -37,17 +47,11 @@ module.exports = Self => { } }); - Self.weeklyHourRecordEmail = async(ctx, recipient, week, year, url) => { - const params = { - recipient: recipient, - lang: ctx.req.getLocale(), - week: week, - year: year, - url: url - }; + Self.weeklyHourRecordEmail = async ctx => { + const models = Self.app.models; - const email = new Email('weekly-hour-record', params); + Self.sendTemplate(ctx, 'weekly-hour-record'); - return email.send(); + return models.WorkerTimeControl.updateWorkerTimeControlMail(ctx); }; }; diff --git a/modules/worker/back/models/worker-time-control-mail.json b/modules/worker/back/models/worker-time-control-mail.json index 78b99881d..87eae9217 100644 --- a/modules/worker/back/models/worker-time-control-mail.json +++ b/modules/worker/back/models/worker-time-control-mail.json @@ -28,6 +28,9 @@ }, "reason": { "type": "string" + }, + "sendedCounter": { + "type": "number" } }, "acls": [ diff --git a/modules/worker/front/time-control/index.html b/modules/worker/front/time-control/index.html index bd7e68b89..044ea4038 100644 --- a/modules/worker/front/time-control/index.html +++ b/modules/worker/front/time-control/index.html @@ -204,7 +204,7 @@ vn-id="sendEmailConfirmation" on-accept="$ctrl.resendEmail()" message="Send time control email"> - + Are you sure you want to send it? diff --git a/modules/worker/front/time-control/index.js b/modules/worker/front/time-control/index.js index 3e4aeaa5c..ebfc8b444 100644 --- a/modules/worker/front/time-control/index.js +++ b/modules/worker/front/time-control/index.js @@ -379,20 +379,6 @@ class Controller extends Section { }); } - isSended() { - const params = { - workerId: this.worker.id, - year: this.date.getFullYear(), - week: this.weekNumber, - state: 'SENDED' - }; - const query = `WorkerTimeControls/updateWorkerTimeControlMail`; - this.$http.post(query, params).then(() => { - this.getMailStates(this.date); - this.getWeekData(); - }); - } - changeState(state, reason) { this.state = state; this.reason = reason; @@ -423,10 +409,12 @@ class Controller extends Section { week: this.weekNumber, year: this.date.getFullYear(), url: url, + workerId: this.worker.id, + state: 'SENDED' }; this.$http.post(`WorkerTimeControls/weekly-hour-hecord-email`, params) .then(() => { - this.isSended(); + this.getMailStates(this.date); this.vnApp.showSuccess(this.$t('Email sended')); }); } From 4edb2463b8c9f4a97eabaf35a234e7ade33d5e66 Mon Sep 17 00:00:00 2001 From: carlossa Date: Thu, 30 Mar 2023 08:23:53 +0200 Subject: [PATCH 12/34] refs #5250 eliminacion isEnabled --- modules/worker/back/models/worker-observation.js | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/modules/worker/back/models/worker-observation.js b/modules/worker/back/models/worker-observation.js index 413d9a2ba..cccc2cfbd 100644 --- a/modules/worker/back/models/worker-observation.js +++ b/modules/worker/back/models/worker-observation.js @@ -1,8 +1,7 @@ module.exports = function(Self) { - Self.validatesPresenceOf('text', isEnabled, {message: 'Description cannot be blank'}); - function isEnabled(err) { - if (!this.text) err(); - } + Self.validatesPresenceOf('text', { + message: 'Description cannot be blank' + }); Self.observe('before save', async function(ctx) { ctx.instance.created = new Date(); From e1bfdc3f3cb5d4b57e8c0b05cefecb1a399f09f1 Mon Sep 17 00:00:00 2001 From: vicent Date: Thu, 30 Mar 2023 11:13:40 +0200 Subject: [PATCH 13/34] eliminada variable que no se usa --- .../back/methods/worker-time-control/weeklyHourRecordEmail.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/modules/worker/back/methods/worker-time-control/weeklyHourRecordEmail.js b/modules/worker/back/methods/worker-time-control/weeklyHourRecordEmail.js index 8e9b325a6..4c6f647cb 100644 --- a/modules/worker/back/methods/worker-time-control/weeklyHourRecordEmail.js +++ b/modules/worker/back/methods/worker-time-control/weeklyHourRecordEmail.js @@ -1,5 +1,3 @@ -const {Email} = require('vn-print'); - module.exports = Self => { Self.remoteMethodCtx('weeklyHourRecordEmail', { description: 'Sends the weekly hour record', From 67689695e4e8bc329800f540bcf5ad42921d9780 Mon Sep 17 00:00:00 2001 From: vicent Date: Thu, 30 Mar 2023 14:29:19 +0200 Subject: [PATCH 14/34] refs #5275 filtra por defecto por el this.vnConfig.warehouseFk --- modules/item/front/fixed-price/index.html | 3 +++ 1 file changed, 3 insertions(+) diff --git a/modules/item/front/fixed-price/index.html b/modules/item/front/fixed-price/index.html index af41b1bc8..a82fd2742 100644 --- a/modules/item/front/fixed-price/index.html +++ b/modules/item/front/fixed-price/index.html @@ -1,6 +1,7 @@ From 862101c4b018cfc217b1fffc8432551f60d258e0 Mon Sep 17 00:00:00 2001 From: vicent Date: Mon, 3 Apr 2023 21:29:02 +0200 Subject: [PATCH 15/34] refs #4856 feat: si se modifica una fichada actualiza el estado a 'SENDED' y notifica al trabajador --- .../worker-time-control/addTimeEntry.js | 2 + .../worker-time-control/deleteTimeEntry.js | 6 +- .../resendWeeklyHourEmail.js | 68 +++++++++++++++++++ .../methods/worker-time-control/sendMail.js | 21 +++--- .../worker-time-control/updateTimeEntry.js | 6 +- .../weeklyHourRecordEmail.js | 46 +++++++++++-- .../worker/back/models/worker-time-control.js | 1 + modules/worker/front/time-control/index.js | 12 ++-- 8 files changed, 139 insertions(+), 23 deletions(-) create mode 100644 modules/worker/back/methods/worker-time-control/resendWeeklyHourEmail.js diff --git a/modules/worker/back/methods/worker-time-control/addTimeEntry.js b/modules/worker/back/methods/worker-time-control/addTimeEntry.js index fef3cf223..c8c08d9b1 100644 --- a/modules/worker/back/methods/worker-time-control/addTimeEntry.js +++ b/modules/worker/back/methods/worker-time-control/addTimeEntry.js @@ -51,6 +51,8 @@ module.exports = Self => { if (response[0] && response[0].error) throw new UserError(response[0].error); + await models.WorkerTimeControl.resendWeeklyHourEmail(ctx, workerId, args.timed, myOptions); + return response; }; }; diff --git a/modules/worker/back/methods/worker-time-control/deleteTimeEntry.js b/modules/worker/back/methods/worker-time-control/deleteTimeEntry.js index c80dcab81..e33d6b790 100644 --- a/modules/worker/back/methods/worker-time-control/deleteTimeEntry.js +++ b/modules/worker/back/methods/worker-time-control/deleteTimeEntry.js @@ -38,7 +38,11 @@ module.exports = Self => { if (isSubordinate === false || (isSubordinate && isHimself && !isTeamBoss)) throw new UserError(`You don't have enough privileges`); - return Self.rawSql('CALL vn.workerTimeControl_remove(?, ?)', [ + const response = await Self.rawSql('CALL vn.workerTimeControl_remove(?, ?)', [ targetTimeEntry.userFk, targetTimeEntry.timed], myOptions); + + await models.WorkerTimeControl.resendWeeklyHourEmail(ctx, targetTimeEntry.userFk, targetTimeEntry.timed, myOptions); + + return response; }; }; diff --git a/modules/worker/back/methods/worker-time-control/resendWeeklyHourEmail.js b/modules/worker/back/methods/worker-time-control/resendWeeklyHourEmail.js new file mode 100644 index 000000000..5fae6988c --- /dev/null +++ b/modules/worker/back/methods/worker-time-control/resendWeeklyHourEmail.js @@ -0,0 +1,68 @@ +module.exports = Self => { + Self.remoteMethodCtx('resendWeeklyHourEmail', { + description: 'Adds a new hour registry', + accessType: 'WRITE', + accepts: [{ + arg: 'id', + type: 'number', + description: 'The worker id', + http: {source: 'path'} + }, + { + arg: 'dated', + type: 'date', + required: true + }], + returns: [{ + type: 'Object', + root: true + }], + http: { + path: `/:id/resendWeeklyHourEmail`, + verb: 'POST' + } + }); + + Self.resendWeeklyHourEmail = async(ctx, workerId, dated, options) => { + const models = Self.app.models; + const myOptions = {}; + + if (typeof options == 'object') + Object.assign(myOptions, options); + + const yearNumber = dated.getFullYear(); + const weekNumber = getWeekNumber(dated); + const workerTimeControlMail = await models.WorkerTimeControlMail.findOne({ + where: { + workerFk: workerId, + year: yearNumber, + week: weekNumber + } + }, myOptions); + + if (workerTimeControlMail && workerTimeControlMail.state != 'SENDED') { + const worker = await models.EmailUser.findById(workerId); + ctx.args = { + recipient: worker.email, + year: yearNumber, + week: weekNumber, + workerId: workerId, + state: 'SENDED' + }; + return models.WorkerTimeControl.weeklyHourRecordEmail(ctx, myOptions); + } + + return false; + }; + + function getWeekNumber(date) { + const tempDate = new Date(date); + let dayOfWeek = tempDate.getDay(); + dayOfWeek = (dayOfWeek === 0) ? 7 : dayOfWeek; + const firstDayOfWeek = new Date(tempDate.getFullYear(), tempDate.getMonth(), tempDate.getDate() - (dayOfWeek - 1)); + const firstDayOfYear = new Date(tempDate.getFullYear(), 0, 1); + const differenceInMilliseconds = firstDayOfWeek.getTime() - firstDayOfYear.getTime(); + const weekNumber = Math.floor(differenceInMilliseconds / (1000 * 60 * 60 * 24 * 7)) + 1; + return weekNumber; + } +}; diff --git a/modules/worker/back/methods/worker-time-control/sendMail.js b/modules/worker/back/methods/worker-time-control/sendMail.js index 7aff9e790..9d17265e8 100644 --- a/modules/worker/back/methods/worker-time-control/sendMail.js +++ b/modules/worker/back/methods/worker-time-control/sendMail.js @@ -322,17 +322,20 @@ module.exports = Self => { const lastDay = days[index][days[index].length - 1]; if (day.workerFk != previousWorkerFk || day == lastDay) { - const salix = await models.Url.findOne({ - where: { - appName: 'salix', - environment: process.env.NODE_ENV || 'dev' - } + await models.WorkerTimeControlMail.create({ + workerFk: previousWorkerFk, + year: args.year, + week: args.week }, myOptions); - const timestamp = started.getTime() / 1000; - const url = `${salix.url}worker/${previousWorkerFk}/time-control?timestamp=${timestamp}`; - - await models.WorkerTimeControl.weeklyHourRecordEmail(ctx, previousReceiver, args.week, args.year, url); + ctx.args = { + recipient: previousReceiver, + year: args.year, + week: args.week, + workerId: previousWorkerFk, + state: 'SENDED' + }; + await models.WorkerTimeControl.weeklyHourRecordEmail(ctx, myOptions); previousWorkerFk = day.workerFk; previousReceiver = day.receiver; diff --git a/modules/worker/back/methods/worker-time-control/updateTimeEntry.js b/modules/worker/back/methods/worker-time-control/updateTimeEntry.js index a99a61770..83349ea63 100644 --- a/modules/worker/back/methods/worker-time-control/updateTimeEntry.js +++ b/modules/worker/back/methods/worker-time-control/updateTimeEntry.js @@ -46,8 +46,12 @@ module.exports = Self => { if (notAllowed) throw new UserError(`You don't have enough privileges`); - return targetTimeEntry.updateAttributes({ + const timeEntryUpdated = await targetTimeEntry.updateAttributes({ direction: args.direction }, myOptions); + + await models.WorkerTimeControl.resendWeeklyHourEmail(ctx, targetTimeEntry.userFk, targetTimeEntry.timed, myOptions); + + return timeEntryUpdated; }; }; diff --git a/modules/worker/back/methods/worker-time-control/weeklyHourRecordEmail.js b/modules/worker/back/methods/worker-time-control/weeklyHourRecordEmail.js index 4c6f647cb..f44080559 100644 --- a/modules/worker/back/methods/worker-time-control/weeklyHourRecordEmail.js +++ b/modules/worker/back/methods/worker-time-control/weeklyHourRecordEmail.js @@ -19,11 +19,6 @@ module.exports = Self => { type: 'number', required: true }, - { - arg: 'url', - type: 'string', - required: true - }, { arg: 'workerId', type: 'number', @@ -45,11 +40,48 @@ module.exports = Self => { } }); - Self.weeklyHourRecordEmail = async ctx => { + Self.weeklyHourRecordEmail = async(ctx, options) => { const models = Self.app.models; + const args = ctx.args; + const myOptions = {}; + + if (typeof options == 'object') + Object.assign(myOptions, options); + + const salix = await models.Url.findOne({ + where: { + appName: 'salix', + environment: process.env.NODE_ENV || 'dev' + } + }, myOptions); + + const dated = getMondayDateFromYearWeek(args.year, args.week); + const timestamp = dated.getTime() / 1000; + + const url = `${salix.url}worker/${args.workerId}/time-control?timestamp=${timestamp}`; + ctx.args.url = url; Self.sendTemplate(ctx, 'weekly-hour-record'); - return models.WorkerTimeControl.updateWorkerTimeControlMail(ctx); + return models.WorkerTimeControl.updateWorkerTimeControlMail(ctx, myOptions); }; + + function getMondayDateFromYearWeek(yearNumber, weekNumber) { + const yearStart = new Date(yearNumber, 0, 1); + const firstMonday = new Date(yearStart.getTime() + ((7 - yearStart.getDay() + 1) % 7) * 86400000); + const firstMondayWeekNumber = getWeekNumber(firstMonday); + + if (firstMondayWeekNumber > 1) + firstMonday.setDate(firstMonday.getDate() + 7); + + firstMonday.setDate(firstMonday.getDate() + (weekNumber - 1) * 7); + + return firstMonday; + } + + function getWeekNumber(date) { + const firstDayOfYear = new Date(date.getFullYear(), 0, 1); + const daysPassed = (date - firstDayOfYear) / 86400000; + return Math.ceil((daysPassed + firstDayOfYear.getDay() + 1) / 7); + } }; diff --git a/modules/worker/back/models/worker-time-control.js b/modules/worker/back/models/worker-time-control.js index 5b13e17f2..d5da680cf 100644 --- a/modules/worker/back/models/worker-time-control.js +++ b/modules/worker/back/models/worker-time-control.js @@ -9,6 +9,7 @@ module.exports = Self => { require('../methods/worker-time-control/updateWorkerTimeControlMail')(Self); require('../methods/worker-time-control/weeklyHourRecordEmail')(Self); require('../methods/worker-time-control/getMailStates')(Self); + require('../methods/worker-time-control/resendWeeklyHourEmail')(Self); Self.rewriteDbError(function(err) { if (err.code === 'ER_DUP_ENTRY') diff --git a/modules/worker/front/time-control/index.js b/modules/worker/front/time-control/index.js index ebfc8b444..85ddcedfe 100644 --- a/modules/worker/front/time-control/index.js +++ b/modules/worker/front/time-control/index.js @@ -303,7 +303,10 @@ class Controller extends Section { const query = `WorkerTimeControls/${this.worker.id}/addTimeEntry`; this.$http.post(query, entry) - .then(() => this.fetchHours()); + .then(() => { + this.fetchHours(); + this.getMailStates(this.date); + }); } catch (e) { this.vnApp.showError(this.$t(e.message)); return false; @@ -324,6 +327,7 @@ class Controller extends Section { this.$http.post(`WorkerTimeControls/${entryId}/deleteTimeEntry`).then(() => { this.fetchHours(); + this.getMailStates(this.date); this.vnApp.showSuccess(this.$t('Entry removed')); }); } @@ -395,20 +399,18 @@ class Controller extends Section { this.$http.post(query, {direction: entry.direction}) .then(() => this.vnApp.showSuccess(this.$t('Data saved!'))) .then(() => this.$.editEntry.hide()) - .then(() => this.fetchHours()); + .then(() => this.fetchHours()) + .then(() => this.getMailStates(this.date)); } catch (e) { this.vnApp.showError(this.$t(e.message)); } } resendEmail() { - const timestamp = this.date.getTime() / 1000; - const url = `${window.location.origin}/#!/worker/${this.worker.id}/time-control?timestamp=${timestamp}`; const params = { recipient: this.worker.user.emailUser.email, week: this.weekNumber, year: this.date.getFullYear(), - url: url, workerId: this.worker.id, state: 'SENDED' }; From 21b7050cfd6b95fa32a9cb8241911ad1690bdb1f Mon Sep 17 00:00:00 2001 From: vicent Date: Tue, 4 Apr 2023 09:29:40 +0200 Subject: [PATCH 16/34] refs #4856 otros usuarios pueden actualizar el estado --- .../worker-time-control/updateWorkerTimeControlMail.js | 4 ---- 1 file changed, 4 deletions(-) diff --git a/modules/worker/back/methods/worker-time-control/updateWorkerTimeControlMail.js b/modules/worker/back/methods/worker-time-control/updateWorkerTimeControlMail.js index 3c44bda40..6f794511f 100644 --- a/modules/worker/back/methods/worker-time-control/updateWorkerTimeControlMail.js +++ b/modules/worker/back/methods/worker-time-control/updateWorkerTimeControlMail.js @@ -47,10 +47,6 @@ module.exports = Self => { if (typeof options == 'object') Object.assign(myOptions, options); - const isHimself = userId == args.workerId; - if (!isHimself) - throw new UserError(`You don't have enough privileges`); - const workerTimeControlMail = await models.WorkerTimeControlMail.findOne({ where: { workerFk: args.workerId, From 0db3bc5e26c53e33bf4c1858cebd13a38aeef42e Mon Sep 17 00:00:00 2001 From: vicent Date: Tue, 4 Apr 2023 09:29:51 +0200 Subject: [PATCH 17/34] refs #4856 fix test --- .../specs/sendMail.spec.js | 120 ------------------ .../worker/front/time-control/index.spec.js | 9 ++ 2 files changed, 9 insertions(+), 120 deletions(-) delete mode 100644 modules/worker/back/methods/worker-time-control/specs/sendMail.spec.js diff --git a/modules/worker/back/methods/worker-time-control/specs/sendMail.spec.js b/modules/worker/back/methods/worker-time-control/specs/sendMail.spec.js deleted file mode 100644 index 24bfd6904..000000000 --- a/modules/worker/back/methods/worker-time-control/specs/sendMail.spec.js +++ /dev/null @@ -1,120 +0,0 @@ -const models = require('vn-loopback/server/server').models; - -describe('workerTimeControl sendMail()', () => { - const workerId = 18; - const activeCtx = { - getLocale: () => { - return 'en'; - } - }; - const ctx = {req: activeCtx, args: {}}; - - it('should fill time control of a worker without records in Journey and with rest', async() => { - const tx = await models.WorkerTimeControl.beginTransaction({}); - - try { - const options = {transaction: tx}; - - await models.WorkerTimeControl.sendMail(ctx, options); - - const workerTimeControl = await models.WorkerTimeControl.find({ - where: {userFk: workerId} - }, options); - - expect(workerTimeControl[0].timed.getHours()).toEqual(8); - expect(workerTimeControl[1].timed.getHours()).toEqual(9); - expect(`${workerTimeControl[2].timed.getHours()}:${workerTimeControl[2].timed.getMinutes()}`).toEqual('9:20'); - expect(workerTimeControl[3].timed.getHours()).toEqual(16); - - await tx.rollback(); - } catch (e) { - await tx.rollback(); - throw e; - } - }); - - it('should fill time control of a worker without records in Journey and without rest', async() => { - const workdayOf20Hours = 3; - const tx = await models.WorkerTimeControl.beginTransaction({}); - - try { - const options = {transaction: tx}; - query = `UPDATE business b - SET b.calendarTypeFk = ? - WHERE b.workerFk = ?; `; - await models.WorkerTimeControl.rawSql(query, [workdayOf20Hours, workerId], options); - - await models.WorkerTimeControl.sendMail(ctx, options); - - const workerTimeControl = await models.WorkerTimeControl.find({ - where: {userFk: workerId} - }, options); - - expect(workerTimeControl[0].timed.getHours()).toEqual(8); - expect(workerTimeControl[1].timed.getHours()).toEqual(12); - - await tx.rollback(); - } catch (e) { - await tx.rollback(); - throw e; - } - }); - - it('should fill time control of a worker with records in Journey and with rest', async() => { - const tx = await models.WorkerTimeControl.beginTransaction({}); - - try { - const options = {transaction: tx}; - query = `INSERT INTO postgresql.journey(journey_id, day_id, start, end, business_id) - VALUES - (1, 1, '09:00:00', '13:00:00', ?), - (2, 1, '14:00:00', '19:00:00', ?);`; - await models.WorkerTimeControl.rawSql(query, [workerId, workerId, workerId], options); - - await models.WorkerTimeControl.sendMail(ctx, options); - - const workerTimeControl = await models.WorkerTimeControl.find({ - where: {userFk: workerId} - }, options); - - expect(workerTimeControl[0].timed.getHours()).toEqual(9); - expect(workerTimeControl[2].timed.getHours()).toEqual(10); - expect(`${workerTimeControl[3].timed.getHours()}:${workerTimeControl[3].timed.getMinutes()}`).toEqual('10:20'); - expect(workerTimeControl[1].timed.getHours()).toEqual(13); - expect(workerTimeControl[4].timed.getHours()).toEqual(14); - expect(workerTimeControl[5].timed.getHours()).toEqual(19); - - await tx.rollback(); - } catch (e) { - await tx.rollback(); - throw e; - } - }); - - it('should fill time control of a worker with records in Journey and without rest', async() => { - const tx = await models.WorkerTimeControl.beginTransaction({}); - - try { - const options = {transaction: tx}; - query = `INSERT INTO postgresql.journey(journey_id, day_id, start, end, business_id) - VALUES - (1, 1, '12:30:00', '14:00:00', ?);`; - await models.WorkerTimeControl.rawSql(query, [workerId, workerId, workerId], options); - - await models.WorkerTimeControl.sendMail(ctx, options); - - const workerTimeControl = await models.WorkerTimeControl.find({ - where: {userFk: workerId} - }, options); - - expect(`${workerTimeControl[0].timed.getHours()}:${workerTimeControl[0].timed.getMinutes()}`).toEqual('12:30'); - expect(workerTimeControl[1].timed.getHours()).toEqual(14); - - await tx.rollback(); - } catch (e) { - await tx.rollback(); - throw e; - } - }); -}); - diff --git a/modules/worker/front/time-control/index.spec.js b/modules/worker/front/time-control/index.spec.js index 0f9b48f6b..94f9d3d48 100644 --- a/modules/worker/front/time-control/index.spec.js +++ b/modules/worker/front/time-control/index.spec.js @@ -120,6 +120,13 @@ describe('Component vnWorkerTimeControl', () => { describe('save() ', () => { it(`should make a query an then call to the fetchHours() method`, () => { + const today = Date.vnNew(); + + jest.spyOn(controller, 'getWeekData').mockReturnThis(); + jest.spyOn(controller, 'getMailStates').mockReturnThis(); + + controller.$.model = {applyFilter: jest.fn().mockReturnValue(Promise.resolve())}; + controller.date = today; controller.fetchHours = jest.fn(); controller.selectedRow = {id: 1, timed: Date.vnNew(), direction: 'in'}; controller.$.editEntry = { @@ -240,7 +247,9 @@ describe('Component vnWorkerTimeControl', () => { describe('resendEmail() ', () => { it(`should make a query an then call showSuccess method`, () => { const today = Date.vnNew(); + jest.spyOn(controller, 'getWeekData').mockReturnThis(); + jest.spyOn(controller, 'getMailStates').mockReturnThis(); jest.spyOn(controller.vnApp, 'showSuccess'); controller.$.model = {applyFilter: jest.fn().mockReturnValue(Promise.resolve())}; From eed1ecc208163e29ed8a24371adeb7c939ca931c Mon Sep 17 00:00:00 2001 From: alexandre Date: Tue, 4 Apr 2023 14:47:13 +0200 Subject: [PATCH 18/34] refs #4954 trigger modified --- db/changes/231401/00-clientBeforeUpdate.sql | 72 +++++++++++++++++++++ modules/client/front/fiscal-data/index.js | 4 ++ 2 files changed, 76 insertions(+) create mode 100644 db/changes/231401/00-clientBeforeUpdate.sql diff --git a/db/changes/231401/00-clientBeforeUpdate.sql b/db/changes/231401/00-clientBeforeUpdate.sql new file mode 100644 index 000000000..8f9f70dd5 --- /dev/null +++ b/db/changes/231401/00-clientBeforeUpdate.sql @@ -0,0 +1,72 @@ +DROP TRIGGER IF EXISTS `vn`.`client_beforeUpdate`; +USE `vn`; + +DELIMITER $$ +$$ +CREATE DEFINER=`root`@`localhost` TRIGGER `vn`.`client_beforeUpdate` + BEFORE UPDATE ON `client` + FOR EACH ROW +BEGIN + DECLARE vText VARCHAR(255) DEFAULT NULL; + DECLARE vPayMethodFk INT; + -- Comprueba que el formato de los teléfonos es válido + + IF !(NEW.phone <=> OLD.phone) AND (NEW.phone <> '') THEN + CALL pbx.phone_isValid(NEW.phone); + END IF; + + IF !(NEW.mobile <=> OLD.mobile) AND (NEW.mobile <> '')THEN + CALL pbx.phone_isValid(NEW.mobile); + END IF; + + SELECT id INTO vPayMethodFk + FROM vn.payMethod + WHERE code = 'bankDraft'; + + IF NEW.payMethodFk = vPayMethodFk AND NEW.dueDay = 0 THEN + SET NEW.dueDay = 5; + END IF; + + -- Avisar al comercial si ha llegado la documentación sepa/core + + IF NEW.hasSepaVnl AND !OLD.hasSepaVnl THEN + SET vText = 'Sepa de VNL'; + END IF; + + IF NEW.hasCoreVnl AND !OLD.hasCoreVnl THEN + SET vText = 'Core de VNL'; + END IF; + + IF vText IS NOT NULL + THEN + INSERT INTO mail(receiver, replyTo, `subject`, body) + SELECT + CONCAT(IF(ac.id,u.name, 'jgallego'), '@verdnatura.es'), + 'administracion@verdnatura.es', + CONCAT('Cliente ', NEW.id), + CONCAT('Recibida la documentación: ', vText) + FROM worker w + LEFT JOIN account.user u ON w.userFk = u.id AND u.active + LEFT JOIN account.account ac ON ac.id = u.id + WHERE w.id = NEW.salesPersonFk; + END IF; + + IF NEW.salespersonFk IS NULL AND OLD.salespersonFk IS NOT NULL THEN + IF (SELECT COUNT(clientFk) + FROM clientProtected + WHERE clientFk = NEW.id + ) > 0 THEN + CALL util.throw("HAS_CLIENT_PROTECTED"); + END IF; + END IF; + + IF !(NEW.salesPersonFk <=> OLD.salesPersonFk) THEN + SET NEW.lastSalesPersonFk = IFNULL(NEW.salesPersonFk, OLD.salesPersonFk); + END IF; + + IF !(NEW.businessTypeFk <=> OLD.businessTypeFk) AND (NEW.businessTypeFk = 'individual' OR OLD.businessTypeFk = 'individual') THEN + SET NEW.isTaxDataChecked = 0; + END IF; + +END$$ +DELIMITER ; diff --git a/modules/client/front/fiscal-data/index.js b/modules/client/front/fiscal-data/index.js index d76944c42..acad38185 100644 --- a/modules/client/front/fiscal-data/index.js +++ b/modules/client/front/fiscal-data/index.js @@ -2,6 +2,10 @@ import ngModule from '../module'; import Section from 'salix/components/section'; export default class Controller extends Section { + $onInit() { + this.card.reload(); + } + onSubmit() { const orgData = this.$.watcher.orgData; delete this.client.despiteOfClient; From 81cf35f2d3d50a8becba767926e24a842620ca76 Mon Sep 17 00:00:00 2001 From: alexandre Date: Tue, 4 Apr 2023 14:55:37 +0200 Subject: [PATCH 19/34] refs #5259 drop procedure invoiceOut_afterInsert --- db/changes/231401/00-invoiceOutAfterInsert.sql | 1 + 1 file changed, 1 insertion(+) create mode 100644 db/changes/231401/00-invoiceOutAfterInsert.sql diff --git a/db/changes/231401/00-invoiceOutAfterInsert.sql b/db/changes/231401/00-invoiceOutAfterInsert.sql new file mode 100644 index 000000000..24836e1fb --- /dev/null +++ b/db/changes/231401/00-invoiceOutAfterInsert.sql @@ -0,0 +1 @@ +DROP PROCEDURE IF EXISTS `vn`.`invoiceOut_afterInsert`; From 589e996b699565d4ebc2dec6113cb0874e40e326 Mon Sep 17 00:00:00 2001 From: alexandre Date: Tue, 4 Apr 2023 15:17:19 +0200 Subject: [PATCH 20/34] refs #5259 minor fix --- db/changes/231401/00-invoiceOutAfterInsert.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/db/changes/231401/00-invoiceOutAfterInsert.sql b/db/changes/231401/00-invoiceOutAfterInsert.sql index 24836e1fb..cf921fd17 100644 --- a/db/changes/231401/00-invoiceOutAfterInsert.sql +++ b/db/changes/231401/00-invoiceOutAfterInsert.sql @@ -1 +1 @@ -DROP PROCEDURE IF EXISTS `vn`.`invoiceOut_afterInsert`; +DROP TRIGGER IF EXISTS `vn`.`invoiceOut_afterInsert`; From 8f4de7e7e95a9082f82a7e3ad689f2839c47bcb1 Mon Sep 17 00:00:00 2001 From: alexandre Date: Tue, 4 Apr 2023 15:27:10 +0200 Subject: [PATCH 21/34] refs #5259 undo delete, update trigger --- db/changes/231401/00-invoiceOutAfterInsert.sql | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/db/changes/231401/00-invoiceOutAfterInsert.sql b/db/changes/231401/00-invoiceOutAfterInsert.sql index cf921fd17..adeaf9834 100644 --- a/db/changes/231401/00-invoiceOutAfterInsert.sql +++ b/db/changes/231401/00-invoiceOutAfterInsert.sql @@ -1 +1,13 @@ DROP TRIGGER IF EXISTS `vn`.`invoiceOut_afterInsert`; +USE vn; + +DELIMITER $$ +$$ +CREATE DEFINER=`root`@`localhost` TRIGGER `vn`.`invoiceOut_afterInsert` + AFTER INSERT ON `invoiceOut` + FOR EACH ROW +BEGIN + CALL clientRisk_update(NEW.clientFk, NEW.companyFk, NEW.amount); +END$$ +DELIMITER ; + From e97b5a9f80fa944ddf6ac553a70b3379ad66d752 Mon Sep 17 00:00:00 2001 From: vicent Date: Wed, 5 Apr 2023 07:54:56 +0200 Subject: [PATCH 22/34] refs #5275 fix backTest --- .../back/methods/fixed-price/specs/upsertFixedPrice.spec.js | 6 +++--- modules/item/back/methods/fixed-price/upsertFixedPrice.js | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/modules/item/back/methods/fixed-price/specs/upsertFixedPrice.spec.js b/modules/item/back/methods/fixed-price/specs/upsertFixedPrice.spec.js index 86f73122d..823406500 100644 --- a/modules/item/back/methods/fixed-price/specs/upsertFixedPrice.spec.js +++ b/modules/item/back/methods/fixed-price/specs/upsertFixedPrice.spec.js @@ -42,7 +42,7 @@ describe('upsertFixedPrice()', () => { delete ctx.args.started; delete ctx.args.ended; - ctx.args.hasMinPrice = true; + ctx.args.hasMinPrice = false; expect(result).toEqual(jasmine.objectContaining(ctx.args)); @@ -74,7 +74,7 @@ describe('upsertFixedPrice()', () => { delete ctx.args.started; delete ctx.args.ended; - ctx.args.hasMinPrice = false; + ctx.args.hasMinPrice = true; expect(result).toEqual(jasmine.objectContaining(ctx.args)); @@ -105,7 +105,7 @@ describe('upsertFixedPrice()', () => { rate2: rate2, rate3: firstRate3, minPrice: 0, - hasMinPrice: false + hasMinPrice: true }}; // create new fixed price diff --git a/modules/item/back/methods/fixed-price/upsertFixedPrice.js b/modules/item/back/methods/fixed-price/upsertFixedPrice.js index d815ed426..edbd23604 100644 --- a/modules/item/back/methods/fixed-price/upsertFixedPrice.js +++ b/modules/item/back/methods/fixed-price/upsertFixedPrice.js @@ -87,7 +87,7 @@ module.exports = Self => { await targetItem.updateAttributes({ minPrice: args.minPrice, - hasMinPrice: args.hasMinPrice ? args.hasMinPrice : false + hasMinPrice: args.hasMinPrice }, myOptions); const itemFields = [ From fb5969a120a58749cdd6e11da90d0656f3fe0611 Mon Sep 17 00:00:00 2001 From: vicent Date: Wed, 5 Apr 2023 08:43:47 +0200 Subject: [PATCH 23/34] refs #5275 add test --- .../fixed-price/specs/editFixedPrice.spec.js | 63 ++++++++++++++ modules/item/front/fixed-price/index.spec.js | 84 +++++++++++++++++++ 2 files changed, 147 insertions(+) create mode 100644 modules/item/back/methods/fixed-price/specs/editFixedPrice.spec.js diff --git a/modules/item/back/methods/fixed-price/specs/editFixedPrice.spec.js b/modules/item/back/methods/fixed-price/specs/editFixedPrice.spec.js new file mode 100644 index 000000000..a5e6cd35a --- /dev/null +++ b/modules/item/back/methods/fixed-price/specs/editFixedPrice.spec.js @@ -0,0 +1,63 @@ +const models = require('vn-loopback/server/server').models; + +describe('Item editFixedPrice()', () => { + it('should change the value of a given column for the selected buys', async() => { + const tx = await models.FixedPrice.beginTransaction({}); + const options = {transaction: tx}; + + try { + const ctx = { + args: { + search: '1' + }, + req: {accessToken: {userId: 1}} + }; + + const [original] = await models.FixedPrice.filter(ctx, null, options); + + const field = 'rate2'; + const newValue = 99; + const lines = [{itemFk: original.itemFk, id: original.id}]; + + await models.FixedPrice.editFixedPrice(ctx, field, newValue, lines, null, options); + + const [result] = await models.FixedPrice.filter(ctx, null, options); + + expect(result[field]).toEqual(newValue); + + await tx.rollback(); + } catch (e) { + await tx.rollback(); + throw e; + } + }); + + it('should change the value of a given column for filter', async() => { + const tx = await models.FixedPrice.beginTransaction({}); + const options = {transaction: tx}; + + try { + const filter = {'it.categoryFk': 1}; + const ctx = { + args: { + filter: filter + }, + req: {accessToken: {userId: 1}} + }; + + const field = 'rate2'; + const newValue = 88; + + await models.FixedPrice.editFixedPrice(ctx, field, newValue, null, filter, options); + + const [result] = await models.FixedPrice.filter(ctx, null, options); + + expect(result[field]).toEqual(newValue); + + await tx.rollback(); + } catch (e) { + await tx.rollback(); + throw e; + } + }); +}); diff --git a/modules/item/front/fixed-price/index.spec.js b/modules/item/front/fixed-price/index.spec.js index 42dd898b3..ae24da60b 100644 --- a/modules/item/front/fixed-price/index.spec.js +++ b/modules/item/front/fixed-price/index.spec.js @@ -12,8 +12,92 @@ describe('fixed price', () => { const $scope = $rootScope.$new(); const $element = angular.element(''); controller = $componentController('vnFixedPrice', {$element, $scope}); + controller.$ = { + model: {refresh: () => {}}, + edit: {hide: () => {}} + }; })); + describe('get columns', () => { + it(`should return a set of columns`, () => { + let result = controller.columns; + + let length = result.length; + let anyColumn = Object.keys(result[Math.floor(Math.random() * Math.floor(length))]); + + expect(anyColumn).toContain('field', 'displayName'); + }); + }); + + describe('get checked', () => { + it(`should return a set of checked lines`, () => { + controller.$.model.data = [ + {checked: true, id: 1}, + {checked: true, id: 2}, + {checked: true, id: 3}, + {checked: false, id: 4}, + ]; + + let result = controller.checked; + + expect(result.length).toEqual(3); + }); + }); + + describe('reCheck()', () => { + it(`should recheck buys`, () => { + controller.$.model.data = [ + {checked: false, id: 1}, + {checked: false, id: 2}, + {checked: false, id: 3}, + {checked: false, id: 4}, + ]; + controller.checkedFixedPrices = [1, 2]; + + controller.reCheck(); + + expect(controller.$.model.data[0].checked).toEqual(true); + expect(controller.$.model.data[1].checked).toEqual(true); + expect(controller.$.model.data[2].checked).toEqual(false); + expect(controller.$.model.data[3].checked).toEqual(false); + }); + }); + + describe('saveChecked()', () => { + it(`should check buy`, () => { + const buyCheck = 3; + controller.checkedFixedPrices = [1, 2]; + + controller.saveChecked(buyCheck); + + expect(controller.checkedFixedPrices[2]).toEqual(buyCheck); + }); + + it(`should uncheck buy`, () => { + const buyUncheck = 3; + controller.checkedFixedPrices = [1, 2, 3]; + + controller.saveChecked(buyUncheck); + + expect(controller.checkedFixedPrices[2]).toEqual(undefined); + }); + }); + + describe('onEditAccept()', () => { + it(`should perform a query to update columns`, () => { + controller.editedColumn = {field: 'my field', newValue: 'the new value'}; + const query = 'FixedPrices/editFixedPrice'; + + $httpBackend.expectPOST(query).respond(); + controller.onEditAccept(); + $httpBackend.flush(); + + const result = controller.checked; + + expect(result.length).toEqual(0); + }); + }); + describe('upsertPrice()', () => { it('should do nothing if one or more required arguments are missing', () => { jest.spyOn(controller.vnApp, 'showSuccess'); From 3450e7ffdf3491116a7cef7e4f25a8c01556d4c0 Mon Sep 17 00:00:00 2001 From: vicent Date: Wed, 5 Apr 2023 09:20:56 +0200 Subject: [PATCH 24/34] refs #5275 fix test e2e --- e2e/helpers/selectors.js | 3 ++- e2e/paths/04-item/13_fixedPrice.spec.js | 8 +++++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/e2e/helpers/selectors.js b/e2e/helpers/selectors.js index 32a60a4e2..06d6ed082 100644 --- a/e2e/helpers/selectors.js +++ b/e2e/helpers/selectors.js @@ -426,7 +426,8 @@ export default { fourthStarted: 'vn-fixed-price tr:nth-child(5) vn-date-picker[ng-model="price.started"]', fourthEnded: 'vn-fixed-price tr:nth-child(5) vn-date-picker[ng-model="price.ended"]', fourthDeleteIcon: 'vn-fixed-price tr:nth-child(5) > td:nth-child(9) > vn-icon-button[icon="delete"]', - orderColumnId: 'vn-fixed-price th[field="itemFk"]' + orderColumnId: 'vn-fixed-price th[field="itemFk"]', + removeWarehouseFilter: 'vn-searchbar > form > vn-textfield > div.container > div.prepend > prepend > div > span:nth-child(1) > vn-icon > i' }, itemCreateView: { temporalName: 'vn-item-create vn-textfield[ng-model="$ctrl.item.provisionalName"]', diff --git a/e2e/paths/04-item/13_fixedPrice.spec.js b/e2e/paths/04-item/13_fixedPrice.spec.js index 1b0f82d83..ec8238b87 100644 --- a/e2e/paths/04-item/13_fixedPrice.spec.js +++ b/e2e/paths/04-item/13_fixedPrice.spec.js @@ -15,8 +15,9 @@ describe('Item fixed prices path', () => { await browser.close(); }); - it('should click on the add new foxed price button', async() => { - await page.doSearch(); + it('should click on the add new fixed price button', async() => { + await page.waitToClick(selectors.itemFixedPrice.removeWarehouseFilter); + await page.waitForSpinnerLoad(); await page.waitToClick(selectors.itemFixedPrice.add); await page.waitForSelector(selectors.itemFixedPrice.fourthFixedPrice); }); @@ -37,7 +38,8 @@ describe('Item fixed prices path', () => { it('should reload the section and check the created price has the expected ID', async() => { await page.accessToSection('item.index'); await page.accessToSection('item.fixedPrice'); - await page.doSearch(); + await page.waitToClick(selectors.itemFixedPrice.removeWarehouseFilter); + await page.waitForSpinnerLoad(); const result = await page.waitToGetProperty(selectors.itemFixedPrice.fourthItemID, 'value'); From 7e42bd11162106f2216a6e070fd54d498002a9e8 Mon Sep 17 00:00:00 2001 From: alexandre Date: Wed, 5 Apr 2023 12:01:42 +0200 Subject: [PATCH 25/34] refs #5379 referencia a vn2008 quitada --- .../reports/expedition-pallet-label/sql/labelData.sql | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/print/templates/reports/expedition-pallet-label/sql/labelData.sql b/print/templates/reports/expedition-pallet-label/sql/labelData.sql index 0661dbe0f..b2a805251 100644 --- a/print/templates/reports/expedition-pallet-label/sql/labelData.sql +++ b/print/templates/reports/expedition-pallet-label/sql/labelData.sql @@ -12,8 +12,8 @@ SELECT ep.id palletFk, JOIN vn.expedition e ON e.id = es.expeditionFk JOIN vn.ticket t ON t.id = e.ticketFk JOIN vn.route r ON r.id = t.routeFk - LEFT JOIN vn2008.Rutas_monitor rm ON rm.Id_Ruta = r.id + LEFT JOIN vn.routesMonitor rm ON rm.routeFk = r.id LEFT JOIN vn.expeditionTruck et2 ON et2.id = rm.expeditionTruckFk WHERE ep.id = ? GROUP BY ep.id, t.routeFk - ORDER BY t.routeFk \ No newline at end of file + ORDER BY t.routeFk From de31d98e2ef4f65921ab548027deec83bc61e199 Mon Sep 17 00:00:00 2001 From: vicent Date: Wed, 5 Apr 2023 13:03:18 +0200 Subject: [PATCH 26/34] refs #5275 fix test e2e --- .../01-salix/03_smartTable_searchBar_integrations.spec.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/e2e/paths/01-salix/03_smartTable_searchBar_integrations.spec.js b/e2e/paths/01-salix/03_smartTable_searchBar_integrations.spec.js index ad558ace2..a3d747f1c 100644 --- a/e2e/paths/01-salix/03_smartTable_searchBar_integrations.spec.js +++ b/e2e/paths/01-salix/03_smartTable_searchBar_integrations.spec.js @@ -90,7 +90,7 @@ describe('SmartTable SearchBar integration', () => { await page.waitToClick(selectors.itemFixedPrice.orderColumnId); const result = await page.waitToGetProperty(selectors.itemFixedPrice.firstItemID, 'value'); - expect(result).toEqual('13'); + expect(result).toEqual('3'); }); it('should reload page and have same order', async() => { @@ -99,7 +99,7 @@ describe('SmartTable SearchBar integration', () => { }); const result = await page.waitToGetProperty(selectors.itemFixedPrice.firstItemID, 'value'); - expect(result).toEqual('13'); + expect(result).toEqual('3'); }); }); }); From a44a640d155ee5b271860217e8bd1beedc73fb18 Mon Sep 17 00:00:00 2001 From: vicent Date: Wed, 5 Apr 2023 15:14:42 +0200 Subject: [PATCH 27/34] refs #4856 manejo errores --- .../methods/worker-time-control/sendMail.js | 60 ++++++++++++++----- 1 file changed, 44 insertions(+), 16 deletions(-) diff --git a/modules/worker/back/methods/worker-time-control/sendMail.js b/modules/worker/back/methods/worker-time-control/sendMail.js index 9d17265e8..17893e6ad 100644 --- a/modules/worker/back/methods/worker-time-control/sendMail.js +++ b/modules/worker/back/methods/worker-time-control/sendMail.js @@ -82,14 +82,9 @@ module.exports = Self => { updated: Date.vnNew(), state: 'SENDED' }, myOptions); - stmt = new ParameterizedSQL( - `CALL vn.timeControl_calculateByUser(?, ?, ?) - `, [args.workerId, started, ended]); + stmt = new ParameterizedSQL('DROP TEMPORARY TABLE IF EXISTS tmp.`user`'); stmts.push(stmt); - - stmt = new ParameterizedSQL( - `CALL vn.timeBusiness_calculateByUser(?, ?, ?) - `, [args.workerId, started, ended]); + stmt = new ParameterizedSQL('CREATE TEMPORARY TABLE tmp.`user` SELECT id userFk FROM account.user WHERE id = vUserFk', [args.workerId]); stmts.push(stmt); } else { await models.WorkerTimeControl.destroyAll({ @@ -105,13 +100,27 @@ module.exports = Self => { updated: Date.vnNew(), state: 'SENDED' }, myOptions); - stmt = new ParameterizedSQL(`CALL vn.timeControl_calculateAll(?, ?)`, [started, ended]); + stmt = new ParameterizedSQL('DROP TEMPORARY TABLE IF EXISTS tmp.`user`'); stmts.push(stmt); - - stmt = new ParameterizedSQL(`CALL vn.timeBusiness_calculateAll(?, ?)`, [started, ended]); + stmt = new ParameterizedSQL('CREATE TEMPORARY TABLE IF NOT EXISTS tmp.`user` SELECT userFk FROM vn.worker w JOIN account.`user` u ON u.id = w.userFk WHERE userFk IS NOT NULL'); stmts.push(stmt); } + stmt = new ParameterizedSQL( + `CALL vn.timeControl_calculate(?, ?) + `, [started, ended]); + stmts.push(stmt); + + stmt = new ParameterizedSQL( + `CALL vn.timeControl_getError(?, ?) + `, [started, ended]); + stmts.push(stmt); + + stmt = new ParameterizedSQL( + `CALL vn.timeBusiness_calculate(?, ?) + `, [started, ended]); + stmts.push(stmt); + stmt = new ParameterizedSQL(` SELECT CONCAT(u.name, '@verdnatura.es') receiver, u.id workerFk, @@ -131,7 +140,13 @@ module.exports = Self => { JOIN business b ON b.id = tb.businessFk LEFT JOIN tmp.timeControlCalculate tc ON tc.userFk = tb.userFk AND tc.dated = tb.dated LEFT JOIN worker w ON w.id = u.id - WHERE IFNULL(?, u.id) = u.id + LEFT JOIN ( + SELECT DISTINCT wtc.userFk + FROM tmp.timeControlError tce + JOIN vn.workerTimeControl wtc ON wtc.id = tce.id + )sub ON sub.userFk = tb.userFk + WHERE sub.userFK IS NULL + AND IFNULL(?, u.id) = u.id AND b.companyCodeFk = 'VNL' AND w.businessFk AND d.isTeleworking @@ -322,11 +337,9 @@ module.exports = Self => { const lastDay = days[index][days[index].length - 1]; if (day.workerFk != previousWorkerFk || day == lastDay) { - await models.WorkerTimeControlMail.create({ - workerFk: previousWorkerFk, - year: args.year, - week: args.week - }, myOptions); + const query = `INSERT IGNORE INTO workerTimeControlMail (workerFk, year, week) + VALUES(?, ?, ?);`; + await Self.rawSql(query, [previousWorkerFk, args.year, args.week]); ctx.args = { recipient: previousReceiver, @@ -351,6 +364,21 @@ module.exports = Self => { } } + // await Self.rawSql('DROP TEMPORARY TABLE IF EXISTS tmp.`user`'); + await Self.rawSql('CREATE TEMPORARY TABLE IF NOT EXISTS tmp.`user` SELECT userFk FROM vn.worker w JOIN account.`user` u ON u.id = w.userFk WHERE userFk IS NOT NULL'); + + await Self.rawSql(`CALL vn.timeControl_getError(?, ?);`, [started, ended]); + const query = `INSERT INTO mail (receiver, replyTo, subject, body) + SELECT CONCAT(u.name, '@verdnatura.es'), + CONCAT('Error registro de horas semana ', vWeek, ' año ', vYear) , + CONCAT('No se ha podido enviar el registro de horas al empleado/s: ', GROUP_CONCAT(DISTINCT CONCAT('
', w.id, ' ', w.firstName, ' ', w.lastName))) + FROM tmp.timeControlError tce + JOIN vn.workerTimeControl wtc ON wtc.id = tce.id + JOIN worker w ON w.id = wtc.userFK + JOIN account.user u ON u.id = w.bossFk + GROUP BY w.bossFk;`; + await Self.rawSql(query, [previousWorkerFk, args.year, args.week]); + return true; }; From 041590e541965af477e6a373d6867d8428b131ed Mon Sep 17 00:00:00 2001 From: vicent Date: Thu, 6 Apr 2023 08:54:12 +0200 Subject: [PATCH 29/34] refs #4856 maneja errores y notifica a los jefes --- .../methods/worker-time-control/sendMail.js | 32 ++++++++----------- 1 file changed, 14 insertions(+), 18 deletions(-) diff --git a/modules/worker/back/methods/worker-time-control/sendMail.js b/modules/worker/back/methods/worker-time-control/sendMail.js index 17893e6ad..2c827e320 100644 --- a/modules/worker/back/methods/worker-time-control/sendMail.js +++ b/modules/worker/back/methods/worker-time-control/sendMail.js @@ -84,7 +84,7 @@ module.exports = Self => { stmt = new ParameterizedSQL('DROP TEMPORARY TABLE IF EXISTS tmp.`user`'); stmts.push(stmt); - stmt = new ParameterizedSQL('CREATE TEMPORARY TABLE tmp.`user` SELECT id userFk FROM account.user WHERE id = vUserFk', [args.workerId]); + stmt = new ParameterizedSQL('CREATE TEMPORARY TABLE tmp.`user` SELECT id userFk FROM account.user WHERE id = ?', [args.workerId]); stmts.push(stmt); } else { await models.WorkerTimeControl.destroyAll({ @@ -112,15 +112,26 @@ module.exports = Self => { stmts.push(stmt); stmt = new ParameterizedSQL( - `CALL vn.timeControl_getError(?, ?) + `CALL vn.timeBusiness_calculate(?, ?) `, [started, ended]); stmts.push(stmt); stmt = new ParameterizedSQL( - `CALL vn.timeBusiness_calculate(?, ?) + `CALL vn.timeControl_getError(?, ?) `, [started, ended]); stmts.push(stmt); + stmt = new ParameterizedSQL(`INSERT INTO mail (receiver, subject, body) + SELECT CONCAT(u.name, '@verdnatura.es'), + CONCAT('Error registro de horas semana ', ?, ' año ', ?) , + CONCAT('No se ha podido enviar el registro de horas al empleado/s: ', GROUP_CONCAT(DISTINCT CONCAT('
', w.id, ' ', w.firstName, ' ', w.lastName))) + FROM tmp.timeControlError tce + JOIN vn.workerTimeControl wtc ON wtc.id = tce.id + JOIN worker w ON w.id = wtc.userFK + JOIN account.user u ON u.id = w.bossFk + GROUP BY w.bossFk`, [args.week, args.year]); + stmts.push(stmt); + stmt = new ParameterizedSQL(` SELECT CONCAT(u.name, '@verdnatura.es') receiver, u.id workerFk, @@ -364,21 +375,6 @@ module.exports = Self => { } } - // await Self.rawSql('DROP TEMPORARY TABLE IF EXISTS tmp.`user`'); - await Self.rawSql('CREATE TEMPORARY TABLE IF NOT EXISTS tmp.`user` SELECT userFk FROM vn.worker w JOIN account.`user` u ON u.id = w.userFk WHERE userFk IS NOT NULL'); - - await Self.rawSql(`CALL vn.timeControl_getError(?, ?);`, [started, ended]); - const query = `INSERT INTO mail (receiver, replyTo, subject, body) - SELECT CONCAT(u.name, '@verdnatura.es'), - CONCAT('Error registro de horas semana ', vWeek, ' año ', vYear) , - CONCAT('No se ha podido enviar el registro de horas al empleado/s: ', GROUP_CONCAT(DISTINCT CONCAT('
', w.id, ' ', w.firstName, ' ', w.lastName))) - FROM tmp.timeControlError tce - JOIN vn.workerTimeControl wtc ON wtc.id = tce.id - JOIN worker w ON w.id = wtc.userFK - JOIN account.user u ON u.id = w.bossFk - GROUP BY w.bossFk;`; - await Self.rawSql(query, [previousWorkerFk, args.year, args.week]); - return true; }; From f307f79dc2fe478b1f64cf612c8b598fbb200356 Mon Sep 17 00:00:00 2001 From: carlossa Date: Thu, 6 Apr 2023 09:34:46 +0200 Subject: [PATCH 30/34] refs #5250 cambio a ult version de changes --- db/changes/{231201 => 231401}/00-workerNotes.sql | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename db/changes/{231201 => 231401}/00-workerNotes.sql (100%) diff --git a/db/changes/231201/00-workerNotes.sql b/db/changes/231401/00-workerNotes.sql similarity index 100% rename from db/changes/231201/00-workerNotes.sql rename to db/changes/231401/00-workerNotes.sql From 8a297469d6dbd1a899ff398fb05bc1089025def3 Mon Sep 17 00:00:00 2001 From: vicent Date: Thu, 6 Apr 2023 10:06:29 +0200 Subject: [PATCH 31/34] =?UTF-8?q?refs=20#4856=20a=C3=B1adido=20myOptions?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../back/methods/worker-time-control/resendWeeklyHourEmail.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/worker/back/methods/worker-time-control/resendWeeklyHourEmail.js b/modules/worker/back/methods/worker-time-control/resendWeeklyHourEmail.js index 5fae6988c..2452a29f9 100644 --- a/modules/worker/back/methods/worker-time-control/resendWeeklyHourEmail.js +++ b/modules/worker/back/methods/worker-time-control/resendWeeklyHourEmail.js @@ -41,7 +41,7 @@ module.exports = Self => { }, myOptions); if (workerTimeControlMail && workerTimeControlMail.state != 'SENDED') { - const worker = await models.EmailUser.findById(workerId); + const worker = await models.EmailUser.findById(workerId, null, myOptions); ctx.args = { recipient: worker.email, year: yearNumber, From ce28339973132ac1d5c60db6fbd1f10521f9b52b Mon Sep 17 00:00:00 2001 From: alexandre Date: Tue, 11 Apr 2023 09:48:31 +0200 Subject: [PATCH 32/34] refs #5522 deleted trigger afterInsert, added hook beforeInsert --- .../231401/00-claimBeginningAfterInsert.sql | 1 + db/dump/fixtures.sql | 10 +++++----- loopback/locale/es.json | 3 ++- loopback/server/connectors/vn-mysql.js | 20 ++++++++++--------- .../claim/specs/createFromSales.spec.js | 4 ++-- modules/claim/back/models/claim-beginning.js | 12 +++++++++-- 6 files changed, 31 insertions(+), 19 deletions(-) create mode 100644 db/changes/231401/00-claimBeginningAfterInsert.sql diff --git a/db/changes/231401/00-claimBeginningAfterInsert.sql b/db/changes/231401/00-claimBeginningAfterInsert.sql new file mode 100644 index 000000000..230b6defb --- /dev/null +++ b/db/changes/231401/00-claimBeginningAfterInsert.sql @@ -0,0 +1 @@ +DROP TRIGGER IF EXISTS `vn`.`claimBeginning_afterInsert`; diff --git a/db/dump/fixtures.sql b/db/dump/fixtures.sql index 9006c6676..59d0a5eaa 100644 --- a/db/dump/fixtures.sql +++ b/db/dump/fixtures.sql @@ -1774,12 +1774,12 @@ INSERT INTO `vn`.`claimState`(`id`, `code`, `description`, `roleFk`, `priority`, ( 6, 'mana', 'Mana', 72, 4, 0), ( 7, 'lack', 'Faltas', 72, 2, 0); -INSERT INTO `vn`.`claim`(`id`, `ticketCreated`, `claimStateFk`, `clientFk`, `workerFk`, `responsibility`, `isChargedToMana`, `created`, `packages`, `rma`) +INSERT INTO `vn`.`claim`(`id`, `ticketCreated`, `claimStateFk`, `clientFk`, `workerFk`, `responsibility`, `isChargedToMana`, `created`, `packages`, `rma`, `ticketFk`) VALUES - (1, util.VN_CURDATE(), 1, 1101, 18, 3, 0, util.VN_CURDATE(), 0, '02676A049183'), - (2, util.VN_CURDATE(), 2, 1101, 18, 3, 0, util.VN_CURDATE(), 1, NULL), - (3, util.VN_CURDATE(), 3, 1101, 18, 1, 1, util.VN_CURDATE(), 5, NULL), - (4, util.VN_CURDATE(), 3, 1104, 18, 5, 0, util.VN_CURDATE(), 10, NULL); + (1, util.VN_CURDATE(), 1, 1101, 18, 3, 0, util.VN_CURDATE(), 0, '02676A049183', 11), + (2, util.VN_CURDATE(), 2, 1101, 18, 3, 0, util.VN_CURDATE(), 1, NULL, 16), + (3, util.VN_CURDATE(), 3, 1101, 18, 1, 1, util.VN_CURDATE(), 5, NULL, 7), + (4, util.VN_CURDATE(), 3, 1104, 18, 5, 0, util.VN_CURDATE(), 10, NULL, 8); INSERT INTO `vn`.`claimObservation` (`claimFk`, `workerFk`, `text`, `created`) VALUES diff --git a/loopback/locale/es.json b/loopback/locale/es.json index 42276efe7..33741d395 100644 --- a/loopback/locale/es.json +++ b/loopback/locale/es.json @@ -274,5 +274,6 @@ "This ticket cannot be signed because it has not been boxed": "Este ticket no puede firmarse porque no ha sido encajado", "Insert a date range": "Inserte un rango de fechas", "Added observation": "{{user}} añadió esta observacion: {{text}}", - "Comment added to client": "Observación añadida al cliente {{clientFk}}" + "Comment added to client": "Observación añadida al cliente {{clientFk}}", + "Cannot create a new claimBeginning from a different ticket": "No se puede crear una línea de reclamación de un ticket diferente al origen" } diff --git a/loopback/server/connectors/vn-mysql.js b/loopback/server/connectors/vn-mysql.js index 728454d86..a6fd3351a 100644 --- a/loopback/server/connectors/vn-mysql.js +++ b/loopback/server/connectors/vn-mysql.js @@ -311,7 +311,7 @@ class VnMySQL extends MySQL { return super[method].apply(this, args); this.invokeMethodP(method, [...args], model, ctx, opts) - .then(res => cb(...res), cb); + .then(res => cb(...[null].concat(res)), cb); } async invokeMethodP(method, args, model, ctx, opts) { @@ -331,8 +331,7 @@ class VnMySQL extends MySQL { const userId = opts.httpCtx && opts.httpCtx.active.accessToken.userId; const user = await Model.app.models.Account.findById(userId, { fields: ['name'] }, opts); await this.executeP(`CALL account.myUser_loginWithName(?)`, [user.name], opts); - } - else { + } else { where = ctx.where; id = ctx.id; data = ctx.data; @@ -358,9 +357,12 @@ class VnMySQL extends MySQL { } } - const res = await new Promise(resolve => { + const res = await new Promise((resolve, reject) => { const fnArgs = args.slice(0, -2); - fnArgs.push(opts, (...args) => resolve(args)); + fnArgs.push(opts, (err, ...args) => { + if (err) return reject(err); + resolve(args); + }); super[method].apply(this, fnArgs); }); @@ -375,11 +377,11 @@ class VnMySQL extends MySQL { case 'update': { switch (method) { case 'createAll': - for (const row of res[1]) + for (const row of res[0]) ids.push(row[idName]); break; case 'create': - ids.push(res[1]); + ids.push(res[0]); break; case 'update': if (data[idName] != null) @@ -387,7 +389,7 @@ class VnMySQL extends MySQL { break; } - const newWhere = ids.length ? { [idName]: ids } : where; + const newWhere = ids.length ? {[idName]: {inq: ids}} : where; const stmt = this.buildSelectStmt(op, data, idName, model, newWhere, limit); newInstances = await this.executeStmt(stmt, opts); @@ -671,4 +673,4 @@ SQLConnector.prototype.all = function find(model, filter, options, cb) { cb(error, []) } }); -}; \ No newline at end of file +}; diff --git a/modules/claim/back/methods/claim/specs/createFromSales.spec.js b/modules/claim/back/methods/claim/specs/createFromSales.spec.js index 7cf663caf..fe009c1c3 100644 --- a/modules/claim/back/methods/claim/specs/createFromSales.spec.js +++ b/modules/claim/back/methods/claim/specs/createFromSales.spec.js @@ -2,9 +2,9 @@ const models = require('vn-loopback/server/server').models; const LoopBackContext = require('loopback-context'); describe('Claim createFromSales()', () => { - const ticketId = 16; + const ticketId = 23; const newSale = [{ - id: 3, + id: 31, instance: 0, quantity: 10 }]; diff --git a/modules/claim/back/models/claim-beginning.js b/modules/claim/back/models/claim-beginning.js index 4c4b59737..4b870e5ea 100644 --- a/modules/claim/back/models/claim-beginning.js +++ b/modules/claim/back/models/claim-beginning.js @@ -10,8 +10,16 @@ module.exports = Self => { }); Self.observe('before save', async ctx => { - if (ctx.isNewInstance) return; - //await claimIsEditable(ctx); + if (ctx.isNewInstance) { + const models = Self.app.models; + const options = ctx.options; + const instance = ctx.instance; + const ticket = await models.Sale.findById(instance.saleFk, {fields: ['ticketFk']}, options); + const claim = await models.Claim.findById(instance.claimFk, {fields: ['ticketFk']}, options); + if (ticket.ticketFk != claim.ticketFk) + throw new UserError(`Cannot create a new claimBeginning from a different ticket`); + } + // await claimIsEditable(ctx); }); Self.observe('before delete', async ctx => { From ec03c6edfa699ca6a1b988fa6e0c418a8337d1c7 Mon Sep 17 00:00:00 2001 From: vicent Date: Tue, 11 Apr 2023 10:23:33 +0200 Subject: [PATCH 33/34] fix intermittent backTest --- .../item/back/methods/fixed-price/specs/editFixedPrice.spec.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/item/back/methods/fixed-price/specs/editFixedPrice.spec.js b/modules/item/back/methods/fixed-price/specs/editFixedPrice.spec.js index a5e6cd35a..9c265f28a 100644 --- a/modules/item/back/methods/fixed-price/specs/editFixedPrice.spec.js +++ b/modules/item/back/methods/fixed-price/specs/editFixedPrice.spec.js @@ -50,7 +50,7 @@ describe('Item editFixedPrice()', () => { await models.FixedPrice.editFixedPrice(ctx, field, newValue, null, filter, options); - const [result] = await models.FixedPrice.filter(ctx, null, options); + const [result] = await models.FixedPrice.filter(ctx, filter, options); expect(result[field]).toEqual(newValue); From eb1798100f691e150285dde60564db162e8e122a Mon Sep 17 00:00:00 2001 From: joan Date: Thu, 13 Apr 2023 08:16:06 +0200 Subject: [PATCH 34/34] Added version 23.16 --- CHANGELOG.md | 14 +++++++++++--- db/changes/231601/.gitkeep | 0 package.json | 2 +- 3 files changed, 12 insertions(+), 4 deletions(-) create mode 100644 db/changes/231601/.gitkeep diff --git a/CHANGELOG.md b/CHANGELOG.md index a346591d8..a3e1ef4a1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,17 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [2316.01] - 2023-05-04 + +### Added +- + +### Changed +- + +### Fixed +- + ## [2314.01] - 2023-04-20 ### Added @@ -12,9 +23,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - (Monitor tickets) Muestra un icono al lado de la zona, si el ticket es frágil y se envía por agencia - (Facturas recibidas -> Bases negativas) Nueva sección -### Changed -- - ### Fixed - (Clientes -> Morosos) Ahora se mantienen los elementos seleccionados al hacer sroll. diff --git a/db/changes/231601/.gitkeep b/db/changes/231601/.gitkeep new file mode 100644 index 000000000..e69de29bb diff --git a/package.json b/package.json index 8fa177646..607367e7b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "salix-back", - "version": "23.14.01", + "version": "23.16.01", "author": "Verdnatura Levante SL", "description": "Salix backend", "license": "GPL-3.0",