From 2a64fde57c74836804c639e7cd21cc2b2f43064f Mon Sep 17 00:00:00 2001 From: vicent Date: Thu, 22 Sep 2022 14:58:38 +0200 Subject: [PATCH 01/55] feat: add option "move expedition" --- modules/ticket/front/expedition/index.html | 119 ++++++++++++--------- modules/ticket/front/expedition/index.js | 11 ++ 2 files changed, 82 insertions(+), 48 deletions(-) diff --git a/modules/ticket/front/expedition/index.html b/modules/ticket/front/expedition/index.html index a41d368f6..37e64fad5 100644 --- a/modules/ticket/front/expedition/index.html +++ b/modules/ticket/front/expedition/index.html @@ -8,54 +8,77 @@ auto-load="true"> - - - - - - Expedition - Item - Name - Package type - Counter - externalId - Created - State - - - - - - - - - - {{expedition.id | zeroFill:6}} - - - {{expedition.packagingFk}} - - - {{::expedition.packageItemName}} - {{::expedition.freightItemName}} - {{::expedition.counter}} - {{::expedition.externalId}} - {{::expedition.created | date:'dd/MM/yyyy HH:mm'}} - {{::expedition.state}} - - - - - - - + + + + + + + + + +

Subtotal {{$ctrl.ticket.totalWithoutVat | currency: 'EUR':2}}

+

VAT {{$ctrl.ticket.totalWithVat - $ctrl.ticket.totalWithoutVat | currency: 'EUR':2}}

+

Total {{$ctrl.ticket.totalWithVat | currency: 'EUR':2}}

+
+
+ + + + + + + + Expedition + Item + Name + Package type + Counter + externalId + Created + State + + + + + + + + + + {{expedition.id | zeroFill:6}} + + + {{expedition.packagingFk}} + + + {{::expedition.packageItemName}} + {{::expedition.freightItemName}} + {{::expedition.counter}} + {{::expedition.externalId}} + {{::expedition.created | date:'dd/MM/yyyy HH:mm'}} + {{::expedition.state}} + + + + + + +
Date: Fri, 23 Sep 2022 08:50:11 +0200 Subject: [PATCH 02/55] feat: add totalChecked --- modules/ticket/front/expedition/index.html | 20 ++++++++++++++++---- modules/ticket/front/expedition/index.js | 4 ++++ 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/modules/ticket/front/expedition/index.html b/modules/ticket/front/expedition/index.html index 37e64fad5..3a5d5f8a6 100644 --- a/modules/ticket/front/expedition/index.html +++ b/modules/ticket/front/expedition/index.html @@ -12,12 +12,11 @@ + ng-show="$ctrl.totalChecked"> @@ -134,4 +133,17 @@ - \ No newline at end of file + + + + + New ticket without route + + + New ticket with route + + \ No newline at end of file diff --git a/modules/ticket/front/expedition/index.js b/modules/ticket/front/expedition/index.js index adbbc53d4..38d02f548 100644 --- a/modules/ticket/front/expedition/index.js +++ b/modules/ticket/front/expedition/index.js @@ -22,6 +22,10 @@ class Controller extends Section { return checkedRows; } + + get totalChecked() { + return this.checked.length; + } } ngModule.vnComponent('vnTicketExpedition', { From 11484edd105c0c57210b523c89f246a55bb1f17d Mon Sep 17 00:00:00 2001 From: vicent Date: Mon, 3 Oct 2022 15:18:07 +0200 Subject: [PATCH 03/55] feat: create new ticket --- modules/ticket/front/expedition/index.html | 22 +++++++++++++++++++--- modules/ticket/front/expedition/index.js | 17 +++++++++++++++++ 2 files changed, 36 insertions(+), 3 deletions(-) diff --git a/modules/ticket/front/expedition/index.html b/modules/ticket/front/expedition/index.html index 3a5d5f8a6..694b3eb33 100644 --- a/modules/ticket/front/expedition/index.html +++ b/modules/ticket/front/expedition/index.html @@ -138,12 +138,28 @@ + ng-click="$ctrl.createTicket()"> New ticket without route + ng-click="selectRoute.show()"> New ticket with route - \ No newline at end of file + + + + + + + + + + + + \ No newline at end of file diff --git a/modules/ticket/front/expedition/index.js b/modules/ticket/front/expedition/index.js index 38d02f548..d80c8e812 100644 --- a/modules/ticket/front/expedition/index.js +++ b/modules/ticket/front/expedition/index.js @@ -26,6 +26,23 @@ class Controller extends Section { get totalChecked() { return this.checked.length; } + + createTicket(routeFk) { + const tomorrow = new Date(); + const params = { + clientId: this.ticket.clientFk, + landed: tomorrow.getDay() + 1, + addressId: this.ticket.addressFk, + agencyModeId: this.ticket.agencyModeFk, + warehouseId: this.ticket.warehouseFk + }; + const query = `Tickets/new`; + this.$http.post(query, params).then(res => { + if (routeFk) this.$http.patch(`Tickets/${res.data.id}`, {routeFk: routeFk}); + this.vnApp.showSuccess(this.$t('Data saved!')); + this.$state.go('ticket.card.summary', {id: res.data.id}); + }); + } } ngModule.vnComponent('vnTicketExpedition', { From 2f17257e46096cdb9049d276df9b1c29c7d3071b Mon Sep 17 00:00:00 2001 From: vicent Date: Wed, 5 Oct 2022 15:13:48 +0200 Subject: [PATCH 04/55] feat: add new sub section itemShelving --- front/salix/locale/es.yml | 1 + modules/item/back/model-config.json | 3 + .../item-shelving-placement-supply.json | 29 +++ modules/item/front/index.js | 2 + modules/item/front/item-shelving/index.html | 172 ++++++++++++++++++ modules/item/front/item-shelving/index.js | 132 ++++++++++++++ .../item/front/item-shelving/index.spec.js | 121 ++++++++++++ .../item/front/item-shelving/locale/es.yml | 9 + modules/item/front/locale/es.yml | 1 + modules/item/front/routes.json | 13 +- modules/shelving/front/routes.json | 2 +- 11 files changed, 483 insertions(+), 2 deletions(-) create mode 100644 modules/item/back/models/item-shelving-placement-supply.json create mode 100644 modules/item/front/item-shelving/index.html create mode 100644 modules/item/front/item-shelving/index.js create mode 100644 modules/item/front/item-shelving/index.spec.js create mode 100644 modules/item/front/item-shelving/locale/es.yml diff --git a/front/salix/locale/es.yml b/front/salix/locale/es.yml index e5dc82b16..d92c32b33 100644 --- a/front/salix/locale/es.yml +++ b/front/salix/locale/es.yml @@ -51,6 +51,7 @@ Entries: Entradas Users: Usuarios Suppliers: Proveedores Monitors: Monitores +Shelvings: Carros # Common diff --git a/modules/item/back/model-config.json b/modules/item/back/model-config.json index 9737d26fc..40d73f1a6 100644 --- a/modules/item/back/model-config.json +++ b/modules/item/back/model-config.json @@ -53,6 +53,9 @@ "ItemShelvingSale": { "dataSource": "vn" }, + "ItemShelvingPlacementSupplyStock": { + "dataSource": "vn" + }, "ItemImageQueue": { "dataSource": "vn" }, diff --git a/modules/item/back/models/item-shelving-placement-supply.json b/modules/item/back/models/item-shelving-placement-supply.json new file mode 100644 index 000000000..11497b4fc --- /dev/null +++ b/modules/item/back/models/item-shelving-placement-supply.json @@ -0,0 +1,29 @@ +{ + "name": "ItemShelvingPlacementSupplyStock", + "base": "VnModel", + "options": { + "mysql": { + "table": "itemShelvingPlacementSupplyStock" + } + }, + "properties": { + "created": { + "type": "date" + }, + "itemFk": { + "type": "number" + }, + "concept": { + "type": "string" + }, + "parking": { + "type": "string" + }, + "shelving": { + "type": "string" + }, + "packing": { + "type": "number" + } + } +} \ No newline at end of file diff --git a/modules/item/front/index.js b/modules/item/front/index.js index 6a8d1b3b7..d2ffcc8fb 100644 --- a/modules/item/front/index.js +++ b/modules/item/front/index.js @@ -24,3 +24,5 @@ import './waste/detail'; import './fixed-price'; import './fixed-price-search-panel'; import './item-type'; +import './item-shelving'; + diff --git a/modules/item/front/item-shelving/index.html b/modules/item/front/item-shelving/index.html new file mode 100644 index 000000000..7949e73a3 --- /dev/null +++ b/modules/item/front/item-shelving/index.html @@ -0,0 +1,172 @@ + + + + + + + + + +
+
+
Total
+ + +
+
+
+ + +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + Created + + Item + + Concept + + Parking + + Shelving + + Etiqueta + + Packing +
+ + + + + {{::defaulter.clientName}} + + + + {{::defaulter.salesPersonName | dashIfEmpty}} + + {{::defaulter.amount | currency: 'EUR': 2}} + + {{::defaulter.workerName | dashIfEmpty}} + + + + + + + {{::defaulter.created | date: 'dd/MM/yyyy'}} + + {{::defaulter.creditInsurance | currency: 'EUR': 2}}{{::defaulter.defaulterSinced | date: 'dd/MM/yyyy'}}
+
+
+
+ + + + + + + + + + + + +
+
{{$ctrl.$t('Add observation to all selected clients', {total: $ctrl.checked.length})}}
+ + + + +
+
+ + + + +
diff --git a/modules/item/front/item-shelving/index.js b/modules/item/front/item-shelving/index.js new file mode 100644 index 000000000..f51a1a65b --- /dev/null +++ b/modules/item/front/item-shelving/index.js @@ -0,0 +1,132 @@ +import ngModule from '../module'; +import Section from 'salix/components/section'; +import UserError from 'core/lib/user-error'; + +export default class Controller extends Section { + constructor($element, $) { + super($element, $); + this.defaulter = {}; + + this.smartTableOptions = { + activeButtons: { + search: true + }, + columns: [ + { + field: 'clientFk', + autocomplete: { + url: 'Clients', + showField: 'name', + valueField: 'id' + } + }, + { + field: 'salesPersonFk', + autocomplete: { + url: 'Workers/activeWithInheritedRole', + where: `{role: 'salesPerson'}`, + searchFunction: '{firstName: $search}', + showField: 'name', + valueField: 'id', + } + }, + { + field: 'workerFk', + autocomplete: { + url: 'Workers/activeWithInheritedRole', + searchFunction: '{firstName: $search}', + showField: 'name', + valueField: 'id', + } + }, + { + field: 'observation', + searchable: false + }, + { + field: 'created', + searchable: false + }, + { + field: 'defaulterSinced', + searchable: false + } + ] + }; + + this.getBalanceDueTotal(); + } + + get checked() { + const clients = this.$.model.data || []; + const checkedLines = []; + for (let defaulter of clients) { + if (defaulter.checked) + checkedLines.push(defaulter); + } + + return checkedLines; + } + + getBalanceDueTotal() { + this.$http.get('Defaulters/filter') + .then(res => { + if (!res.data) return 0; + + this.balanceDueTotal = res.data.reduce( + (accumulator, currentValue) => { + return accumulator + (currentValue['amount'] || 0); + }, 0); + }); + } + + chipColor(date) { + const day = 24 * 60 * 60 * 1000; + const today = new Date(); + today.setHours(0, 0, 0, 0); + + const observationShipped = new Date(date); + observationShipped.setHours(0, 0, 0, 0); + + const difference = today - observationShipped; + + if (difference > (day * 20)) + return 'alert'; + if (difference > (day * 10)) + return 'warning'; + } + + onResponse() { + if (!this.defaulter.observation) + throw new UserError(`The message can't be empty`); + + const params = []; + for (let defaulter of this.checked) { + params.push({ + text: this.defaulter.observation, + clientFk: defaulter.clientFk + }); + } + + this.$http.post(`ClientObservations`, params) .then(() => { + this.vnApp.showMessage(this.$t('Observation saved!')); + this.$state.reload(); + }); + } + + exprBuilder(param, value) { + switch (param) { + case 'creditInsurance': + case 'amount': + case 'clientFk': + case 'workerFk': + case 'salesPersonFk': + return {[`d.${param}`]: value}; + } + } +} + +ngModule.vnComponent('vnItemShelving', { + template: require('./index.html'), + controller: Controller +}); diff --git a/modules/item/front/item-shelving/index.spec.js b/modules/item/front/item-shelving/index.spec.js new file mode 100644 index 000000000..0732c68a1 --- /dev/null +++ b/modules/item/front/item-shelving/index.spec.js @@ -0,0 +1,121 @@ +import './index'; +import crudModel from 'core/mocks/crud-model'; + +describe('client defaulter', () => { + describe('Component vnClientDefaulter', () => { + let controller; + let $httpBackend; + + beforeEach(ngModule('client')); + + beforeEach(inject(($componentController, _$httpBackend_) => { + $httpBackend = _$httpBackend_; + const $element = angular.element(''); + controller = $componentController('vnClientDefaulter', {$element}); + controller.$.model = crudModel; + controller.$.model.data = [ + {clientFk: 1101, amount: 125}, + {clientFk: 1102, amount: 500}, + {clientFk: 1103, amount: 250} + ]; + })); + + describe('checked() getter', () => { + it('should return the checked lines', () => { + const data = controller.$.model.data; + data[1].checked = true; + data[2].checked = true; + + const checkedRows = controller.checked; + + const firstCheckedRow = checkedRows[0]; + const secondCheckedRow = checkedRows[1]; + + expect(firstCheckedRow.clientFk).toEqual(1102); + expect(secondCheckedRow.clientFk).toEqual(1103); + }); + }); + + describe('chipColor()', () => { + it('should return undefined when the date is the present', () => { + let today = new Date(); + let result = controller.chipColor(today); + + expect(result).toEqual(undefined); + }); + + it('should return warning when the date is 10 days in the past', () => { + let pastDate = new Date(); + pastDate = pastDate.setDate(pastDate.getDate() - 11); + let result = controller.chipColor(pastDate); + + expect(result).toEqual('warning'); + }); + + it('should return alert when the date is 20 days in the past', () => { + let pastDate = new Date(); + pastDate = pastDate.setDate(pastDate.getDate() - 21); + let result = controller.chipColor(pastDate); + + expect(result).toEqual('alert'); + }); + }); + + describe('onResponse()', () => { + it('should return error for empty message', () => { + let error; + try { + controller.onResponse(); + } catch (e) { + error = e; + } + + expect(error).toBeDefined(); + expect(error.message).toBe(`The message can't be empty`); + }); + + it('should return saved message', () => { + const data = controller.$.model.data; + data[1].checked = true; + controller.defaulter = {observation: 'My new observation'}; + + const params = [{text: controller.defaulter.observation, clientFk: data[1].clientFk}]; + + jest.spyOn(controller.vnApp, 'showMessage'); + $httpBackend.expect('GET', `Defaulters/filter`).respond(200); + $httpBackend.expect('POST', `ClientObservations`, params).respond(200, params); + + controller.onResponse(); + $httpBackend.flush(); + + expect(controller.vnApp.showMessage).toHaveBeenCalledWith('Observation saved!'); + }); + }); + + describe('exprBuilder()', () => { + it('should search by sales person', () => { + const expr = controller.exprBuilder('salesPersonFk', '5'); + + expect(expr).toEqual({'d.salesPersonFk': '5'}); + }); + + it('should search by client', () => { + const expr = controller.exprBuilder('clientFk', '5'); + + expect(expr).toEqual({'d.clientFk': '5'}); + }); + }); + + describe('getBalanceDueTotal()', () => { + it('should return balance due total', () => { + const defaulters = controller.$.model.data; + $httpBackend.when('GET', `Defaulters/filter`).respond(defaulters); + + controller.getBalanceDueTotal(); + $httpBackend.flush(); + + expect(controller.balanceDueTotal).toEqual(875); + }); + }); + }); +}); diff --git a/modules/item/front/item-shelving/locale/es.yml b/modules/item/front/item-shelving/locale/es.yml new file mode 100644 index 000000000..c3e1d4e19 --- /dev/null +++ b/modules/item/front/item-shelving/locale/es.yml @@ -0,0 +1,9 @@ +Add observation: Añadir observación +Add observation to all selected clients: Añadir observación a {{total}} cliente(s) seleccionado(s) +Balance D.: Saldo V. +Credit I.: Crédito A. +Last observation: Última observación +L. O. Date: Fecha Ú. O. +Last observation date: Fecha última observación +Search client: Buscar clientes +Worker who made the last observation: Trabajador que ha realizado la última observación \ No newline at end of file diff --git a/modules/item/front/locale/es.yml b/modules/item/front/locale/es.yml index 1b75e3802..88ab031e1 100644 --- a/modules/item/front/locale/es.yml +++ b/modules/item/front/locale/es.yml @@ -54,6 +54,7 @@ Basic data: Datos básicos Tax: IVA History: Historial Botanical: Botánico +Shelvings: Carros Barcodes: Códigos de barras Diary: Histórico Item diary: Registro de compra-venta diff --git a/modules/item/front/routes.json b/modules/item/front/routes.json index 5743d0ce7..52cf5d2be 100644 --- a/modules/item/front/routes.json +++ b/modules/item/front/routes.json @@ -16,7 +16,8 @@ {"state": "item.card.basicData", "icon": "settings"}, {"state": "item.card.tags", "icon": "icon-tags"}, {"state": "item.card.tax", "icon": "icon-tax"}, - {"state": "item.card.botanical", "icon": "local_florist"}, + {"state": "item.card.botanical", "icon": "local_florist"}, + {"state": "item.card.shelving", "icon": "icon-inventory"}, {"state": "item.card.itemBarcode", "icon": "icon-barcode"}, {"state": "item.card.diary", "icon": "icon-transaction"}, {"state": "item.card.last-entries", "icon": "icon-regentry"}, @@ -92,6 +93,16 @@ }, "acl": ["buyer"] }, + { + "url" : "/shelving", + "state": "item.card.shelving", + "component": "vn-item-shelving", + "description": "Shelvings", + "params": { + "item": "$ctrl.item" + }, + "acl": ["employee"] + }, { "url" : "/barcode", "state": "item.card.itemBarcode", diff --git a/modules/shelving/front/routes.json b/modules/shelving/front/routes.json index b99ca4cac..0a05db9e3 100644 --- a/modules/shelving/front/routes.json +++ b/modules/shelving/front/routes.json @@ -14,7 +14,7 @@ ] }, "keybindings": [ - {"key": "s", "state": "shelving.index"} + {"key": "c", "state": "shelving.index"} ], "routes": [ { From ddbe1057ad9996e42100e156c188faafd40f1a3f Mon Sep 17 00:00:00 2001 From: vicent Date: Thu, 6 Oct 2022 09:47:53 +0200 Subject: [PATCH 05/55] feat: add new section --- .../10490-august/00-aclItemShelving.sql | 3 + ...00-aclItemShelvingPlacementSupply copy.sql | 3 + .../item-shelving-placement-supply.json | 9 +- modules/item/front/item-shelving/index.html | 132 +++++------------- modules/item/front/item-shelving/index.js | 106 ++++++-------- .../item/front/item-shelving/locale/es.yml | 12 +- 6 files changed, 95 insertions(+), 170 deletions(-) create mode 100644 db/changes/10490-august/00-aclItemShelving.sql create mode 100644 db/changes/10490-august/00-aclItemShelvingPlacementSupply copy.sql diff --git a/db/changes/10490-august/00-aclItemShelving.sql b/db/changes/10490-august/00-aclItemShelving.sql new file mode 100644 index 000000000..3995bbe49 --- /dev/null +++ b/db/changes/10490-august/00-aclItemShelving.sql @@ -0,0 +1,3 @@ +INSERT INTO `salix`.`ACL` (`model`, `property`, `accessType`, `permission`, `principalType`, `principalId`) + VALUES + ('ItemShelving', '*', '*', 'ALLOW', 'ROLE', 'employee'); \ No newline at end of file diff --git a/db/changes/10490-august/00-aclItemShelvingPlacementSupply copy.sql b/db/changes/10490-august/00-aclItemShelvingPlacementSupply copy.sql new file mode 100644 index 000000000..cc589a58f --- /dev/null +++ b/db/changes/10490-august/00-aclItemShelvingPlacementSupply copy.sql @@ -0,0 +1,3 @@ +INSERT INTO `salix`.`ACL` (`model`, `property`, `accessType`, `permission`, `principalType`, `principalId`) + VALUES + ('ItemShelvingPlacementSupplyStock', '*', '*', 'ALLOW', 'ROLE', 'employee'); \ No newline at end of file diff --git a/modules/item/back/models/item-shelving-placement-supply.json b/modules/item/back/models/item-shelving-placement-supply.json index 11497b4fc..a54013e05 100644 --- a/modules/item/back/models/item-shelving-placement-supply.json +++ b/modules/item/back/models/item-shelving-placement-supply.json @@ -7,13 +7,17 @@ } }, "properties": { + "itemShelvingFk": { + "type": "number", + "id": true + }, "created": { "type": "date" }, "itemFk": { "type": "number" }, - "concept": { + "longName": { "type": "string" }, "parking": { @@ -24,6 +28,9 @@ }, "packing": { "type": "number" + }, + "stock": { + "type": "number" } } } \ No newline at end of file diff --git a/modules/item/front/item-shelving/index.html b/modules/item/front/item-shelving/index.html index 7949e73a3..115829c8d 100644 --- a/modules/item/front/item-shelving/index.html +++ b/modules/item/front/item-shelving/index.html @@ -1,21 +1,10 @@ - - - - + ng-click="removeConfirm.show()" + vn-tooltip="Remove selected lines" + vn-acl="replenisherBos" + icon="delete"> @@ -50,123 +39,78 @@ model="model"> - + Created - + Item + field="longName"> Concept + field="parking"> Parking - + Shelving + field="label"> Etiqueta Packing - + - + {{::itemShelvingPlacementSupplyStock.created | date: 'dd/MM/yyyy'}} + + {{::itemShelvingPlacementSupplyStock.itemFk}} + + - {{::defaulter.clientName}} + {{itemShelvingPlacementSupplyStock.longName}} - - {{::defaulter.salesPersonName | dashIfEmpty}} - + {{::itemShelvingPlacementSupplyStock.parking}} - {{::defaulter.amount | currency: 'EUR': 2}} - - {{::defaulter.workerName | dashIfEmpty}} - + {{::itemShelvingPlacementSupplyStock.shelving}} - - - + + {{::itemShelvingPlacementSupplyStock.label}} - - - {{::defaulter.created | date: 'dd/MM/yyyy'}} - + + {{::itemShelvingPlacementSupplyStock.packing}} - {{::defaulter.creditInsurance | currency: 'EUR': 2}} - {{::defaulter.defaulterSinced | date: 'dd/MM/yyyy'}} - - - - - - - - + + - - - -
-
{{$ctrl.$t('Add observation to all selected clients', {total: $ctrl.checked.length})}}
- - - - -
-
- - - - -
+ + \ No newline at end of file diff --git a/modules/item/front/item-shelving/index.js b/modules/item/front/item-shelving/index.js index f51a1a65b..6fd8825aa 100644 --- a/modules/item/front/item-shelving/index.js +++ b/modules/item/front/item-shelving/index.js @@ -1,11 +1,9 @@ import ngModule from '../module'; import Section from 'salix/components/section'; -import UserError from 'core/lib/user-error'; export default class Controller extends Section { constructor($element, $) { super($element, $); - this.defaulter = {}; this.smartTableOptions = { activeButtons: { @@ -13,42 +11,31 @@ export default class Controller extends Section { }, columns: [ { - field: 'clientFk', + field: 'parking', autocomplete: { - url: 'Clients', - showField: 'name', - valueField: 'id' + url: 'Parkings', + showField: 'code', + valueField: 'code' } }, { - field: 'salesPersonFk', + field: 'shelving', autocomplete: { - url: 'Workers/activeWithInheritedRole', - where: `{role: 'salesPerson'}`, - searchFunction: '{firstName: $search}', - showField: 'name', - valueField: 'id', + url: 'Shelvings', + showField: 'code', + valueField: 'code' } }, - { - field: 'workerFk', - autocomplete: { - url: 'Workers/activeWithInheritedRole', - searchFunction: '{firstName: $search}', - showField: 'name', - valueField: 'id', - } - }, - { - field: 'observation', - searchable: false - }, { field: 'created', searchable: false }, { - field: 'defaulterSinced', + field: 'itemFk', + searchable: false + }, + { + field: 'longName', searchable: false } ] @@ -58,16 +45,24 @@ export default class Controller extends Section { } get checked() { - const clients = this.$.model.data || []; + const itemShelvings = this.$.model.data || []; const checkedLines = []; - for (let defaulter of clients) { - if (defaulter.checked) - checkedLines.push(defaulter); + for (let itemShelving of itemShelvings) { + if (itemShelving.checked) + checkedLines.push(itemShelving); } return checkedLines; } + get label() { + const itemShelvings = this.$.model.data || []; + for (let itemShelving of itemShelvings) + itemShelving.label = itemShelving.stock / itemShelving.packing; + + return true; + } + getBalanceDueTotal() { this.$http.get('Defaulters/filter') .then(res => { @@ -80,48 +75,27 @@ export default class Controller extends Section { }); } - chipColor(date) { - const day = 24 * 60 * 60 * 1000; - const today = new Date(); - today.setHours(0, 0, 0, 0); - - const observationShipped = new Date(date); - observationShipped.setHours(0, 0, 0, 0); - - const difference = today - observationShipped; - - if (difference > (day * 20)) - return 'alert'; - if (difference > (day * 10)) - return 'warning'; - } - - onResponse() { - if (!this.defaulter.observation) - throw new UserError(`The message can't be empty`); - + async onRemove() { const params = []; - for (let defaulter of this.checked) { - params.push({ - text: this.defaulter.observation, - clientFk: defaulter.clientFk - }); - } + for (let itemShelving of this.checked) + params.push(itemShelving.itemShelvingFk); - this.$http.post(`ClientObservations`, params) .then(() => { - this.vnApp.showMessage(this.$t('Observation saved!')); - this.$state.reload(); - }); + for (let id of params) { + await this.$http.delete(`ItemShelvings/${id}`) + .then(() => { + this.vnApp.showSuccess(this.$t('ItemShelving removed')); + this.$state.reload(); + }); + } } exprBuilder(param, value) { switch (param) { - case 'creditInsurance': - case 'amount': - case 'clientFk': - case 'workerFk': - case 'salesPersonFk': - return {[`d.${param}`]: value}; + case 'parking': + case 'shelving': + case 'label': + case 'packing': + return {[param]: value}; } } } diff --git a/modules/item/front/item-shelving/locale/es.yml b/modules/item/front/item-shelving/locale/es.yml index c3e1d4e19..00b6ffe58 100644 --- a/modules/item/front/item-shelving/locale/es.yml +++ b/modules/item/front/item-shelving/locale/es.yml @@ -1,9 +1,3 @@ -Add observation: Añadir observación -Add observation to all selected clients: Añadir observación a {{total}} cliente(s) seleccionado(s) -Balance D.: Saldo V. -Credit I.: Crédito A. -Last observation: Última observación -L. O. Date: Fecha Ú. O. -Last observation date: Fecha última observación -Search client: Buscar clientes -Worker who made the last observation: Trabajador que ha realizado la última observación \ No newline at end of file +Shelving: Matrícula +Remove selected lines: Eliminar líneas seleccionadas +Selected lines will be deleted: Las líneas seleccionadas serán eliminadas \ No newline at end of file From a3a432c753c19d263d642c379aa1d7c4977b3a6e Mon Sep 17 00:00:00 2001 From: vicent Date: Thu, 6 Oct 2022 10:18:19 +0200 Subject: [PATCH 06/55] fix: delete one or more expeditions --- modules/ticket/front/expedition/index.html | 11 ++++++----- modules/ticket/front/expedition/index.js | 14 ++++++++++++++ modules/ticket/front/expedition/locale/es.yml | 3 ++- 3 files changed, 22 insertions(+), 6 deletions(-) diff --git a/modules/ticket/front/expedition/index.html b/modules/ticket/front/expedition/index.html index 694b3eb33..caef67f59 100644 --- a/modules/ticket/front/expedition/index.html +++ b/modules/ticket/front/expedition/index.html @@ -17,8 +17,9 @@ ng-show="$ctrl.totalChecked">
@@ -88,11 +89,11 @@ - + on-accept="$ctrl.onRemove()"> diff --git a/modules/ticket/front/expedition/index.js b/modules/ticket/front/expedition/index.js index d80c8e812..1525f97b5 100644 --- a/modules/ticket/front/expedition/index.js +++ b/modules/ticket/front/expedition/index.js @@ -27,6 +27,20 @@ class Controller extends Section { return this.checked.length; } + async onRemove() { + const params = []; + for (let expedition of this.checked) + params.push(expedition.id); + + for (let id of params) { + await this.$http.delete(`Expeditions/${id}`) + .then(() => { + this.vnApp.showSuccess(this.$t('Expedition removed')); + this.$state.reload(); + }); + } + } + createTicket(routeFk) { const tomorrow = new Date(); const params = { diff --git a/modules/ticket/front/expedition/locale/es.yml b/modules/ticket/front/expedition/locale/es.yml index d23cf25af..9c7872fd7 100644 --- a/modules/ticket/front/expedition/locale/es.yml +++ b/modules/ticket/front/expedition/locale/es.yml @@ -1 +1,2 @@ -Status log: Hitorial de estados \ No newline at end of file +Status log: Hitorial de estados +Expedition removed: Expedición eliminada \ No newline at end of file From 37601934f579e55668e5b2eae07e9b68e95a3e81 Mon Sep 17 00:00:00 2001 From: vicent Date: Thu, 6 Oct 2022 11:40:46 +0200 Subject: [PATCH 07/55] feat: first option to delete and update --- modules/ticket/front/expedition/index.js | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/modules/ticket/front/expedition/index.js b/modules/ticket/front/expedition/index.js index 1525f97b5..4f7b34e7c 100644 --- a/modules/ticket/front/expedition/index.js +++ b/modules/ticket/front/expedition/index.js @@ -42,17 +42,25 @@ class Controller extends Section { } createTicket(routeFk) { - const tomorrow = new Date(); - const params = { + const date = new Date(); // esta fecha hay que preguntarla a Fran Monsalvez + const ticketParams = { clientId: this.ticket.clientFk, - landed: tomorrow.getDay() + 1, + landed: date, addressId: this.ticket.addressFk, agencyModeId: this.ticket.agencyModeFk, warehouseId: this.ticket.warehouseFk }; const query = `Tickets/new`; - this.$http.post(query, params).then(res => { + this.$http.post(query, ticketParams).then(res => { if (routeFk) this.$http.patch(`Tickets/${res.data.id}`, {routeFk: routeFk}); + + const params = []; + for (let expedition of this.checked) + params.push(expedition.id); + const expeditionParams = {ticketFk: res.data.id}; + for (let id of params) + this.$http.patch(`Expeditions/${id}`, expeditionParams); + this.vnApp.showSuccess(this.$t('Data saved!')); this.$state.go('ticket.card.summary', {id: res.data.id}); }); From deb8a00dfb2edbd5d3a2a2e84caec89679cce5ad Mon Sep 17 00:00:00 2001 From: vicent Date: Fri, 7 Oct 2022 10:47:54 +0200 Subject: [PATCH 08/55] feat: add backRoutes --- .../methods/expedition/deleteExpeditions.js | 48 +++++++++++++++ .../methods/expedition/moveExpeditions.js | 59 +++++++++++++++++++ modules/ticket/back/models/expedition.js | 2 + modules/ticket/front/expedition/index.html | 4 +- modules/ticket/front/expedition/index.js | 35 +++++------ modules/ticket/front/expedition/locale/es.yml | 5 +- 6 files changed, 130 insertions(+), 23 deletions(-) create mode 100644 modules/ticket/back/methods/expedition/deleteExpeditions.js create mode 100644 modules/ticket/back/methods/expedition/moveExpeditions.js diff --git a/modules/ticket/back/methods/expedition/deleteExpeditions.js b/modules/ticket/back/methods/expedition/deleteExpeditions.js new file mode 100644 index 000000000..b902b9f0c --- /dev/null +++ b/modules/ticket/back/methods/expedition/deleteExpeditions.js @@ -0,0 +1,48 @@ + +module.exports = Self => { + Self.remoteMethod('deleteExpeditions', { + description: 'Delete the selected expeditions', + accessType: 'WRITE', + accepts: [{ + arg: 'expeditionsIds', + type: ['number'], + required: true, + description: 'The expeditions ids to delete' + }], + returns: { + type: ['object'], + root: true + }, + http: { + path: `/deleteExpeditions`, + verb: 'POST' + } + }); + + Self.deleteExpeditions = async(expeditionsIds, options) => { + const models = Self.app.models; + const myOptions = {}; + let tx; + + if (typeof options == 'object') + Object.assign(myOptions, options); + + if (!myOptions.transaction) { + tx = await Self.beginTransaction({}); + myOptions.transaction = tx; + } + + try { + const deletedExpeditions = await models.Expedition.destroyAll({ + id: {inq: expeditionsIds} + }, myOptions); + + if (tx) await tx.commit(); + + return deletedExpeditions; + } catch (e) { + if (tx) await tx.rollback(); + throw e; + } + }; +}; diff --git a/modules/ticket/back/methods/expedition/moveExpeditions.js b/modules/ticket/back/methods/expedition/moveExpeditions.js new file mode 100644 index 000000000..2c521dda7 --- /dev/null +++ b/modules/ticket/back/methods/expedition/moveExpeditions.js @@ -0,0 +1,59 @@ + +module.exports = Self => { + Self.remoteMethod('moveExpeditions', { + description: 'Move the selected expeditions to another ticket', + accessType: 'WRITE', + accepts: [{ + arg: 'expeditionsIds', + type: ['number'], + required: true, + description: 'The expeditions ids to nove' + }, + { + arg: 'ticketId', + type: 'number', + required: true, + description: 'the ticket id to which the expeditions are added' + }], + returns: { + type: 'object', + root: true + }, + http: { + path: `/moveExpeditions`, + verb: 'POST' + } + }); + + Self.moveExpeditions = async(expeditionsIds, ticketId, options) => { + const models = Self.app.models; + const myOptions = {}; + let tx; + + if (typeof options == 'object') + Object.assign(myOptions, options); + + if (!myOptions.transaction) { + tx = await Self.beginTransaction({}); + myOptions.transaction = tx; + } + + try { + const promises = []; + for (let expeditionsId of expeditionsIds) { + const expeditionToUpdate = await models.Expedition.findById(expeditionsId); + const expeditionUpdated = expeditionToUpdate.updateAttribute('ticketFk', ticketId, myOptions); + promises.push(expeditionUpdated); + } + + const updated = await Promise.all(promises); + + if (tx) await tx.commit(); + + return updated; + } catch (e) { + if (tx) await tx.rollback(); + throw e; + } + }; +}; diff --git a/modules/ticket/back/models/expedition.js b/modules/ticket/back/models/expedition.js index 9d6564373..46cde6890 100644 --- a/modules/ticket/back/models/expedition.js +++ b/modules/ticket/back/models/expedition.js @@ -1,3 +1,5 @@ module.exports = function(Self) { require('../methods/expedition/filter')(Self); + require('../methods/expedition/deleteExpeditions')(Self); + require('../methods/expedition/moveExpeditions')(Self); }; diff --git a/modules/ticket/front/expedition/index.html b/modules/ticket/front/expedition/index.html index caef67f59..35f56872c 100644 --- a/modules/ticket/front/expedition/index.html +++ b/modules/ticket/front/expedition/index.html @@ -14,10 +14,10 @@ + disabled="!$ctrl.totalChecked"> diff --git a/modules/ticket/front/expedition/index.js b/modules/ticket/front/expedition/index.js index 4f7b34e7c..a81439d64 100644 --- a/modules/ticket/front/expedition/index.js +++ b/modules/ticket/front/expedition/index.js @@ -17,7 +17,7 @@ class Controller extends Section { const checkedRows = []; for (let row of rows) { if (row.checked) - checkedRows.push(row); + checkedRows.push(row.id); } return checkedRows; @@ -27,18 +27,14 @@ class Controller extends Section { return this.checked.length; } - async onRemove() { - const params = []; - for (let expedition of this.checked) - params.push(expedition.id); - - for (let id of params) { - await this.$http.delete(`Expeditions/${id}`) - .then(() => { - this.vnApp.showSuccess(this.$t('Expedition removed')); - this.$state.reload(); - }); - } + onRemove() { + const params = {expeditionsIds: this.checked}; + const query = `Expeditions/deleteExpeditions`; + this.$http.post(query, params) + .then(() => { + this.vnApp.showSuccess(this.$t('Expedition removed')); + this.$state.reload(); + }); } createTicket(routeFk) { @@ -54,13 +50,12 @@ class Controller extends Section { this.$http.post(query, ticketParams).then(res => { if (routeFk) this.$http.patch(`Tickets/${res.data.id}`, {routeFk: routeFk}); - const params = []; - for (let expedition of this.checked) - params.push(expedition.id); - const expeditionParams = {ticketFk: res.data.id}; - for (let id of params) - this.$http.patch(`Expeditions/${id}`, expeditionParams); - + const params = { + expeditionsIds: this.checked, + ticketId: res.data.id + }; + const query = `Expeditions/moveExpeditions`; + this.$http.post(query, params); this.vnApp.showSuccess(this.$t('Data saved!')); this.$state.go('ticket.card.summary', {id: res.data.id}); }); diff --git a/modules/ticket/front/expedition/locale/es.yml b/modules/ticket/front/expedition/locale/es.yml index 9c7872fd7..bc3ec3345 100644 --- a/modules/ticket/front/expedition/locale/es.yml +++ b/modules/ticket/front/expedition/locale/es.yml @@ -1,2 +1,5 @@ Status log: Hitorial de estados -Expedition removed: Expedición eliminada \ No newline at end of file +Expedition removed: Expedición eliminada +Move: Mover +New ticket without route: Nuevo ticket sin ruta +New ticket with route: Nuevo ticket con ruta \ No newline at end of file From bb26fa6502232335c784f9fb101a381bf4f1be39 Mon Sep 17 00:00:00 2001 From: vicent Date: Fri, 7 Oct 2022 13:49:42 +0200 Subject: [PATCH 09/55] feat: add tFront --- modules/ticket/front/expedition/index.js | 23 ++++---- modules/ticket/front/expedition/index.spec.js | 58 +++++++++++++++++++ 2 files changed, 69 insertions(+), 12 deletions(-) diff --git a/modules/ticket/front/expedition/index.js b/modules/ticket/front/expedition/index.js index a81439d64..f7674716b 100644 --- a/modules/ticket/front/expedition/index.js +++ b/modules/ticket/front/expedition/index.js @@ -2,16 +2,6 @@ import ngModule from '../module'; import Section from 'salix/components/section'; class Controller extends Section { - onDialogAccept(id) { - return this.$http.delete(`Expeditions/${id}`) - .then(() => this.$.model.refresh()); - } - - showLog(expedition) { - this.expedition = expedition; - this.$.statusLog.show(); - } - get checked() { const rows = this.$.model.data || []; const checkedRows = []; @@ -27,13 +17,23 @@ class Controller extends Section { return this.checked.length; } + onDialogAccept(id) { + return this.$http.delete(`Expeditions/${id}`) + .then(() => this.$.model.refresh()); + } + + showLog(expedition) { + this.expedition = expedition; + this.$.statusLog.show(); + } + onRemove() { const params = {expeditionsIds: this.checked}; const query = `Expeditions/deleteExpeditions`; this.$http.post(query, params) .then(() => { this.vnApp.showSuccess(this.$t('Expedition removed')); - this.$state.reload(); + this.$.model.refresh(); }); } @@ -49,7 +49,6 @@ class Controller extends Section { const query = `Tickets/new`; this.$http.post(query, ticketParams).then(res => { if (routeFk) this.$http.patch(`Tickets/${res.data.id}`, {routeFk: routeFk}); - const params = { expeditionsIds: this.checked, ticketId: res.data.id diff --git a/modules/ticket/front/expedition/index.spec.js b/modules/ticket/front/expedition/index.spec.js index 586ef2109..fe23046ce 100644 --- a/modules/ticket/front/expedition/index.spec.js +++ b/modules/ticket/front/expedition/index.spec.js @@ -17,6 +17,14 @@ describe('Ticket', () => { refresh: () => {} }; controller = $componentController('vnTicketExpedition', {$element: null, $scope}); + controller.$.model.data = [ + {id: 1}, + {id: 2}, + {id: 3} + ]; + const modelData = controller.$.model.data; + modelData[0].checked = true; + modelData[1].checked = true; })); describe('onDialogAccept()', () => { @@ -50,5 +58,55 @@ describe('Ticket', () => { expect(controller.$.statusLog.show).toHaveBeenCalledWith(); }); }); + + describe('onRemove()', () => { + it('should make a query and then call to the model refresh() method', () => { + jest.spyOn($scope.model, 'refresh'); + + const expectedParams = {expeditionsIds: [1, 2]}; + $httpBackend.expect('POST', 'Expeditions/deleteExpeditions', expectedParams).respond(200); + controller.onRemove(); + $httpBackend.flush(); + + expect($scope.model.refresh).toHaveBeenCalledWith(); + }); + }); + + describe('createTicket()', () => { + it('should make a query and then call to the $state go() method', () => { + jest.spyOn(controller.$state, 'go').mockReturnThis(); + + const ticket = { + clientFk: 1101, + landed: new Date(), + addressFk: 121, + agencyModeFk: 1, + warehouseFk: 1 + }; + controller.ticket = ticket; + + const expectedTicket = { + clientId: 1101, + landed: new Date(), + addressId: 121, + agencyModeId: 1, + warehouseId: 1 + }; + + const ticketIdToTransfer = 28; + const expectedResponse = {id: ticketIdToTransfer}; + + const expectedParams = { + expeditionsIds: [1, 2], + ticketId: 28 + }; + $httpBackend.expect('POST', 'Tickets/new', expectedTicket).respond(expectedResponse); + $httpBackend.expect('POST', 'Expeditions/moveExpeditions', expectedParams).respond(200); + controller.createTicket(); + $httpBackend.flush(); + + expect(controller.$state.go).toHaveBeenCalledWith('ticket.card.summary', {id: ticketIdToTransfer}); + }); + }); }); }); From 843f67919c9992e7e622f01b8dcfca7697fd81b3 Mon Sep 17 00:00:00 2001 From: vicent Date: Mon, 10 Oct 2022 12:56:03 +0200 Subject: [PATCH 10/55] feat: add backTest --- .../specs/deleteExpeditions.spec.js | 22 ++++++++++++++++++ .../expedition/specs/moveExpeditions.spec.js | 23 +++++++++++++++++++ 2 files changed, 45 insertions(+) create mode 100644 modules/ticket/back/methods/expedition/specs/deleteExpeditions.spec.js create mode 100644 modules/ticket/back/methods/expedition/specs/moveExpeditions.spec.js diff --git a/modules/ticket/back/methods/expedition/specs/deleteExpeditions.spec.js b/modules/ticket/back/methods/expedition/specs/deleteExpeditions.spec.js new file mode 100644 index 000000000..0a47c78da --- /dev/null +++ b/modules/ticket/back/methods/expedition/specs/deleteExpeditions.spec.js @@ -0,0 +1,22 @@ +const models = require('vn-loopback/server/server').models; + +describe('ticket deleteExpeditions()', () => { + it('should delete the selected expeditions', async() => { + const tx = await models.Expedition.beginTransaction({}); + + try { + const options = {transaction: tx}; + + const expeditionIds = [12, 13]; + const result = await models.Expedition.deleteExpeditions(expeditionIds, options); + + expect(result.count).toEqual(2); + + await tx.rollback(); + } catch (e) { + await tx.rollback(); + throw e; + } + }); +}); + diff --git a/modules/ticket/back/methods/expedition/specs/moveExpeditions.spec.js b/modules/ticket/back/methods/expedition/specs/moveExpeditions.spec.js new file mode 100644 index 000000000..0bb402a55 --- /dev/null +++ b/modules/ticket/back/methods/expedition/specs/moveExpeditions.spec.js @@ -0,0 +1,23 @@ +const models = require('vn-loopback/server/server').models; + +describe('ticket moveExpeditions()', () => { + it('should delete the selected expeditions', async() => { + const tx = await models.Expedition.beginTransaction({}); + + try { + const options = {transaction: tx}; + + const expeditionIds = [12, 13]; + const ticketId = 1; + const result = await models.Expedition.moveExpeditions(expeditionIds, ticketId, options); + + expect(result.length).toEqual(2); + + await tx.rollback(); + } catch (e) { + await tx.rollback(); + throw e; + } + }); +}); + From ea1714240e63f97bd91a9de75d3ca8463c88de17 Mon Sep 17 00:00:00 2001 From: vicent Date: Mon, 10 Oct 2022 13:45:34 +0200 Subject: [PATCH 11/55] fix: test e2e --- e2e/helpers/selectors.js | 3 ++- e2e/paths/05-ticket/02_expeditions_and_log.spec.js | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/e2e/helpers/selectors.js b/e2e/helpers/selectors.js index fedcaf5f9..97a58ba9c 100644 --- a/e2e/helpers/selectors.js +++ b/e2e/helpers/selectors.js @@ -596,7 +596,8 @@ export default { submitNotesButton: 'button[type=submit]' }, ticketExpedition: { - thirdExpeditionRemoveButton: 'vn-ticket-expedition vn-table div > vn-tbody > vn-tr:nth-child(3) > vn-td:nth-child(1) > vn-icon-button[icon="delete"]', + thirdSaleCheckbox: 'vn-ticket-expedition vn-tr:nth-child(3) vn-check[ng-model="expedition.checked"]', + deleteExpeditionButton: 'vn-ticket-expedition vn-tool-bar > vn-button[icon="delete"]', expeditionRow: 'vn-ticket-expedition vn-table vn-tbody > vn-tr' }, ticketPackages: { diff --git a/e2e/paths/05-ticket/02_expeditions_and_log.spec.js b/e2e/paths/05-ticket/02_expeditions_and_log.spec.js index dd2525f43..f970247e5 100644 --- a/e2e/paths/05-ticket/02_expeditions_and_log.spec.js +++ b/e2e/paths/05-ticket/02_expeditions_and_log.spec.js @@ -18,7 +18,8 @@ describe('Ticket expeditions and log path', () => { }); it(`should delete a former expedition and confirm the remaining expedition are the expected ones`, async() => { - await page.waitToClick(selectors.ticketExpedition.thirdExpeditionRemoveButton); + await page.waitToClick(selectors.ticketExpedition.thirdSaleCheckbox); + await page.waitToClick(selectors.ticketExpedition.deleteExpeditionButton); await page.waitToClick(selectors.globalItems.acceptButton); await page.reloadSection('ticket.card.expedition'); From 9c52508a88a20d1d5d827b3c8c3e4d08494b32d0 Mon Sep 17 00:00:00 2001 From: vicent Date: Tue, 11 Oct 2022 08:40:22 +0200 Subject: [PATCH 12/55] feat: add total labels --- .../00-aclItemShelving.sql | 0 .../00-aclItemShelvingPlacementSupply.sql} | 0 .../00-itemType.sql | 0 .../item-shelving/deleteItemShelvings.js | 47 +++++++++++++++++++ .../specs/deleteItemShelvings.spec.js | 21 +++++++++ modules/item/back/models/item-shelving.js | 3 ++ modules/item/front/item-shelving/index.html | 18 +++---- modules/item/front/item-shelving/index.js | 45 ++++++------------ .../item/front/item-shelving/locale/es.yml | 4 +- 9 files changed, 98 insertions(+), 40 deletions(-) rename db/changes/{10490-august => 10491-august}/00-aclItemShelving.sql (100%) rename db/changes/{10490-august/00-aclItemShelvingPlacementSupply copy.sql => 10491-august/00-aclItemShelvingPlacementSupply.sql} (100%) rename db/changes/{10480-june => 10491-august}/00-itemType.sql (100%) create mode 100644 modules/item/back/methods/item-shelving/deleteItemShelvings.js create mode 100644 modules/item/back/methods/item-shelving/specs/deleteItemShelvings.spec.js create mode 100644 modules/item/back/models/item-shelving.js diff --git a/db/changes/10490-august/00-aclItemShelving.sql b/db/changes/10491-august/00-aclItemShelving.sql similarity index 100% rename from db/changes/10490-august/00-aclItemShelving.sql rename to db/changes/10491-august/00-aclItemShelving.sql diff --git a/db/changes/10490-august/00-aclItemShelvingPlacementSupply copy.sql b/db/changes/10491-august/00-aclItemShelvingPlacementSupply.sql similarity index 100% rename from db/changes/10490-august/00-aclItemShelvingPlacementSupply copy.sql rename to db/changes/10491-august/00-aclItemShelvingPlacementSupply.sql diff --git a/db/changes/10480-june/00-itemType.sql b/db/changes/10491-august/00-itemType.sql similarity index 100% rename from db/changes/10480-june/00-itemType.sql rename to db/changes/10491-august/00-itemType.sql diff --git a/modules/item/back/methods/item-shelving/deleteItemShelvings.js b/modules/item/back/methods/item-shelving/deleteItemShelvings.js new file mode 100644 index 000000000..0b58970d8 --- /dev/null +++ b/modules/item/back/methods/item-shelving/deleteItemShelvings.js @@ -0,0 +1,47 @@ +module.exports = Self => { + Self.remoteMethod('deleteItemShelvings', { + description: 'Deletes the selected orders', + accessType: 'WRITE', + accepts: [{ + arg: 'itemShelvingIds', + type: ['number'], + required: true, + description: 'The itemShelving ids to delete' + }], + returns: { + type: ['object'], + root: true + }, + http: { + path: `/deleteItemShelvings`, + verb: 'POST' + } + }); + + Self.deleteItemShelvings = async(itemShelvingIds, options) => { + const models = Self.app.models; + const myOptions = {}; + let tx; + + if (typeof options == 'object') + Object.assign(myOptions, options); + + if (!myOptions.transaction) { + tx = await Self.beginTransaction({}); + myOptions.transaction = tx; + } + + try { + const deletedItemShelvings = await models.ItemShelving.destroyAll({ + id: {inq: itemShelvingIds} + }, myOptions); + + if (tx) await tx.commit(); + + return deletedItemShelvings; + } catch (e) { + if (tx) await tx.rollback(); + throw e; + } + }; +}; diff --git a/modules/item/back/methods/item-shelving/specs/deleteItemShelvings.spec.js b/modules/item/back/methods/item-shelving/specs/deleteItemShelvings.spec.js new file mode 100644 index 000000000..a152b5981 --- /dev/null +++ b/modules/item/back/methods/item-shelving/specs/deleteItemShelvings.spec.js @@ -0,0 +1,21 @@ +const models = require('vn-loopback/server/server').models; + +describe('ItemShelving deleteItemShelvings()', () => { + it('should return the deleted itemShelvings', async() => { + const tx = await models.Order.beginTransaction({}); + + try { + const options = {transaction: tx}; + + const itemShelvingIds = [1, 2]; + const result = await models.ItemShelving.deleteItemShelvings(itemShelvingIds, options); + + expect(result.count).toEqual(2); + + await tx.rollback(); + } catch (e) { + await tx.rollback(); + throw e; + } + }); +}); diff --git a/modules/item/back/models/item-shelving.js b/modules/item/back/models/item-shelving.js new file mode 100644 index 000000000..5f372a3be --- /dev/null +++ b/modules/item/back/models/item-shelving.js @@ -0,0 +1,3 @@ +module.exports = Self => { + require('../methods/item-shelving/deleteItemShelvings')(Self); +}; diff --git a/modules/item/front/item-shelving/index.html b/modules/item/front/item-shelving/index.html index 115829c8d..fa7a70544 100644 --- a/modules/item/front/item-shelving/index.html +++ b/modules/item/front/item-shelving/index.html @@ -2,7 +2,7 @@ vn-id="model" url="ItemShelvingPlacementSupplyStocks" link="{itemFk: $ctrl.$params.id}" - data="itemShelvingPlacementSupplyStocks" + data="$ctrl.itemShelvingPlacementSupplyStocks" auto-load="true"> @@ -15,18 +15,18 @@
Total
+ label="Total labels" + value="{{$ctrl.labelTotal.toFixed(2)}}">
+ vn-acl="replenisherBos">
@@ -68,7 +68,9 @@ - + - {{::itemShelvingPlacementSupplyStock.label}} + {{(itemShelvingPlacementSupplyStock.stock / itemShelvingPlacementSupplyStock.packing).toFixed(2)}} {{::itemShelvingPlacementSupplyStock.packing}} diff --git a/modules/item/front/item-shelving/index.js b/modules/item/front/item-shelving/index.js index 6fd8825aa..b8584039b 100644 --- a/modules/item/front/item-shelving/index.js +++ b/modules/item/front/item-shelving/index.js @@ -40,8 +40,6 @@ export default class Controller extends Section { } ] }; - - this.getBalanceDueTotal(); } get checked() { @@ -49,46 +47,31 @@ export default class Controller extends Section { const checkedLines = []; for (let itemShelving of itemShelvings) { if (itemShelving.checked) - checkedLines.push(itemShelving); + checkedLines.push(itemShelving.itemShelvingFk); } return checkedLines; } - get label() { + calculateTotals() { + this.labelTotal = 0; const itemShelvings = this.$.model.data || []; - for (let itemShelving of itemShelvings) - itemShelving.label = itemShelving.stock / itemShelving.packing; - - return true; + itemShelvings.forEach(itemShelving => { + const label = itemShelving.stock / itemShelving.packing; + this.labelTotal += label; + }); } - getBalanceDueTotal() { - this.$http.get('Defaulters/filter') - .then(res => { - if (!res.data) return 0; - - this.balanceDueTotal = res.data.reduce( - (accumulator, currentValue) => { - return accumulator + (currentValue['amount'] || 0); - }, 0); + onRemove() { + const params = {itemShelvingIds: this.checked}; + const query = `ItemShelvings/deleteItemShelvings`; + this.$http.post(query, params) + .then(() => { + this.vnApp.showSuccess(this.$t('ItemShelvings removed')); + this.$.model.refresh(); }); } - async onRemove() { - const params = []; - for (let itemShelving of this.checked) - params.push(itemShelving.itemShelvingFk); - - for (let id of params) { - await this.$http.delete(`ItemShelvings/${id}`) - .then(() => { - this.vnApp.showSuccess(this.$t('ItemShelving removed')); - this.$state.reload(); - }); - } - } - exprBuilder(param, value) { switch (param) { case 'parking': diff --git a/modules/item/front/item-shelving/locale/es.yml b/modules/item/front/item-shelving/locale/es.yml index 00b6ffe58..006363cfa 100644 --- a/modules/item/front/item-shelving/locale/es.yml +++ b/modules/item/front/item-shelving/locale/es.yml @@ -1,3 +1,5 @@ Shelving: Matrícula Remove selected lines: Eliminar líneas seleccionadas -Selected lines will be deleted: Las líneas seleccionadas serán eliminadas \ No newline at end of file +Selected lines will be deleted: Las líneas seleccionadas serán eliminadas +ItemShelvings removed: Carros eliminados +Total labels: Total etiquetas \ No newline at end of file From 1a38fc307f1364676adadf5feb02dc231daf10c4 Mon Sep 17 00:00:00 2001 From: vicent Date: Tue, 11 Oct 2022 08:42:59 +0200 Subject: [PATCH 13/55] delete: duplicated keybinding --- modules/shelving/front/routes.json | 3 --- 1 file changed, 3 deletions(-) diff --git a/modules/shelving/front/routes.json b/modules/shelving/front/routes.json index 0a05db9e3..09a8e389b 100644 --- a/modules/shelving/front/routes.json +++ b/modules/shelving/front/routes.json @@ -13,9 +13,6 @@ {"state": "shelving.card.log", "icon": "history"} ] }, - "keybindings": [ - {"key": "c", "state": "shelving.index"} - ], "routes": [ { "url": "/shelving", From bfefec397e68e86c2879bd1f89d3aacc8763a276 Mon Sep 17 00:00:00 2001 From: vicent Date: Tue, 11 Oct 2022 09:13:29 +0200 Subject: [PATCH 14/55] feat: add testFront --- .../item/front/item-shelving/index.spec.js | 118 ++++++------------ 1 file changed, 39 insertions(+), 79 deletions(-) diff --git a/modules/item/front/item-shelving/index.spec.js b/modules/item/front/item-shelving/index.spec.js index 0732c68a1..55df1c27d 100644 --- a/modules/item/front/item-shelving/index.spec.js +++ b/modules/item/front/item-shelving/index.spec.js @@ -1,120 +1,80 @@ import './index'; import crudModel from 'core/mocks/crud-model'; -describe('client defaulter', () => { - describe('Component vnClientDefaulter', () => { +describe('item shelving', () => { + describe('Component vnItemShelving', () => { let controller; let $httpBackend; - beforeEach(ngModule('client')); + beforeEach(ngModule('item')); beforeEach(inject(($componentController, _$httpBackend_) => { $httpBackend = _$httpBackend_; - const $element = angular.element(''); - controller = $componentController('vnClientDefaulter', {$element}); + const $element = angular.element(''); + controller = $componentController('vnItemShelving', {$element}); controller.$.model = crudModel; controller.$.model.data = [ - {clientFk: 1101, amount: 125}, - {clientFk: 1102, amount: 500}, - {clientFk: 1103, amount: 250} + {itemShelvingFk: 1, packing: 10, stock: 1}, + {itemShelvingFk: 2, packing: 12, stock: 5}, + {itemShelvingFk: 4, packing: 20, stock: 10} ]; + const modelData = controller.$.model.data; + modelData[0].checked = true; + modelData[1].checked = true; })); describe('checked() getter', () => { - it('should return the checked lines', () => { - const data = controller.$.model.data; - data[1].checked = true; - data[2].checked = true; + it('should return a the selected rows', () => { + const result = controller.checked; - const checkedRows = controller.checked; - - const firstCheckedRow = checkedRows[0]; - const secondCheckedRow = checkedRows[1]; - - expect(firstCheckedRow.clientFk).toEqual(1102); - expect(secondCheckedRow.clientFk).toEqual(1103); + expect(result).toEqual(expect.arrayContaining([1, 2])); }); }); - describe('chipColor()', () => { - it('should return undefined when the date is the present', () => { - let today = new Date(); - let result = controller.chipColor(today); + describe('calculateTotals()', () => { + it('should calculate the total of labels', () => { + controller.calculateTotals(); - expect(result).toEqual(undefined); - }); - - it('should return warning when the date is 10 days in the past', () => { - let pastDate = new Date(); - pastDate = pastDate.setDate(pastDate.getDate() - 11); - let result = controller.chipColor(pastDate); - - expect(result).toEqual('warning'); - }); - - it('should return alert when the date is 20 days in the past', () => { - let pastDate = new Date(); - pastDate = pastDate.setDate(pastDate.getDate() - 21); - let result = controller.chipColor(pastDate); - - expect(result).toEqual('alert'); + expect(controller.labelTotal).toEqual(1.0166666666666666); }); }); - describe('onResponse()', () => { - it('should return error for empty message', () => { - let error; - try { - controller.onResponse(); - } catch (e) { - error = e; - } + describe('onRemove()', () => { + it('shoud remove the selected lines', () => { + jest.spyOn(controller.$.model, 'refresh'); + const expectedParams = {itemShelvingIds: [1, 2]}; - expect(error).toBeDefined(); - expect(error.message).toBe(`The message can't be empty`); - }); - - it('should return saved message', () => { - const data = controller.$.model.data; - data[1].checked = true; - controller.defaulter = {observation: 'My new observation'}; - - const params = [{text: controller.defaulter.observation, clientFk: data[1].clientFk}]; - - jest.spyOn(controller.vnApp, 'showMessage'); - $httpBackend.expect('GET', `Defaulters/filter`).respond(200); - $httpBackend.expect('POST', `ClientObservations`, params).respond(200, params); - - controller.onResponse(); + $httpBackend.expectPOST('ItemShelvings/deleteItemShelvings', expectedParams).respond(200); + controller.onRemove(); $httpBackend.flush(); - expect(controller.vnApp.showMessage).toHaveBeenCalledWith('Observation saved!'); + expect(controller.$.model.refresh).toHaveBeenCalled(); }); }); describe('exprBuilder()', () => { - it('should search by sales person', () => { - const expr = controller.exprBuilder('salesPersonFk', '5'); + it('should search by parking', () => { + const expr = controller.exprBuilder('parking', '700-01'); - expect(expr).toEqual({'d.salesPersonFk': '5'}); + expect(expr).toEqual({'parking': '700-01'}); }); - it('should search by client', () => { - const expr = controller.exprBuilder('clientFk', '5'); + it('should search by shelving', () => { + const expr = controller.exprBuilder('shelving', 'AAA'); - expect(expr).toEqual({'d.clientFk': '5'}); + expect(expr).toEqual({'shelving': 'AAA'}); }); - }); - describe('getBalanceDueTotal()', () => { - it('should return balance due total', () => { - const defaulters = controller.$.model.data; - $httpBackend.when('GET', `Defaulters/filter`).respond(defaulters); + it('should search by label', () => { + const expr = controller.exprBuilder('label', 0.17); - controller.getBalanceDueTotal(); - $httpBackend.flush(); + expect(expr).toEqual({'label': 0.17}); + }); - expect(controller.balanceDueTotal).toEqual(875); + it('should search by packing', () => { + const expr = controller.exprBuilder('packing', 10); + + expect(expr).toEqual({'packing': 10}); }); }); }); From 2455a11c26744ac45f81b869b618af686d868157 Mon Sep 17 00:00:00 2001 From: vicent Date: Fri, 14 Oct 2022 14:29:21 +0200 Subject: [PATCH 15/55] feat: changeMultipleDiscount uses the same popover than changeDiscount --- modules/ticket/front/sale/index.html | 30 ++---------------------- modules/ticket/front/sale/index.js | 34 ++++++++++++---------------- 2 files changed, 17 insertions(+), 47 deletions(-) diff --git a/modules/ticket/front/sale/index.html b/modules/ticket/front/sale/index.html index 42eb10cb0..112476c30 100644 --- a/modules/ticket/front/sale/index.html +++ b/modules/ticket/front/sale/index.html @@ -300,7 +300,7 @@ ng-model="$ctrl.manaCode"> -
+

New price

{{$ctrl.getNewPrice() | currency: 'EUR': 2}} @@ -321,32 +321,6 @@

- - - - - -
-
- - -
-
- Mana: {{::$ctrl.edit.mana | currency: 'EUR': 0}} -
-
-
-
-
@@ -490,7 +464,7 @@ + ng-click="$ctrl.showEditDiscountPopover($event, sale)"> Update discount Date: Fri, 14 Oct 2022 14:30:37 +0200 Subject: [PATCH 16/55] fix: only can exists 'mana' or 'manaClaim' discount. Never both --- .../back/methods/ticket/updateDiscount.js | 41 +++++++++++++++++-- 1 file changed, 37 insertions(+), 4 deletions(-) diff --git a/modules/ticket/back/methods/ticket/updateDiscount.js b/modules/ticket/back/methods/ticket/updateDiscount.js index b1291a45b..99daac512 100644 --- a/modules/ticket/back/methods/ticket/updateDiscount.js +++ b/modules/ticket/back/methods/ticket/updateDiscount.js @@ -115,10 +115,43 @@ module.exports = Self => { for (let sale of sales) { const oldDiscount = sale.discount; const value = ((-sale.price * newDiscount) / 100); - const newComponent = models.SaleComponent.upsert({ - saleFk: sale.id, - value: value, - componentFk: componentId}, myOptions); + + const manaComponent = await models.Component.findOne({ + where: {code: 'mana'} + }, myOptions); + + const manaClaimComponent = await models.Component.findOne({ + where: {code: 'manaClaim'} + }, myOptions); + + const oldComponent = await models.SaleComponent.find({ + where: { + and: [ + {saleFk: sale.id}, + {componentFk: {inq: [manaComponent.id, manaClaimComponent.id]}} + ] + } + }, myOptions); + + let newComponent; + if (oldComponent) { + const filter = { + saleFk: sale.id, + componentFk: oldComponent.componentFk + }; + await models.SaleComponent.destroyAll(filter, myOptions); + + newComponent = models.SaleComponent.create({ + saleFk: sale.id, + value: value, + componentFk: componentId + }, myOptions); + } else { + newComponent = models.SaleComponent.create({ + saleFk: sale.id, + value: value, + componentFk: componentId}, myOptions); + } const updatedSale = sale.updateAttribute('discount', newDiscount, myOptions); From 40075e7e21633569a5c7eb29d5f60fbedbb4a9c1 Mon Sep 17 00:00:00 2001 From: vicent Date: Fri, 14 Oct 2022 14:38:47 +0200 Subject: [PATCH 17/55] fix: testFront --- modules/ticket/front/sale/index.js | 1 - modules/ticket/front/sale/index.spec.js | 8 ++++---- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/modules/ticket/front/sale/index.js b/modules/ticket/front/sale/index.js index 714baa126..0d1d28b0e 100644 --- a/modules/ticket/front/sale/index.js +++ b/modules/ticket/front/sale/index.js @@ -273,7 +273,6 @@ class Controller extends Section { const hasChanges = sales.some(sale => { return sale.discount != newDiscount; }); - if (newDiscount != null && hasChanges) this.updateDiscount(sales); diff --git a/modules/ticket/front/sale/index.spec.js b/modules/ticket/front/sale/index.spec.js index 28d874932..a59eb3865 100644 --- a/modules/ticket/front/sale/index.spec.js +++ b/modules/ticket/front/sale/index.spec.js @@ -393,7 +393,7 @@ describe('Ticket', () => { secondSelectedSale.checked = true; const expectedSales = [firstSelectedSale, secondSelectedSale]; - controller.$.editDiscountDialog = {hide: jest.fn()}; + controller.$.editDiscount = {hide: jest.fn()}; controller.edit = { discount: 10, sales: expectedSales @@ -402,7 +402,7 @@ describe('Ticket', () => { controller.changeMultipleDiscount(); expect(controller.updateDiscount).toHaveBeenCalledWith(expectedSales); - expect(controller.$.editDiscountDialog.hide).toHaveBeenCalledWith(); + expect(controller.$.editDiscount.hide).toHaveBeenCalledWith(); }); it('should not call to the updateDiscount() method and then to the editDiscountDialog hide() method', () => { @@ -417,7 +417,7 @@ describe('Ticket', () => { secondSelectedSale.discount = 10; const expectedSales = [firstSelectedSale, secondSelectedSale]; - controller.$.editDiscountDialog = {hide: jest.fn()}; + controller.$.editDiscount = {hide: jest.fn()}; controller.edit = { discount: 10, sales: expectedSales @@ -426,7 +426,7 @@ describe('Ticket', () => { controller.changeMultipleDiscount(); expect(controller.updateDiscount).not.toHaveBeenCalledWith(expectedSales); - expect(controller.$.editDiscountDialog.hide).toHaveBeenCalledWith(); + expect(controller.$.editDiscount.hide).toHaveBeenCalledWith(); }); }); From a11ef73dfbb70a780dc503767cab76c3e7476112 Mon Sep 17 00:00:00 2001 From: vicent Date: Mon, 17 Oct 2022 08:01:55 +0200 Subject: [PATCH 18/55] refactor: code repetead --- .../back/methods/ticket/updateDiscount.js | 24 ++++++++++--------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/modules/ticket/back/methods/ticket/updateDiscount.js b/modules/ticket/back/methods/ticket/updateDiscount.js index 99daac512..d452b03fe 100644 --- a/modules/ticket/back/methods/ticket/updateDiscount.js +++ b/modules/ticket/back/methods/ticket/updateDiscount.js @@ -141,17 +141,9 @@ module.exports = Self => { }; await models.SaleComponent.destroyAll(filter, myOptions); - newComponent = models.SaleComponent.create({ - saleFk: sale.id, - value: value, - componentFk: componentId - }, myOptions); - } else { - newComponent = models.SaleComponent.create({ - saleFk: sale.id, - value: value, - componentFk: componentId}, myOptions); - } + await createSaleComponent(sale.id, value, componentId, myOptions); + } else + await createSaleComponent(sale.id, value, componentId, myOptions); const updatedSale = sale.updateAttribute('discount', newDiscount, myOptions); @@ -198,4 +190,14 @@ module.exports = Self => { throw e; } }; + + async function createSaleComponent(saleId, value, componentId, myOptions) { + const models = Self.app.models; + + newComponent = models.SaleComponent.create({ + saleFk: saleId, + value: value, + componentFk: componentId + }, myOptions); + } }; From 06ecceb478373820cfd0d0c9968ae200462c034c Mon Sep 17 00:00:00 2001 From: vicent Date: Mon, 17 Oct 2022 08:02:19 +0200 Subject: [PATCH 19/55] refactor: lines to long --- .../back/methods/ticket/specs/componentUpdate.spec.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/modules/ticket/back/methods/ticket/specs/componentUpdate.spec.js b/modules/ticket/back/methods/ticket/specs/componentUpdate.spec.js index 2aa2a07c4..a8a4d5048 100644 --- a/modules/ticket/back/methods/ticket/specs/componentUpdate.spec.js +++ b/modules/ticket/back/methods/ticket/specs/componentUpdate.spec.js @@ -18,13 +18,17 @@ describe('ticket componentUpdate()', () => { beforeAll(async() => { const deliveryComponenet = await models.Component.findOne({where: {code: 'delivery'}}); deliveryComponentId = deliveryComponenet.id; - componentOfSaleSeven = `SELECT value FROM vn.saleComponent WHERE saleFk = 7 AND componentFk = ${deliveryComponentId}`; - componentOfSaleEight = `SELECT value FROM vn.saleComponent WHERE saleFk = 8 AND componentFk = ${deliveryComponentId}`; - + componentOfSaleSeven = `SELECT value + FROM vn.saleComponent + WHERE saleFk = 7 AND componentFk = ${deliveryComponentId}`; + componentOfSaleEight = `SELECT value + FROM vn.saleComponent + WHERE saleFk = 8 AND componentFk = ${deliveryComponentId}`; [componentValue] = await models.SaleComponent.rawSql(componentOfSaleSeven); firstvalueBeforeChange = componentValue.value; [componentValue] = await models.SaleComponent.rawSql(componentOfSaleEight); + secondvalueBeforeChange = componentValue.value; }); From cdce628038a2bea5aefd5589a4e68d13a900d69c Mon Sep 17 00:00:00 2001 From: vicent Date: Mon, 17 Oct 2022 08:11:50 +0200 Subject: [PATCH 20/55] refactor: delete line break --- modules/ticket/back/methods/ticket/specs/componentUpdate.spec.js | 1 - 1 file changed, 1 deletion(-) diff --git a/modules/ticket/back/methods/ticket/specs/componentUpdate.spec.js b/modules/ticket/back/methods/ticket/specs/componentUpdate.spec.js index a8a4d5048..b3291c25a 100644 --- a/modules/ticket/back/methods/ticket/specs/componentUpdate.spec.js +++ b/modules/ticket/back/methods/ticket/specs/componentUpdate.spec.js @@ -28,7 +28,6 @@ describe('ticket componentUpdate()', () => { firstvalueBeforeChange = componentValue.value; [componentValue] = await models.SaleComponent.rawSql(componentOfSaleEight); - secondvalueBeforeChange = componentValue.value; }); From 787d10aac6c08fb7e69643b622505d9d1d3a47d4 Mon Sep 17 00:00:00 2001 From: vicent Date: Mon, 17 Oct 2022 08:29:09 +0200 Subject: [PATCH 21/55] fix: select one result only --- modules/ticket/back/methods/ticket/updateDiscount.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/ticket/back/methods/ticket/updateDiscount.js b/modules/ticket/back/methods/ticket/updateDiscount.js index d452b03fe..bfa3cdbf6 100644 --- a/modules/ticket/back/methods/ticket/updateDiscount.js +++ b/modules/ticket/back/methods/ticket/updateDiscount.js @@ -124,7 +124,7 @@ module.exports = Self => { where: {code: 'manaClaim'} }, myOptions); - const oldComponent = await models.SaleComponent.find({ + const [oldComponent] = await models.SaleComponent.find({ where: { and: [ {saleFk: sale.id}, From f85c2e9700dcada8120b286a54a99fd97c333d8e Mon Sep 17 00:00:00 2001 From: vicent Date: Mon, 17 Oct 2022 14:01:21 +0200 Subject: [PATCH 22/55] refactor: delete code repeated --- modules/ticket/back/methods/ticket/updateDiscount.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/modules/ticket/back/methods/ticket/updateDiscount.js b/modules/ticket/back/methods/ticket/updateDiscount.js index bfa3cdbf6..7e7c4e06d 100644 --- a/modules/ticket/back/methods/ticket/updateDiscount.js +++ b/modules/ticket/back/methods/ticket/updateDiscount.js @@ -140,10 +140,9 @@ module.exports = Self => { componentFk: oldComponent.componentFk }; await models.SaleComponent.destroyAll(filter, myOptions); + } - await createSaleComponent(sale.id, value, componentId, myOptions); - } else - await createSaleComponent(sale.id, value, componentId, myOptions); + await createSaleComponent(sale.id, value, componentId, myOptions); const updatedSale = sale.updateAttribute('discount', newDiscount, myOptions); From 423454d19ea755b1ebc1667c1ebbb6830a7bfb80 Mon Sep 17 00:00:00 2001 From: vicent Date: Tue, 18 Oct 2022 11:47:22 +0200 Subject: [PATCH 23/55] feat: add date-picker --- modules/ticket/front/expedition/index.html | 20 ++++++++++++-------- modules/ticket/front/expedition/index.js | 15 ++++++++++----- 2 files changed, 22 insertions(+), 13 deletions(-) diff --git a/modules/ticket/front/expedition/index.html b/modules/ticket/front/expedition/index.html index 35f56872c..f4b261533 100644 --- a/modules/ticket/front/expedition/index.html +++ b/modules/ticket/front/expedition/index.html @@ -138,25 +138,29 @@ + name="withoutRoute" + ng-click="selectLanded.show('withoutRoute')"> New ticket without route + name="withRoute" + ng-click="selectLanded.show('withRoute')"> New ticket with route + vn-id="selectLanded" + on-accept="$ctrl.createTicket($ctrl.landed, $ctrl.newRoute)"> + + + ng-model="$ctrl.newRoute"> diff --git a/modules/ticket/front/expedition/index.js b/modules/ticket/front/expedition/index.js index f7674716b..49ba3280d 100644 --- a/modules/ticket/front/expedition/index.js +++ b/modules/ticket/front/expedition/index.js @@ -2,6 +2,12 @@ import ngModule from '../module'; import Section from 'salix/components/section'; class Controller extends Section { + constructor($element, $scope) { + super($element, $scope); + this.landed = new Date(); + this.newRoute = null; + } + get checked() { const rows = this.$.model.data || []; const checkedRows = []; @@ -28,7 +34,7 @@ class Controller extends Section { } onRemove() { - const params = {expeditionsIds: this.checked}; + const params = {expeditionIds: this.checked}; const query = `Expeditions/deleteExpeditions`; this.$http.post(query, params) .then(() => { @@ -37,11 +43,10 @@ class Controller extends Section { }); } - createTicket(routeFk) { - const date = new Date(); // esta fecha hay que preguntarla a Fran Monsalvez + createTicket(landed, routeFk) { const ticketParams = { clientId: this.ticket.clientFk, - landed: date, + landed: landed, addressId: this.ticket.addressFk, agencyModeId: this.ticket.agencyModeFk, warehouseId: this.ticket.warehouseFk @@ -50,7 +55,7 @@ class Controller extends Section { this.$http.post(query, ticketParams).then(res => { if (routeFk) this.$http.patch(`Tickets/${res.data.id}`, {routeFk: routeFk}); const params = { - expeditionsIds: this.checked, + expeditionIds: this.checked, ticketId: res.data.id }; const query = `Expeditions/moveExpeditions`; From 5fce93abd5bd36720eec2ffa6d7df0f0ec3cbcd4 Mon Sep 17 00:00:00 2001 From: vicent Date: Tue, 18 Oct 2022 11:47:37 +0200 Subject: [PATCH 24/55] refactor: change variables name --- modules/ticket/back/methods/expedition/deleteExpeditions.js | 6 +++--- modules/ticket/back/methods/expedition/moveExpeditions.js | 6 +++--- modules/ticket/front/expedition/index.spec.js | 4 ++-- modules/ticket/front/expedition/locale/es.yml | 3 ++- 4 files changed, 10 insertions(+), 9 deletions(-) diff --git a/modules/ticket/back/methods/expedition/deleteExpeditions.js b/modules/ticket/back/methods/expedition/deleteExpeditions.js index b902b9f0c..5b9d0daaa 100644 --- a/modules/ticket/back/methods/expedition/deleteExpeditions.js +++ b/modules/ticket/back/methods/expedition/deleteExpeditions.js @@ -4,7 +4,7 @@ module.exports = Self => { description: 'Delete the selected expeditions', accessType: 'WRITE', accepts: [{ - arg: 'expeditionsIds', + arg: 'expeditionIds', type: ['number'], required: true, description: 'The expeditions ids to delete' @@ -19,7 +19,7 @@ module.exports = Self => { } }); - Self.deleteExpeditions = async(expeditionsIds, options) => { + Self.deleteExpeditions = async(expeditionIds, options) => { const models = Self.app.models; const myOptions = {}; let tx; @@ -34,7 +34,7 @@ module.exports = Self => { try { const deletedExpeditions = await models.Expedition.destroyAll({ - id: {inq: expeditionsIds} + id: {inq: expeditionIds} }, myOptions); if (tx) await tx.commit(); diff --git a/modules/ticket/back/methods/expedition/moveExpeditions.js b/modules/ticket/back/methods/expedition/moveExpeditions.js index 2c521dda7..338568fdb 100644 --- a/modules/ticket/back/methods/expedition/moveExpeditions.js +++ b/modules/ticket/back/methods/expedition/moveExpeditions.js @@ -4,7 +4,7 @@ module.exports = Self => { description: 'Move the selected expeditions to another ticket', accessType: 'WRITE', accepts: [{ - arg: 'expeditionsIds', + arg: 'expeditionIds', type: ['number'], required: true, description: 'The expeditions ids to nove' @@ -25,7 +25,7 @@ module.exports = Self => { } }); - Self.moveExpeditions = async(expeditionsIds, ticketId, options) => { + Self.moveExpeditions = async(expeditionIds, ticketId, options) => { const models = Self.app.models; const myOptions = {}; let tx; @@ -40,7 +40,7 @@ module.exports = Self => { try { const promises = []; - for (let expeditionsId of expeditionsIds) { + for (let expeditionsId of expeditionIds) { const expeditionToUpdate = await models.Expedition.findById(expeditionsId); const expeditionUpdated = expeditionToUpdate.updateAttribute('ticketFk', ticketId, myOptions); promises.push(expeditionUpdated); diff --git a/modules/ticket/front/expedition/index.spec.js b/modules/ticket/front/expedition/index.spec.js index fe23046ce..ad5dafbd7 100644 --- a/modules/ticket/front/expedition/index.spec.js +++ b/modules/ticket/front/expedition/index.spec.js @@ -63,7 +63,7 @@ describe('Ticket', () => { it('should make a query and then call to the model refresh() method', () => { jest.spyOn($scope.model, 'refresh'); - const expectedParams = {expeditionsIds: [1, 2]}; + const expectedParams = {expeditionIds: [1, 2]}; $httpBackend.expect('POST', 'Expeditions/deleteExpeditions', expectedParams).respond(200); controller.onRemove(); $httpBackend.flush(); @@ -97,7 +97,7 @@ describe('Ticket', () => { const expectedResponse = {id: ticketIdToTransfer}; const expectedParams = { - expeditionsIds: [1, 2], + expeditionIds: [1, 2], ticketId: 28 }; $httpBackend.expect('POST', 'Tickets/new', expectedTicket).respond(expectedResponse); diff --git a/modules/ticket/front/expedition/locale/es.yml b/modules/ticket/front/expedition/locale/es.yml index bc3ec3345..68812f985 100644 --- a/modules/ticket/front/expedition/locale/es.yml +++ b/modules/ticket/front/expedition/locale/es.yml @@ -2,4 +2,5 @@ Status log: Hitorial de estados Expedition removed: Expedición eliminada Move: Mover New ticket without route: Nuevo ticket sin ruta -New ticket with route: Nuevo ticket con ruta \ No newline at end of file +New ticket with route: Nuevo ticket con ruta +Id route: Id ruta \ No newline at end of file From ae3e3c3c49c4dc474d96fbd510febaa03fb28f7c Mon Sep 17 00:00:00 2001 From: vicent Date: Tue, 18 Oct 2022 12:37:06 +0200 Subject: [PATCH 25/55] fix: id model duplicated --- modules/ticket/front/expedition/index.html | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/modules/ticket/front/expedition/index.html b/modules/ticket/front/expedition/index.html index f4b261533..0ebe388c1 100644 --- a/modules/ticket/front/expedition/index.html +++ b/modules/ticket/front/expedition/index.html @@ -98,16 +98,16 @@ - + - + State From 9ea427dbfece8d68a6350e1f9861f2222c31f631 Mon Sep 17 00:00:00 2001 From: vicent Date: Tue, 18 Oct 2022 13:45:46 +0200 Subject: [PATCH 26/55] refactor: move front to back funcionality --- loopback/locale/es.json | 3 +- .../methods/expedition/moveExpeditions.js | 60 +++++++++++++++---- modules/ticket/front/expedition/index.js | 17 ++---- 3 files changed, 55 insertions(+), 25 deletions(-) diff --git a/loopback/locale/es.json b/loopback/locale/es.json index 67370b343..bd9de41c2 100644 --- a/loopback/locale/es.json +++ b/loopback/locale/es.json @@ -235,5 +235,6 @@ "Dirección incorrecta": "Dirección incorrecta", "Modifiable user details only by an administrator": "Detalles de usuario modificables solo por un administrador", "Modifiable password only via recovery or by an administrator": "Contraseña modificable solo a través de la recuperación o por un administrador", - "Not enough privileges to edit a client": "No tienes suficientes privilegios para editar un cliente" + "Not enough privileges to edit a client": "No tienes suficientes privilegios para editar un cliente", + "This route not exists": "Esta ruta no existe" } \ No newline at end of file diff --git a/modules/ticket/back/methods/expedition/moveExpeditions.js b/modules/ticket/back/methods/expedition/moveExpeditions.js index 338568fdb..d0f8aa893 100644 --- a/modules/ticket/back/methods/expedition/moveExpeditions.js +++ b/modules/ticket/back/methods/expedition/moveExpeditions.js @@ -1,19 +1,47 @@ +const UserError = require('vn-loopback/util/user-error'); module.exports = Self => { - Self.remoteMethod('moveExpeditions', { + Self.remoteMethodCtx('moveExpeditions', { description: 'Move the selected expeditions to another ticket', accessType: 'WRITE', accepts: [{ + arg: 'clientId', + type: 'number', + description: `The client id`, + required: true + }, + { + arg: 'landed', + type: 'date', + description: `The landing date` + }, + { + arg: 'warehouseId', + type: 'number', + description: `The warehouse id`, + required: true + }, + { + arg: 'addressId', + type: 'number', + description: `The address id`, + required: true + }, + { + arg: 'agencyModeId', + type: 'any', + description: `The agencyMode id` + }, + { + arg: 'routeId', + type: 'any', + description: `The route id` + }, + { arg: 'expeditionIds', type: ['number'], required: true, - description: 'The expeditions ids to nove' - }, - { - arg: 'ticketId', - type: 'number', - required: true, - description: 'the ticket id to which the expeditions are added' + description: 'The expeditions ids to move' }], returns: { type: 'object', @@ -25,8 +53,9 @@ module.exports = Self => { } }); - Self.moveExpeditions = async(expeditionIds, ticketId, options) => { + Self.moveExpeditions = async(ctx, options) => { const models = Self.app.models; + const args = ctx.args; const myOptions = {}; let tx; @@ -39,18 +68,23 @@ module.exports = Self => { } try { + if (args.routeId) { + const route = await models.Route.findById(args.routeId, null, myOptions); + if (!route) throw new UserError('This route not exists'); + } + const ticket = await models.Ticket.new(ctx, myOptions); const promises = []; - for (let expeditionsId of expeditionIds) { + for (let expeditionsId of args.expeditionIds) { const expeditionToUpdate = await models.Expedition.findById(expeditionsId); - const expeditionUpdated = expeditionToUpdate.updateAttribute('ticketFk', ticketId, myOptions); + const expeditionUpdated = expeditionToUpdate.updateAttribute('ticketFk', ticket.id, myOptions); promises.push(expeditionUpdated); } - const updated = await Promise.all(promises); + await Promise.all(promises); if (tx) await tx.commit(); - return updated; + return ticket; } catch (e) { if (tx) await tx.rollback(); throw e; diff --git a/modules/ticket/front/expedition/index.js b/modules/ticket/front/expedition/index.js index 49ba3280d..7ffe2fe5e 100644 --- a/modules/ticket/front/expedition/index.js +++ b/modules/ticket/front/expedition/index.js @@ -44,22 +44,17 @@ class Controller extends Section { } createTicket(landed, routeFk) { - const ticketParams = { + const params = { clientId: this.ticket.clientFk, landed: landed, + warehouseId: this.ticket.warehouseFk, addressId: this.ticket.addressFk, agencyModeId: this.ticket.agencyModeFk, - warehouseId: this.ticket.warehouseFk + routeId: routeFk, + expeditionIds: this.checked }; - const query = `Tickets/new`; - this.$http.post(query, ticketParams).then(res => { - if (routeFk) this.$http.patch(`Tickets/${res.data.id}`, {routeFk: routeFk}); - const params = { - expeditionIds: this.checked, - ticketId: res.data.id - }; - const query = `Expeditions/moveExpeditions`; - this.$http.post(query, params); + const query = `Expeditions/moveExpeditions`; + this.$http.post(query, params).then(res => { this.vnApp.showSuccess(this.$t('Data saved!')); this.$state.go('ticket.card.summary', {id: res.data.id}); }); From 51cad752984fb2d13f804772aa8bec233430e4f7 Mon Sep 17 00:00:00 2001 From: vicent Date: Thu, 20 Oct 2022 08:17:15 +0200 Subject: [PATCH 27/55] fix: testFront --- modules/ticket/front/expedition/index.spec.js | 28 ++++++++----------- 1 file changed, 12 insertions(+), 16 deletions(-) diff --git a/modules/ticket/front/expedition/index.spec.js b/modules/ticket/front/expedition/index.spec.js index ad5dafbd7..b95d64fa3 100644 --- a/modules/ticket/front/expedition/index.spec.js +++ b/modules/ticket/front/expedition/index.spec.js @@ -83,29 +83,25 @@ describe('Ticket', () => { agencyModeFk: 1, warehouseFk: 1 }; + const routeId = null; controller.ticket = ticket; - const expectedTicket = { - clientId: 1101, - landed: new Date(), - addressId: 121, - agencyModeId: 1, - warehouseId: 1 - }; - - const ticketIdToTransfer = 28; - const expectedResponse = {id: ticketIdToTransfer}; + const ticketToTransfer = {id: 28}; const expectedParams = { - expeditionIds: [1, 2], - ticketId: 28 + clientId: 1101, + landed: new Date(), + warehouseId: 1, + addressId: 121, + agencyModeId: 1, + routeId: null, + expeditionIds: [1, 2] }; - $httpBackend.expect('POST', 'Tickets/new', expectedTicket).respond(expectedResponse); - $httpBackend.expect('POST', 'Expeditions/moveExpeditions', expectedParams).respond(200); - controller.createTicket(); + $httpBackend.expect('POST', 'Expeditions/moveExpeditions', expectedParams).respond(ticketToTransfer); + controller.createTicket(ticket.landed, routeId); $httpBackend.flush(); - expect(controller.$state.go).toHaveBeenCalledWith('ticket.card.summary', {id: ticketIdToTransfer}); + expect(controller.$state.go).toHaveBeenCalledWith('ticket.card.summary', {id: ticketToTransfer.id}); }); }); }); From bcc9acac0ac997d9c54df4e12efc830dc50c1331 Mon Sep 17 00:00:00 2001 From: vicent Date: Thu, 20 Oct 2022 08:41:00 +0200 Subject: [PATCH 28/55] fix: tBack --- .../expedition/specs/moveExpeditions.spec.js | 26 +++++++++++++++---- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/modules/ticket/back/methods/expedition/specs/moveExpeditions.spec.js b/modules/ticket/back/methods/expedition/specs/moveExpeditions.spec.js index 0bb402a55..67919e76c 100644 --- a/modules/ticket/back/methods/expedition/specs/moveExpeditions.spec.js +++ b/modules/ticket/back/methods/expedition/specs/moveExpeditions.spec.js @@ -1,17 +1,33 @@ const models = require('vn-loopback/server/server').models; describe('ticket moveExpeditions()', () => { - it('should delete the selected expeditions', async() => { + it('should move the selected expeditions to new ticket', async() => { const tx = await models.Expedition.beginTransaction({}); + const ctx = { + req: {accessToken: {userId: 9}}, + args: {}, + params: {} + }; + const myCtx = Object.assign({}, ctx); try { const options = {transaction: tx}; + myCtx.args = { + clientId: 1101, + landed: new Date(), + warehouseId: 1, + addressId: 121, + agencyModeId: 1, + routeId: null, + expeditionIds: [1, 2] - const expeditionIds = [12, 13]; - const ticketId = 1; - const result = await models.Expedition.moveExpeditions(expeditionIds, ticketId, options); + }; - expect(result.length).toEqual(2); + const ticket = await models.Expedition.moveExpeditions(myCtx, options); + + const newestTicketIdInFixtures = 27; + + expect(ticket.id).toBeGreaterThan(newestTicketIdInFixtures); await tx.rollback(); } catch (e) { From 2da34d0850de92ee8684fb9d339b59a4ff2cc852 Mon Sep 17 00:00:00 2001 From: vicent Date: Thu, 20 Oct 2022 09:40:11 +0200 Subject: [PATCH 29/55] feat: add e2e --- e2e/helpers/selectors.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/e2e/helpers/selectors.js b/e2e/helpers/selectors.js index 74dabc31a..dabb4c0cd 100644 --- a/e2e/helpers/selectors.js +++ b/e2e/helpers/selectors.js @@ -596,8 +596,14 @@ export default { submitNotesButton: 'button[type=submit]' }, ticketExpedition: { + firstSaleCheckbox: 'vn-ticket-expedition vn-tr:nth-child(1) vn-check[ng-model="expedition.checked"]', thirdSaleCheckbox: 'vn-ticket-expedition vn-tr:nth-child(3) vn-check[ng-model="expedition.checked"]', deleteExpeditionButton: 'vn-ticket-expedition vn-tool-bar > vn-button[icon="delete"]', + moveExpeditionButton: 'vn-ticket-expedition vn-tool-bar > vn-button[icon="keyboard_arrow_down"]', + moreMenuWithoutRoute: 'vn-item[name="withoutRoute"]', + moreMenuWithRoute: 'vn-item[name="withRoute"]', + newRouteId: '.vn-dialog.shown vn-textfield[ng-model="$ctrl.newRoute"]', + saveButton: '.vn-dialog.shown [response="accept"]', expeditionRow: 'vn-ticket-expedition vn-table vn-tbody > vn-tr' }, ticketPackages: { From 5824fee213055de7401a1ebd3e63f7879199315a Mon Sep 17 00:00:00 2001 From: vicent Date: Thu, 20 Oct 2022 09:40:23 +0200 Subject: [PATCH 30/55] feat: add e2e --- e2e/paths/05-ticket/20_moveExpedition.spec.js | 50 +++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 e2e/paths/05-ticket/20_moveExpedition.spec.js diff --git a/e2e/paths/05-ticket/20_moveExpedition.spec.js b/e2e/paths/05-ticket/20_moveExpedition.spec.js new file mode 100644 index 000000000..9673c7071 --- /dev/null +++ b/e2e/paths/05-ticket/20_moveExpedition.spec.js @@ -0,0 +1,50 @@ +import selectors from '../../helpers/selectors.js'; +import getBrowser from '../../helpers/puppeteer'; + +fdescribe('Ticket expeditions', () => { + let browser; + let page; + + beforeAll(async() => { + browser = await getBrowser(); + page = browser.page; + await page.loginAndModule('production', 'ticket'); + await page.accessToSearchResult('1'); + await page.accessToSection('ticket.card.expedition'); + }); + + afterAll(async() => { + await browser.close(); + }); + + it(`should move one expedition to new ticket withoute route`, async() => { + await page.waitToClick(selectors.ticketExpedition.thirdSaleCheckbox); + await page.waitToClick(selectors.ticketExpedition.moveExpeditionButton); + await page.waitToClick(selectors.ticketExpedition.moreMenuWithoutRoute); + await page.waitToClick(selectors.ticketExpedition.saveButton); + await page.waitForState('ticket.card.summary'); + await page.accessToSection('ticket.card.expedition'); + + await page.waitForSelector(selectors.ticketExpedition.expeditionRow, {}); + const result = await page + .countElement(selectors.ticketExpedition.expeditionRow); + + expect(result).toEqual(1); + }); + + it(`should move one expedition to new ticket with route`, async() => { + await page.waitToClick(selectors.ticketExpedition.firstSaleCheckbox); + await page.waitToClick(selectors.ticketExpedition.moveExpeditionButton); + await page.waitToClick(selectors.ticketExpedition.moreMenuWithRoute); + await page.write(selectors.ticketExpedition.newRouteId, '1'); + await page.waitToClick(selectors.ticketExpedition.saveButton); + await page.waitForState('ticket.card.summary'); + await page.accessToSection('ticket.card.expedition'); + + await page.waitForSelector(selectors.ticketExpedition.expeditionRow, {}); + const result = await page + .countElement(selectors.ticketExpedition.expeditionRow); + + expect(result).toEqual(1); + }); +}); From dd15d06f5edfb7c439482764551175e7fe225b70 Mon Sep 17 00:00:00 2001 From: vicent Date: Thu, 20 Oct 2022 10:21:44 +0200 Subject: [PATCH 31/55] delete focus test --- e2e/paths/05-ticket/20_moveExpedition.spec.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/e2e/paths/05-ticket/20_moveExpedition.spec.js b/e2e/paths/05-ticket/20_moveExpedition.spec.js index 9673c7071..cf1c5ded3 100644 --- a/e2e/paths/05-ticket/20_moveExpedition.spec.js +++ b/e2e/paths/05-ticket/20_moveExpedition.spec.js @@ -1,7 +1,7 @@ import selectors from '../../helpers/selectors.js'; import getBrowser from '../../helpers/puppeteer'; -fdescribe('Ticket expeditions', () => { +describe('Ticket expeditions', () => { let browser; let page; From 29093d7d30e98083c36ee81bebb5c5ed95453020 Mon Sep 17 00:00:00 2001 From: vicent Date: Thu, 20 Oct 2022 14:25:55 +0200 Subject: [PATCH 32/55] =?UTF-8?q?feat:=20en=20vez=20de=20consultar=20si=20?= =?UTF-8?q?el=20usuario=20est=C3=A1=20en=20la=20tabla=20workerMana,=20cons?= =?UTF-8?q?ultar=20es=20si=20el=20usuario=20est=C3=A1=20en=20un=20departam?= =?UTF-8?q?ento=20que=20cuelga=20de=20ventas?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../back/methods/sale/specs/updatePrice.spec.js | 11 ++++++++++- modules/ticket/back/methods/sale/updatePrice.js | 8 ++++++-- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/modules/ticket/back/methods/sale/specs/updatePrice.spec.js b/modules/ticket/back/methods/sale/specs/updatePrice.spec.js index e76511421..75be665fb 100644 --- a/modules/ticket/back/methods/sale/specs/updatePrice.spec.js +++ b/modules/ticket/back/methods/sale/specs/updatePrice.spec.js @@ -79,10 +79,19 @@ describe('sale updatePrice()', () => { const price = 5.4; const originalSalesPersonMana = await models.WorkerMana.findById(18, null, options); const manaComponent = await models.Component.findOne({where: {code: 'mana'}}, options); + const teamCLopez = 96; + const userId = 18; + await models.Sale.rawSql(`UPDATE vn.business b + JOIN vn.department d ON d.id = b.departmentFk + SET b.departmentFk = ? + WHERE b.id = ?`, [teamCLopez, userId]); await models.Sale.updatePrice(ctx, saleId, price, options); const updatedSale = await models.Sale.findById(saleId, null, options); - createdSaleComponent = await models.SaleComponent.findOne({where: {saleFk: saleId, componentFk: manaComponent.id}}, options); + const createdSaleComponent = await models.SaleComponent.findOne({ + where: { + saleFk: saleId, componentFk: manaComponent.id + }}, options); expect(updatedSale.price).toBe(price); expect(createdSaleComponent.value).toEqual(-2.04); diff --git a/modules/ticket/back/methods/sale/updatePrice.js b/modules/ticket/back/methods/sale/updatePrice.js index bbd9d154d..dbd4ed091 100644 --- a/modules/ticket/back/methods/sale/updatePrice.js +++ b/modules/ticket/back/methods/sale/updatePrice.js @@ -77,7 +77,12 @@ module.exports = Self => { const oldPrice = sale.price; const userId = ctx.req.accessToken.userId; - const usesMana = await models.WorkerMana.findOne({where: {workerFk: userId}, fields: 'amount'}, myOptions); + + const salesDepartment = await models.Department.findOne({where: {code: 'VT'}, fields: 'id'}, myOptions); + const departments = await models.Department.getLeaves(salesDepartment.id, null, myOptions); + const workerDepartment = await models.WorkerDepartment.findById(userId); + const usesMana = departments.find(department => department.id == workerDepartment.departmentFk); + const componentCode = usesMana ? 'mana' : 'buyerDiscount'; const discount = await models.Component.findOne({where: {code: componentCode}}, myOptions); const componentId = discount.id; @@ -88,7 +93,6 @@ module.exports = Self => { saleFk: id }; const saleComponent = await models.SaleComponent.findOne({where}, myOptions); - if (saleComponent) { await models.SaleComponent.updateAll(where, { value: saleComponent.value + componentValue From 6891190c72e019cb8c2c2232a028e27a47a1ea56 Mon Sep 17 00:00:00 2001 From: vicent Date: Thu, 20 Oct 2022 15:05:46 +0200 Subject: [PATCH 33/55] refactor: create endpoint to unify code --- db/changes/10491-august/00-aclUsesMana.sql | 3 ++ .../ticket/back/methods/sale/updatePrice.js | 10 +++--- modules/ticket/back/methods/sale/usesMana.js | 31 +++++++++++++++++++ modules/ticket/back/models/sale.js | 1 + 4 files changed, 41 insertions(+), 4 deletions(-) create mode 100644 db/changes/10491-august/00-aclUsesMana.sql create mode 100644 modules/ticket/back/methods/sale/usesMana.js diff --git a/db/changes/10491-august/00-aclUsesMana.sql b/db/changes/10491-august/00-aclUsesMana.sql new file mode 100644 index 000000000..5bb7178dd --- /dev/null +++ b/db/changes/10491-august/00-aclUsesMana.sql @@ -0,0 +1,3 @@ +INSERT INTO `salix`.`ACL` (`model`, `property`, `accessType`, `permission`, `principalType`, `principalId`) + VALUES + ('Sale', 'usesMana', '*', 'ALLOW', 'ROLE', 'employee'); \ No newline at end of file diff --git a/modules/ticket/back/methods/sale/updatePrice.js b/modules/ticket/back/methods/sale/updatePrice.js index dbd4ed091..d325d6eaa 100644 --- a/modules/ticket/back/methods/sale/updatePrice.js +++ b/modules/ticket/back/methods/sale/updatePrice.js @@ -78,11 +78,13 @@ module.exports = Self => { const oldPrice = sale.price; const userId = ctx.req.accessToken.userId; - const salesDepartment = await models.Department.findOne({where: {code: 'VT'}, fields: 'id'}, myOptions); - const departments = await models.Department.getLeaves(salesDepartment.id, null, myOptions); - const workerDepartment = await models.WorkerDepartment.findById(userId); - const usesMana = departments.find(department => department.id == workerDepartment.departmentFk); + // const salesDepartment = await models.Department.findOne({where: {code: 'VT'}, fields: 'id'}, myOptions); + // const departments = await models.Department.getLeaves(salesDepartment.id, null, myOptions); + // const workerDepartment = await models.WorkerDepartment.findById(userId); + // const usesMana = departments.find(department => department.id == workerDepartment.departmentFk); + const usesMana = await models.Sale.usesMana(); + console.log(usesMana ? 'mana' : 'buyerDiscount'); const componentCode = usesMana ? 'mana' : 'buyerDiscount'; const discount = await models.Component.findOne({where: {code: componentCode}}, myOptions); const componentId = discount.id; diff --git a/modules/ticket/back/methods/sale/usesMana.js b/modules/ticket/back/methods/sale/usesMana.js new file mode 100644 index 000000000..7ff2a5e2a --- /dev/null +++ b/modules/ticket/back/methods/sale/usesMana.js @@ -0,0 +1,31 @@ +module.exports = Self => { + Self.remoteMethodCtx('usesMana', { + description: 'Returns if the worker uses mana', + accessType: 'WRITE', + accepts: [], + returns: { + type: 'boolean', + root: true + }, + http: { + path: `/usesMana`, + verb: 'POST' + } + }); + + Self.usesMana = async(ctx, options) => { + const models = Self.app.models; + const userId = ctx.req.accessToken.userId; + const myOptions = {}; + + if (typeof options == 'object') + Object.assign(myOptions, options); + + const salesDepartment = await models.Department.findOne({where: {code: 'VT'}, fields: 'id'}, myOptions); + const departments = await models.Department.getLeaves(salesDepartment.id, null, myOptions); + const workerDepartment = await models.WorkerDepartment.findById(userId); + const usesMana = departments.find(department => department.id == workerDepartment.departmentFk); + + return usesMana ? true : false; + }; +}; diff --git a/modules/ticket/back/models/sale.js b/modules/ticket/back/models/sale.js index 2a4457263..ae247fc24 100644 --- a/modules/ticket/back/models/sale.js +++ b/modules/ticket/back/models/sale.js @@ -8,6 +8,7 @@ module.exports = Self => { require('../methods/sale/recalculatePrice')(Self); require('../methods/sale/refund')(Self); require('../methods/sale/canEdit')(Self); + require('../methods/sale/usesMana')(Self); Self.validatesPresenceOf('concept', { message: `Concept cannot be blank` From 5da29fe38158e71d3d8fab36fd2fb9deab0bf137 Mon Sep 17 00:00:00 2001 From: vicent Date: Fri, 21 Oct 2022 08:00:24 +0200 Subject: [PATCH 34/55] refactor: unify duplicated code --- modules/ticket/back/methods/sale/updatePrice.js | 8 +------- modules/ticket/back/methods/sale/usesMana.js | 6 +++--- modules/ticket/back/methods/ticket/updateDiscount.js | 7 +------ 3 files changed, 5 insertions(+), 16 deletions(-) diff --git a/modules/ticket/back/methods/sale/updatePrice.js b/modules/ticket/back/methods/sale/updatePrice.js index d325d6eaa..302522cfb 100644 --- a/modules/ticket/back/methods/sale/updatePrice.js +++ b/modules/ticket/back/methods/sale/updatePrice.js @@ -78,13 +78,7 @@ module.exports = Self => { const oldPrice = sale.price; const userId = ctx.req.accessToken.userId; - // const salesDepartment = await models.Department.findOne({where: {code: 'VT'}, fields: 'id'}, myOptions); - // const departments = await models.Department.getLeaves(salesDepartment.id, null, myOptions); - // const workerDepartment = await models.WorkerDepartment.findById(userId); - // const usesMana = departments.find(department => department.id == workerDepartment.departmentFk); - - const usesMana = await models.Sale.usesMana(); - console.log(usesMana ? 'mana' : 'buyerDiscount'); + const usesMana = await models.Sale.usesMana(ctx, myOptions); const componentCode = usesMana ? 'mana' : 'buyerDiscount'; const discount = await models.Component.findOne({where: {code: componentCode}}, myOptions); const componentId = discount.id; diff --git a/modules/ticket/back/methods/sale/usesMana.js b/modules/ticket/back/methods/sale/usesMana.js index 7ff2a5e2a..093057dca 100644 --- a/modules/ticket/back/methods/sale/usesMana.js +++ b/modules/ticket/back/methods/sale/usesMana.js @@ -1,7 +1,7 @@ module.exports = Self => { Self.remoteMethodCtx('usesMana', { description: 'Returns if the worker uses mana', - accessType: 'WRITE', + accessType: 'READ', accepts: [], returns: { type: 'boolean', @@ -9,7 +9,7 @@ module.exports = Self => { }, http: { path: `/usesMana`, - verb: 'POST' + verb: 'GET' } }); @@ -23,7 +23,7 @@ module.exports = Self => { const salesDepartment = await models.Department.findOne({where: {code: 'VT'}, fields: 'id'}, myOptions); const departments = await models.Department.getLeaves(salesDepartment.id, null, myOptions); - const workerDepartment = await models.WorkerDepartment.findById(userId); + const workerDepartment = await models.WorkerDepartment.findById(userId, null, myOptions); const usesMana = departments.find(department => department.id == workerDepartment.departmentFk); return usesMana ? true : false; diff --git a/modules/ticket/back/methods/ticket/updateDiscount.js b/modules/ticket/back/methods/ticket/updateDiscount.js index b1291a45b..9419b9a40 100644 --- a/modules/ticket/back/methods/ticket/updateDiscount.js +++ b/modules/ticket/back/methods/ticket/updateDiscount.js @@ -98,12 +98,7 @@ module.exports = Self => { if (isLocked || (!hasAllowedRoles && alertLevel > 0)) throw new UserError(`The sales of this ticket can't be modified`); - const usesMana = await models.WorkerMana.findOne({ - where: { - workerFk: userId - }, - fields: 'amount'}, myOptions); - + const usesMana = await models.Sale.usesMana(ctx); const componentCode = usesMana ? manaCode : 'buyerDiscount'; const discountComponent = await models.Component.findOne({ where: {code: componentCode}}, myOptions); From 6f31bea21f50306ef47133afeacb447b2fb709a0 Mon Sep 17 00:00:00 2001 From: vicent Date: Fri, 21 Oct 2022 08:00:48 +0200 Subject: [PATCH 35/55] feat: update testBack --- db/changes/10491-august/00-aclBusiness.sql | 3 ++ modules/client/back/model-config.json | 3 ++ modules/client/back/models/business.json | 27 +++++++++++ .../methods/sale/specs/updatePrice.spec.js | 11 ++--- .../back/methods/sale/specs/usesMana.spec.js | 48 +++++++++++++++++++ 5 files changed, 86 insertions(+), 6 deletions(-) create mode 100644 db/changes/10491-august/00-aclBusiness.sql create mode 100644 modules/client/back/models/business.json create mode 100644 modules/ticket/back/methods/sale/specs/usesMana.spec.js diff --git a/db/changes/10491-august/00-aclBusiness.sql b/db/changes/10491-august/00-aclBusiness.sql new file mode 100644 index 000000000..f1f7a3632 --- /dev/null +++ b/db/changes/10491-august/00-aclBusiness.sql @@ -0,0 +1,3 @@ +INSERT INTO `salix`.`ACL` (`model`, `property`, `accessType`, `permission`, `principalType`, `principalId`) + VALUES + ('Business', '*', '*', 'ALLOW', 'ROLE', 'employee'); \ No newline at end of file diff --git a/modules/client/back/model-config.json b/modules/client/back/model-config.json index b2e600610..4ef34ca3a 100644 --- a/modules/client/back/model-config.json +++ b/modules/client/back/model-config.json @@ -8,6 +8,9 @@ "BankEntity": { "dataSource": "vn" }, + "Business": { + "dataSource": "vn" + }, "BusinessType": { "dataSource": "vn" }, diff --git a/modules/client/back/models/business.json b/modules/client/back/models/business.json new file mode 100644 index 000000000..7ad2d307f --- /dev/null +++ b/modules/client/back/models/business.json @@ -0,0 +1,27 @@ +{ + "name": "Business", + "base": "VnModel", + "options": { + "mysql": { + "table": "business" + } + }, + "properties": { + "id": { + "type": "number", + "id": true + } + }, + "relations": { + "worker": { + "type": "belongsTo", + "model": "Worker", + "foreignKey": "workerFk" + }, + "department": { + "type": "belongsTo", + "model": "Department", + "foreignKey": "departmentFk" + } + } +} \ No newline at end of file diff --git a/modules/ticket/back/methods/sale/specs/updatePrice.spec.js b/modules/ticket/back/methods/sale/specs/updatePrice.spec.js index 75be665fb..f8cb5a4ec 100644 --- a/modules/ticket/back/methods/sale/specs/updatePrice.spec.js +++ b/modules/ticket/back/methods/sale/specs/updatePrice.spec.js @@ -1,6 +1,6 @@ const models = require('vn-loopback/server/server').models; -describe('sale updatePrice()', () => { +fdescribe('sale updatePrice()', () => { const ctx = { req: { accessToken: {userId: 18}, @@ -80,11 +80,10 @@ describe('sale updatePrice()', () => { const originalSalesPersonMana = await models.WorkerMana.findById(18, null, options); const manaComponent = await models.Component.findOne({where: {code: 'mana'}}, options); const teamCLopez = 96; - const userId = 18; - await models.Sale.rawSql(`UPDATE vn.business b - JOIN vn.department d ON d.id = b.departmentFk - SET b.departmentFk = ? - WHERE b.id = ?`, [teamCLopez, userId]); + const userId = ctx.req.accessToken.userId; + + const business = await models.Business.findOne({where: {workerFk: userId}}, options); + await business.updateAttribute('departmentFk', teamCLopez, options); await models.Sale.updatePrice(ctx, saleId, price, options); const updatedSale = await models.Sale.findById(saleId, null, options); diff --git a/modules/ticket/back/methods/sale/specs/usesMana.spec.js b/modules/ticket/back/methods/sale/specs/usesMana.spec.js new file mode 100644 index 000000000..4e14ed2c9 --- /dev/null +++ b/modules/ticket/back/methods/sale/specs/usesMana.spec.js @@ -0,0 +1,48 @@ +const models = require('vn-loopback/server/server').models; + +describe('sale usesMana()', () => { + const ctx = { + req: { + accessToken: {userId: 18} + } + }; + + it('should return that the worker uses mana', async() => { + const tx = await models.Sale.beginTransaction({}); + + try { + const options = {transaction: tx}; + const teamCLopez = 96; + const userId = ctx.req.accessToken.userId; + + const business = await models.Business.findOne({where: {workerFk: userId}}, options); + await business.updateAttribute('departmentFk', teamCLopez, options); + + const usesMana = await models.Sale.usesMana(ctx, options); + + expect(usesMana).toBe(true); + + await tx.rollback(); + } catch (e) { + await tx.rollback(); + throw e; + } + }); + + it('should return that the worker not uses mana', async() => { + const tx = await models.Sale.beginTransaction({}); + + try { + const options = {transaction: tx}; + + const usesMana = await models.Sale.usesMana(ctx, options); + + expect(usesMana).toBe(false); + + await tx.rollback(); + } catch (e) { + await tx.rollback(); + throw e; + } + }); +}); From e7261573d7954cd9ce129efc0dd945e1114febfe Mon Sep 17 00:00:00 2001 From: vicent Date: Fri, 21 Oct 2022 08:01:22 +0200 Subject: [PATCH 36/55] delete focus --- modules/ticket/back/methods/sale/specs/updatePrice.spec.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/ticket/back/methods/sale/specs/updatePrice.spec.js b/modules/ticket/back/methods/sale/specs/updatePrice.spec.js index f8cb5a4ec..15b00a732 100644 --- a/modules/ticket/back/methods/sale/specs/updatePrice.spec.js +++ b/modules/ticket/back/methods/sale/specs/updatePrice.spec.js @@ -1,6 +1,6 @@ const models = require('vn-loopback/server/server').models; -fdescribe('sale updatePrice()', () => { +describe('sale updatePrice()', () => { const ctx = { req: { accessToken: {userId: 18}, From 2d0cb60b50825144113edde29f97f084240002ac Mon Sep 17 00:00:00 2001 From: vicent Date: Fri, 21 Oct 2022 08:55:05 +0200 Subject: [PATCH 37/55] feat: check if uses mana --- modules/ticket/front/sale/index.html | 14 ++++++++++++-- modules/ticket/front/sale/index.js | 8 ++++++++ 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/modules/ticket/front/sale/index.html b/modules/ticket/front/sale/index.html index 42eb10cb0..35e45a812 100644 --- a/modules/ticket/front/sale/index.html +++ b/modules/ticket/front/sale/index.html @@ -264,6 +264,16 @@
+ + + + + + @@ -278,7 +288,7 @@
-
Mana: {{::$ctrl.edit.mana | currency: 'EUR':0}}
+
MANÁ: {{::$ctrl.edit.mana | currency: 'EUR': 0}}
- + { + this.useMana = res.data; + }); + } + /** * Returns checked instances * From c33cab7b10b94be095f0b96e4c2860e68e3fcf36 Mon Sep 17 00:00:00 2001 From: vicent Date: Fri, 21 Oct 2022 09:01:08 +0200 Subject: [PATCH 38/55] fix: test back --- .../back/methods/ticket/specs/updateDiscount.spec.js | 10 ++++++++++ modules/ticket/back/methods/ticket/updateDiscount.js | 2 +- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/modules/ticket/back/methods/ticket/specs/updateDiscount.spec.js b/modules/ticket/back/methods/ticket/specs/updateDiscount.spec.js index 1873207aa..5249fe5d8 100644 --- a/modules/ticket/back/methods/ticket/specs/updateDiscount.spec.js +++ b/modules/ticket/back/methods/ticket/specs/updateDiscount.spec.js @@ -110,6 +110,11 @@ describe('sale updateDiscount()', () => { const componentId = manaDiscount.id; const manaCode = 'mana'; + const teamCLopez = 96; + const userId = ctx.req.accessToken.userId; + const business = await models.Business.findOne({where: {workerFk: userId}}, options); + await business.updateAttribute('departmentFk', teamCLopez, options); + await models.Ticket.updateDiscount(ctx, ticketId, sales, newDiscount, manaCode, options); const updatedSale = await models.Sale.findById(originalSaleId, null, options); @@ -150,6 +155,11 @@ describe('sale updateDiscount()', () => { const componentId = manaDiscount.id; const manaCode = 'manaClaim'; + const teamCLopez = 96; + const userId = ctx.req.accessToken.userId; + const business = await models.Business.findOne({where: {workerFk: userId}}, options); + await business.updateAttribute('departmentFk', teamCLopez, options); + await models.Ticket.updateDiscount(ctx, ticketId, sales, newDiscount, manaCode, options); const updatedSale = await models.Sale.findById(originalSaleId, null, options); diff --git a/modules/ticket/back/methods/ticket/updateDiscount.js b/modules/ticket/back/methods/ticket/updateDiscount.js index 9419b9a40..8bc79ca9c 100644 --- a/modules/ticket/back/methods/ticket/updateDiscount.js +++ b/modules/ticket/back/methods/ticket/updateDiscount.js @@ -98,7 +98,7 @@ module.exports = Self => { if (isLocked || (!hasAllowedRoles && alertLevel > 0)) throw new UserError(`The sales of this ticket can't be modified`); - const usesMana = await models.Sale.usesMana(ctx); + const usesMana = await models.Sale.usesMana(ctx, myOptions); const componentCode = usesMana ? manaCode : 'buyerDiscount'; const discountComponent = await models.Component.findOne({ where: {code: componentCode}}, myOptions); From f968b19d1e2603036050fbc2b5b17680f5b05d13 Mon Sep 17 00:00:00 2001 From: vicent Date: Fri, 21 Oct 2022 09:08:17 +0200 Subject: [PATCH 39/55] fix: testFront --- modules/ticket/front/sale/index.spec.js | 1 + 1 file changed, 1 insertion(+) diff --git a/modules/ticket/front/sale/index.spec.js b/modules/ticket/front/sale/index.spec.js index 28d874932..a7260a3ec 100644 --- a/modules/ticket/front/sale/index.spec.js +++ b/modules/ticket/front/sale/index.spec.js @@ -115,6 +115,7 @@ describe('Ticket', () => { const expectedAmount = 250; $httpBackend.expect('GET', 'Tickets/1/getSalesPersonMana').respond(200, expectedAmount); + $httpBackend.expect('GET', 'Sales/usesMana').respond(200); $httpBackend.expect('GET', 'WorkerManas/getCurrentWorkerMana').respond(200, expectedAmount); controller.getMana(); $httpBackend.flush(); From 18c119c62a88a0e1959d1af2e00d22f9a91e37b1 Mon Sep 17 00:00:00 2001 From: vicent Date: Fri, 21 Oct 2022 09:20:27 +0200 Subject: [PATCH 40/55] change acl --- db/changes/10491-august/00-aclBusiness.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/db/changes/10491-august/00-aclBusiness.sql b/db/changes/10491-august/00-aclBusiness.sql index f1f7a3632..8ea2c6d83 100644 --- a/db/changes/10491-august/00-aclBusiness.sql +++ b/db/changes/10491-august/00-aclBusiness.sql @@ -1,3 +1,3 @@ INSERT INTO `salix`.`ACL` (`model`, `property`, `accessType`, `permission`, `principalType`, `principalId`) VALUES - ('Business', '*', '*', 'ALLOW', 'ROLE', 'employee'); \ No newline at end of file + ('Business', '*', '*', 'ALLOW', 'ROLE', 'hr'); \ No newline at end of file From 8a3573474a99de0a60a330ab00c0fd106273c406 Mon Sep 17 00:00:00 2001 From: vicent Date: Tue, 25 Oct 2022 07:40:32 +0200 Subject: [PATCH 41/55] refactor: move 'lastEntries' to thrid position in descriptor --- modules/item/front/routes.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/item/front/routes.json b/modules/item/front/routes.json index 52cf5d2be..3dea69ba1 100644 --- a/modules/item/front/routes.json +++ b/modules/item/front/routes.json @@ -15,12 +15,12 @@ "card": [ {"state": "item.card.basicData", "icon": "settings"}, {"state": "item.card.tags", "icon": "icon-tags"}, + {"state": "item.card.last-entries", "icon": "icon-regentry"}, {"state": "item.card.tax", "icon": "icon-tax"}, {"state": "item.card.botanical", "icon": "local_florist"}, {"state": "item.card.shelving", "icon": "icon-inventory"}, {"state": "item.card.itemBarcode", "icon": "icon-barcode"}, {"state": "item.card.diary", "icon": "icon-transaction"}, - {"state": "item.card.last-entries", "icon": "icon-regentry"}, {"state": "item.card.log", "icon": "history"} ], "itemType": [ From 7f1dd801a55aff414fbaf06eacbbdb8bf25039ad Mon Sep 17 00:00:00 2001 From: vicent Date: Tue, 25 Oct 2022 07:56:17 +0200 Subject: [PATCH 42/55] refactor: change ACLs --- db/changes/10491-august/00-aclItemShelving.sql | 3 --- db/changes/10491-august/00-aclItemShelvingPlacementSupply.sql | 3 --- db/changes/10500-november/00-itemShelvingACL.sql | 4 ++++ .../10500-november/00-itemShelvingPlacementSupplyStockACL.sql | 4 ++++ 4 files changed, 8 insertions(+), 6 deletions(-) delete mode 100644 db/changes/10491-august/00-aclItemShelving.sql delete mode 100644 db/changes/10491-august/00-aclItemShelvingPlacementSupply.sql create mode 100644 db/changes/10500-november/00-itemShelvingACL.sql create mode 100644 db/changes/10500-november/00-itemShelvingPlacementSupplyStockACL.sql diff --git a/db/changes/10491-august/00-aclItemShelving.sql b/db/changes/10491-august/00-aclItemShelving.sql deleted file mode 100644 index 3995bbe49..000000000 --- a/db/changes/10491-august/00-aclItemShelving.sql +++ /dev/null @@ -1,3 +0,0 @@ -INSERT INTO `salix`.`ACL` (`model`, `property`, `accessType`, `permission`, `principalType`, `principalId`) - VALUES - ('ItemShelving', '*', '*', 'ALLOW', 'ROLE', 'employee'); \ No newline at end of file diff --git a/db/changes/10491-august/00-aclItemShelvingPlacementSupply.sql b/db/changes/10491-august/00-aclItemShelvingPlacementSupply.sql deleted file mode 100644 index cc589a58f..000000000 --- a/db/changes/10491-august/00-aclItemShelvingPlacementSupply.sql +++ /dev/null @@ -1,3 +0,0 @@ -INSERT INTO `salix`.`ACL` (`model`, `property`, `accessType`, `permission`, `principalType`, `principalId`) - VALUES - ('ItemShelvingPlacementSupplyStock', '*', '*', 'ALLOW', 'ROLE', 'employee'); \ No newline at end of file diff --git a/db/changes/10500-november/00-itemShelvingACL.sql b/db/changes/10500-november/00-itemShelvingACL.sql new file mode 100644 index 000000000..fc32fe1ed --- /dev/null +++ b/db/changes/10500-november/00-itemShelvingACL.sql @@ -0,0 +1,4 @@ +INSERT INTO `salix`.`ACL` (model, property, accessType, permission, principalType, principalId) +VALUES + ('ItemShelving', '*', 'READ', 'ALLOW', 'ROLE', 'employee'), + ('ItemShelving', '*', 'WRITE', 'ALLOW', 'ROLE', 'production'); \ No newline at end of file diff --git a/db/changes/10500-november/00-itemShelvingPlacementSupplyStockACL.sql b/db/changes/10500-november/00-itemShelvingPlacementSupplyStockACL.sql new file mode 100644 index 000000000..25eac8d51 --- /dev/null +++ b/db/changes/10500-november/00-itemShelvingPlacementSupplyStockACL.sql @@ -0,0 +1,4 @@ +INSERT INTO `salix`.`ACL` (model, property, accessType, permission, principalType, principalId) +VALUES + ('ItemShelvingPlacementSupplyStock', '*', 'READ', 'ALLOW', 'ROLE', 'employee'); + From 07a18dc736048fd3f6304daa80a9ef0fcf985e0c Mon Sep 17 00:00:00 2001 From: vicent Date: Wed, 26 Oct 2022 08:05:11 +0200 Subject: [PATCH 43/55] delete sql --- db/changes/10491-august/00-itemType.sql | 5 ----- 1 file changed, 5 deletions(-) delete mode 100644 db/changes/10491-august/00-itemType.sql diff --git a/db/changes/10491-august/00-itemType.sql b/db/changes/10491-august/00-itemType.sql deleted file mode 100644 index d201acf37..000000000 --- a/db/changes/10491-august/00-itemType.sql +++ /dev/null @@ -1,5 +0,0 @@ -ALTER TABLE `vn`.`itemType` CHANGE `transaction` transaction__ tinyint(4) DEFAULT 0 NOT NULL; -ALTER TABLE `vn`.`itemType` CHANGE location location__ varchar(10) CHARACTER SET utf8mb3 COLLATE utf8mb3_unicode_ci DEFAULT NULL NULL; -ALTER TABLE `vn`.`itemType` CHANGE hasComponents hasComponents__ tinyint(1) DEFAULT 1 NOT NULL; -ALTER TABLE `vn`.`itemType` CHANGE warehouseFk warehouseFk__ smallint(6) unsigned DEFAULT 60 NOT NULL; -ALTER TABLE `vn`.`itemType` CHANGE compression compression__ decimal(5,2) DEFAULT 1.00 NULL; \ No newline at end of file From 925565d3d24037bb53d209823db0b5cef12bc83c Mon Sep 17 00:00:00 2001 From: vicent Date: Wed, 26 Oct 2022 08:23:36 +0200 Subject: [PATCH 44/55] =?UTF-8?q?refator:=20borrada=20variable=20global=20?= =?UTF-8?q?y=20a=C3=B1adida=20Promesa=20al=20array?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- modules/ticket/back/methods/ticket/updateDiscount.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/modules/ticket/back/methods/ticket/updateDiscount.js b/modules/ticket/back/methods/ticket/updateDiscount.js index 7e7c4e06d..a60d732b1 100644 --- a/modules/ticket/back/methods/ticket/updateDiscount.js +++ b/modules/ticket/back/methods/ticket/updateDiscount.js @@ -133,20 +133,20 @@ module.exports = Self => { } }, myOptions); - let newComponent; + let deletedComponent; if (oldComponent) { const filter = { saleFk: sale.id, componentFk: oldComponent.componentFk }; - await models.SaleComponent.destroyAll(filter, myOptions); + deletedComponent = await models.SaleComponent.destroyAll(filter, myOptions); } - await createSaleComponent(sale.id, value, componentId, myOptions); + const newComponent = await createSaleComponent(sale.id, value, componentId, myOptions); const updatedSale = sale.updateAttribute('discount', newDiscount, myOptions); - promises.push(newComponent, updatedSale); + promises.push(newComponent, updatedSale, deletedComponent); const change = `${oldDiscount}% ➔ *${newDiscount}%*`; changesMade += `\r\n-${sale.itemFk}: ${sale.concept} (${sale.quantity}) ${change}`; @@ -193,7 +193,7 @@ module.exports = Self => { async function createSaleComponent(saleId, value, componentId, myOptions) { const models = Self.app.models; - newComponent = models.SaleComponent.create({ + return models.SaleComponent.create({ saleFk: saleId, value: value, componentFk: componentId From d4e278363009abaa45090212dc3e50a2f0430086 Mon Sep 17 00:00:00 2001 From: vicent Date: Wed, 26 Oct 2022 08:39:07 +0200 Subject: [PATCH 45/55] =?UTF-8?q?refactor:=20corregidas=20traducciones,=20?= =?UTF-8?q?eliminado=20destroyAll=20y=20a=C3=B1adida=20transacci=C3=B3n?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- loopback/locale/es.json | 2 +- .../back/methods/expedition/deleteExpeditions.js | 10 +++++++--- .../ticket/back/methods/expedition/moveExpeditions.js | 4 ++-- .../methods/expedition/specs/deleteExpeditions.spec.js | 2 +- modules/ticket/front/expedition/index.html | 2 +- modules/ticket/front/expedition/locale/es.yml | 2 +- 6 files changed, 13 insertions(+), 9 deletions(-) diff --git a/loopback/locale/es.json b/loopback/locale/es.json index bd9de41c2..2d9bae1d8 100644 --- a/loopback/locale/es.json +++ b/loopback/locale/es.json @@ -236,5 +236,5 @@ "Modifiable user details only by an administrator": "Detalles de usuario modificables solo por un administrador", "Modifiable password only via recovery or by an administrator": "Contraseña modificable solo a través de la recuperación o por un administrador", "Not enough privileges to edit a client": "No tienes suficientes privilegios para editar un cliente", - "This route not exists": "Esta ruta no existe" + "This route does not exists": "Esta ruta no existe" } \ No newline at end of file diff --git a/modules/ticket/back/methods/expedition/deleteExpeditions.js b/modules/ticket/back/methods/expedition/deleteExpeditions.js index 5b9d0daaa..2419d3a5e 100644 --- a/modules/ticket/back/methods/expedition/deleteExpeditions.js +++ b/modules/ticket/back/methods/expedition/deleteExpeditions.js @@ -33,9 +33,13 @@ module.exports = Self => { } try { - const deletedExpeditions = await models.Expedition.destroyAll({ - id: {inq: expeditionIds} - }, myOptions); + const promises = []; + for (let expeditionId of expeditionIds) { + const deletedExpedition = models.Expedition.destroyById(expeditionId, myOptions); + promises.push(deletedExpedition); + } + + const deletedExpeditions = await Promise.all(promises); if (tx) await tx.commit(); diff --git a/modules/ticket/back/methods/expedition/moveExpeditions.js b/modules/ticket/back/methods/expedition/moveExpeditions.js index d0f8aa893..cef35ab86 100644 --- a/modules/ticket/back/methods/expedition/moveExpeditions.js +++ b/modules/ticket/back/methods/expedition/moveExpeditions.js @@ -70,12 +70,12 @@ module.exports = Self => { try { if (args.routeId) { const route = await models.Route.findById(args.routeId, null, myOptions); - if (!route) throw new UserError('This route not exists'); + if (!route) throw new UserError('This route does not exists'); } const ticket = await models.Ticket.new(ctx, myOptions); const promises = []; for (let expeditionsId of args.expeditionIds) { - const expeditionToUpdate = await models.Expedition.findById(expeditionsId); + const expeditionToUpdate = await models.Expedition.findById(expeditionsId, null, myOptions); const expeditionUpdated = expeditionToUpdate.updateAttribute('ticketFk', ticket.id, myOptions); promises.push(expeditionUpdated); } diff --git a/modules/ticket/back/methods/expedition/specs/deleteExpeditions.spec.js b/modules/ticket/back/methods/expedition/specs/deleteExpeditions.spec.js index 0a47c78da..14bdf7aea 100644 --- a/modules/ticket/back/methods/expedition/specs/deleteExpeditions.spec.js +++ b/modules/ticket/back/methods/expedition/specs/deleteExpeditions.spec.js @@ -10,7 +10,7 @@ describe('ticket deleteExpeditions()', () => { const expeditionIds = [12, 13]; const result = await models.Expedition.deleteExpeditions(expeditionIds, options); - expect(result.count).toEqual(2); + expect(result.length).toEqual(2); await tx.rollback(); } catch (e) { diff --git a/modules/ticket/front/expedition/index.html b/modules/ticket/front/expedition/index.html index 0ebe388c1..ec6dc7ee2 100644 --- a/modules/ticket/front/expedition/index.html +++ b/modules/ticket/front/expedition/index.html @@ -159,7 +159,7 @@ diff --git a/modules/ticket/front/expedition/locale/es.yml b/modules/ticket/front/expedition/locale/es.yml index 68812f985..278dcc8f2 100644 --- a/modules/ticket/front/expedition/locale/es.yml +++ b/modules/ticket/front/expedition/locale/es.yml @@ -3,4 +3,4 @@ Expedition removed: Expedición eliminada Move: Mover New ticket without route: Nuevo ticket sin ruta New ticket with route: Nuevo ticket con ruta -Id route: Id ruta \ No newline at end of file +Route id: Id ruta \ No newline at end of file From d1e2b1f7d5ff9b98b8d62554e879c539937337dc Mon Sep 17 00:00:00 2001 From: vicent Date: Wed, 26 Oct 2022 09:02:54 +0200 Subject: [PATCH 46/55] refactor: tranducciones --- modules/ticket/front/sale/index.html | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/ticket/front/sale/index.html b/modules/ticket/front/sale/index.html index 35e45a812..c68138141 100644 --- a/modules/ticket/front/sale/index.html +++ b/modules/ticket/front/sale/index.html @@ -244,7 +244,7 @@
-
MANÁ: {{::$ctrl.edit.mana | currency: 'EUR': 0}}
+
Mana: {{::$ctrl.edit.mana | currency: 'EUR': 0}}
-
MANÁ: {{::$ctrl.edit.mana | currency: 'EUR': 0}}
+
Mana: {{::$ctrl.edit.mana | currency: 'EUR': 0}}
Date: Wed, 26 Oct 2022 09:04:53 +0200 Subject: [PATCH 47/55] refactor: renombrada variable --- .../ticket/back/methods/sale/specs/updatePrice.spec.js | 4 ++-- modules/ticket/back/methods/sale/specs/usesMana.spec.js | 4 ++-- .../back/methods/ticket/specs/updateDiscount.spec.js | 8 ++++---- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/modules/ticket/back/methods/sale/specs/updatePrice.spec.js b/modules/ticket/back/methods/sale/specs/updatePrice.spec.js index 15b00a732..51cd2403f 100644 --- a/modules/ticket/back/methods/sale/specs/updatePrice.spec.js +++ b/modules/ticket/back/methods/sale/specs/updatePrice.spec.js @@ -79,11 +79,11 @@ describe('sale updatePrice()', () => { const price = 5.4; const originalSalesPersonMana = await models.WorkerMana.findById(18, null, options); const manaComponent = await models.Component.findOne({where: {code: 'mana'}}, options); - const teamCLopez = 96; + const teamOne = 96; const userId = ctx.req.accessToken.userId; const business = await models.Business.findOne({where: {workerFk: userId}}, options); - await business.updateAttribute('departmentFk', teamCLopez, options); + await business.updateAttribute('departmentFk', teamOne, options); await models.Sale.updatePrice(ctx, saleId, price, options); const updatedSale = await models.Sale.findById(saleId, null, options); diff --git a/modules/ticket/back/methods/sale/specs/usesMana.spec.js b/modules/ticket/back/methods/sale/specs/usesMana.spec.js index 4e14ed2c9..777bdc8f0 100644 --- a/modules/ticket/back/methods/sale/specs/usesMana.spec.js +++ b/modules/ticket/back/methods/sale/specs/usesMana.spec.js @@ -12,11 +12,11 @@ describe('sale usesMana()', () => { try { const options = {transaction: tx}; - const teamCLopez = 96; + const teamOne = 96; const userId = ctx.req.accessToken.userId; const business = await models.Business.findOne({where: {workerFk: userId}}, options); - await business.updateAttribute('departmentFk', teamCLopez, options); + await business.updateAttribute('departmentFk', teamOne, options); const usesMana = await models.Sale.usesMana(ctx, options); diff --git a/modules/ticket/back/methods/ticket/specs/updateDiscount.spec.js b/modules/ticket/back/methods/ticket/specs/updateDiscount.spec.js index 5249fe5d8..1f6712087 100644 --- a/modules/ticket/back/methods/ticket/specs/updateDiscount.spec.js +++ b/modules/ticket/back/methods/ticket/specs/updateDiscount.spec.js @@ -110,10 +110,10 @@ describe('sale updateDiscount()', () => { const componentId = manaDiscount.id; const manaCode = 'mana'; - const teamCLopez = 96; + const teamOne = 96; const userId = ctx.req.accessToken.userId; const business = await models.Business.findOne({where: {workerFk: userId}}, options); - await business.updateAttribute('departmentFk', teamCLopez, options); + await business.updateAttribute('departmentFk', teamOne, options); await models.Ticket.updateDiscount(ctx, ticketId, sales, newDiscount, manaCode, options); @@ -155,10 +155,10 @@ describe('sale updateDiscount()', () => { const componentId = manaDiscount.id; const manaCode = 'manaClaim'; - const teamCLopez = 96; + const teamOne = 96; const userId = ctx.req.accessToken.userId; const business = await models.Business.findOne({where: {workerFk: userId}}, options); - await business.updateAttribute('departmentFk', teamCLopez, options); + await business.updateAttribute('departmentFk', teamOne, options); await models.Ticket.updateDiscount(ctx, ticketId, sales, newDiscount, manaCode, options); From 21e2945d4f6b59df9b239fd197b8845dbda7f8ef Mon Sep 17 00:00:00 2001 From: vicent Date: Wed, 26 Oct 2022 09:30:17 +0200 Subject: [PATCH 48/55] refactor: delete destroyAll --- .../methods/item-shelving/deleteItemShelvings.js | 12 ++++++++---- .../item-shelving/specs/deleteItemShelvings.spec.js | 2 +- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/modules/item/back/methods/item-shelving/deleteItemShelvings.js b/modules/item/back/methods/item-shelving/deleteItemShelvings.js index 0b58970d8..f534b4e9a 100644 --- a/modules/item/back/methods/item-shelving/deleteItemShelvings.js +++ b/modules/item/back/methods/item-shelving/deleteItemShelvings.js @@ -1,6 +1,6 @@ module.exports = Self => { Self.remoteMethod('deleteItemShelvings', { - description: 'Deletes the selected orders', + description: 'Deletes the selected item shelvings', accessType: 'WRITE', accepts: [{ arg: 'itemShelvingIds', @@ -32,9 +32,13 @@ module.exports = Self => { } try { - const deletedItemShelvings = await models.ItemShelving.destroyAll({ - id: {inq: itemShelvingIds} - }, myOptions); + const promises = []; + for (let itemShelvingId of itemShelvingIds) { + const itemShelvingToDelete = models.ItemShelving.destroyById(itemShelvingId, myOptions); + promises.push(itemShelvingToDelete); + } + + const deletedItemShelvings = await Promise.all(promises); if (tx) await tx.commit(); diff --git a/modules/item/back/methods/item-shelving/specs/deleteItemShelvings.spec.js b/modules/item/back/methods/item-shelving/specs/deleteItemShelvings.spec.js index a152b5981..b4113d7cf 100644 --- a/modules/item/back/methods/item-shelving/specs/deleteItemShelvings.spec.js +++ b/modules/item/back/methods/item-shelving/specs/deleteItemShelvings.spec.js @@ -10,7 +10,7 @@ describe('ItemShelving deleteItemShelvings()', () => { const itemShelvingIds = [1, 2]; const result = await models.ItemShelving.deleteItemShelvings(itemShelvingIds, options); - expect(result.count).toEqual(2); + expect(result.length).toEqual(2); await tx.rollback(); } catch (e) { From 65e32f5e7fc1b0c3b1ff0d9a7fa5564d12f0e84b Mon Sep 17 00:00:00 2001 From: vicent Date: Wed, 26 Oct 2022 12:40:13 +0200 Subject: [PATCH 49/55] feat: client search panel add find by zone --- .../10500-november/00-zone_getPostalCode.sql | 56 ++++++ modules/client/back/methods/client/filter.js | 174 ++++++++++++++++++ modules/client/back/models/client-methods.js | 1 + modules/client/front/main/index.html | 5 +- modules/client/front/main/index.js | 26 --- modules/client/front/search-panel/index.html | 7 + 6 files changed, 240 insertions(+), 29 deletions(-) create mode 100644 db/changes/10500-november/00-zone_getPostalCode.sql create mode 100644 modules/client/back/methods/client/filter.js diff --git a/db/changes/10500-november/00-zone_getPostalCode.sql b/db/changes/10500-november/00-zone_getPostalCode.sql new file mode 100644 index 000000000..b71306a58 --- /dev/null +++ b/db/changes/10500-november/00-zone_getPostalCode.sql @@ -0,0 +1,56 @@ +DROP PROCEDURE IF EXISTS `vn`.`zone_getPostalCode`; + +DELIMITER $$ +$$ +CREATE DEFINER=`root`@`localhost` PROCEDURE `vn`.`zone_getPostalCode`(vSelf INT) +BEGIN +/** + * Devuelve los códigos postales incluidos en una zona + * + * @return vNewTicket + */ + DECLARE vGeoFk INT DEFAULT NULL; + + DROP TEMPORARY TABLE IF EXISTS tmp.zoneNodes; + CREATE TEMPORARY TABLE tmp.zoneNodes ( + geoFk INT, + name VARCHAR(100), + parentFk INT, + sons INT, + isChecked BOOL DEFAULT 0, + zoneFk INT, + PRIMARY KEY zoneNodesPk (zoneFk, geoFk), + INDEX(geoFk)) + ENGINE = MEMORY; + + CALL zone_getLeaves2(vSelf, NULL , NULL); + + UPDATE tmp.zoneNodes zn + SET isChecked = 0 + WHERE parentFk IS NULL; + + myLoop: LOOP + SET vGeoFk = NULL; + SELECT geoFk INTO vGeoFk + FROM tmp.zoneNodes zn + WHERE NOT isChecked + LIMIT 1; + + CALL zone_getLeaves2(vSelf, vGeoFk, NULL); + UPDATE tmp.zoneNodes + SET isChecked = TRUE + WHERE geoFk = vGeoFk; + + IF vGeoFk IS NULL THEN + LEAVE myLoop; + END IF; + END LOOP; + + DELETE FROM tmp.zoneNodes + WHERE sons > 0; + + SELECT zn.geoFk, zn.name + FROM tmp.zoneNodes zn + JOIN zone z ON z.id = zn.zoneFk; +END$$ +DELIMITER ; diff --git a/modules/client/back/methods/client/filter.js b/modules/client/back/methods/client/filter.js new file mode 100644 index 000000000..0e9eaf160 --- /dev/null +++ b/modules/client/back/methods/client/filter.js @@ -0,0 +1,174 @@ + +const ParameterizedSQL = require('loopback-connector').ParameterizedSQL; +const buildFilter = require('vn-loopback/util/filter').buildFilter; +const mergeFilters = require('vn-loopback/util/filter').mergeFilters; + +module.exports = Self => { + Self.remoteMethodCtx('filter', { + description: 'Find all clients matched by the filter', + accessType: 'READ', + accepts: [ + { + arg: 'filter', + type: 'object', + }, + { + arg: 'search', + type: 'string', + description: `If it's and integer searchs by id, otherwise it searchs by name`, + }, + { + arg: 'name', + type: 'string', + description: 'The client name', + }, + { + arg: 'salesPersonFk', + type: 'number', + }, + { + arg: 'fi', + type: 'string', + description: 'The client fiscal id', + }, + { + arg: 'socialName', + type: 'string', + }, + { + arg: 'city', + type: 'string', + }, + { + arg: 'postcode', + type: 'string', + }, + { + arg: 'provinceFk', + type: 'number', + }, + { + arg: 'email', + type: 'string', + }, + { + arg: 'phone', + type: 'string', + }, + { + arg: 'zoneFk', + type: 'number', + }, + ], + returns: { + type: ['object'], + root: true + }, + http: { + path: `/filter`, + verb: 'GET' + } + }); + + Self.filter = async(ctx, filter, options) => { + const conn = Self.dataSource.connector; + const myOptions = {}; + const postalCode = []; + const args = ctx.args; + if (typeof options == 'object') + Object.assign(myOptions, options); + if (args.zoneFk) { + query = `CALL vn.zone_getPostalCode(?)`; + const [geos] = await Self.rawSql(query, [args.zoneFk]); + for (let geo of geos) + postalCode.push(geo.name); + } + + const where = buildFilter(ctx.args, (param, value) => { + switch (param) { + case 'search': + return /^\d+$/.test(value) + ? {'c.id': {inq: value}} + : {'c.name': {like: `%${value}%`}}; + case 'name': + case 'salesPersonFk': + case 'fi': + case 'socialName': + case 'city': + case 'postcode': + case 'provinceFk': + case 'email': + case 'phone': + param = `c.${param}`; + return {[param]: value}; + case 'zoneFk': + param = 'a.postalCode'; + return {[param]: {inq: postalCode}}; + } + }); + + filter = mergeFilters(filter, {where}); + + const stmts = []; + const stmt = new ParameterizedSQL( + `SELECT + c.id, + c.name, + c.socialName, + c.fi, + c.credit, + c.creditInsurance, + c.phone, + c.mobile, + c.street, + c.city, + c.postcode, + c.email, + c.created, + c.isActive, + c.isVies, + c.isTaxDataChecked, + c.isEqualizated, + c.isFreezed, + c.hasToInvoice, + c.hasToInvoiceByAddress, + c.isToBeMailed, + c.hasSepaVnl, + c.hasLcr, + c.hasCoreVnl, + ct.id AS countryFk, + ct.country, + p.id AS provinceFk, + p.name AS province, + u.id AS salesPersonFk, + u.name AS salesPerson, + bt.code AS businessTypeFk, + bt.description AS businessType, + pm.id AS payMethodFk, + pm.name AS payMethod, + sti.CodigoIva AS sageTaxTypeFk, + sti.Iva AS sageTaxType, + stt.CodigoTransaccion AS sageTransactionTypeFk, + stt.Transaccion AS sageTransactionType + FROM client c + LEFT JOIN account.user u ON u.id = c.salesPersonFk + LEFT JOIN country ct ON ct.id = c.countryFk + LEFT JOIN province p ON p.id = c.provinceFk + LEFT JOIN businessType bt ON bt.code = c.businessTypeFk + LEFT JOIN payMethod pm ON pm.id = c.payMethodFk + LEFT JOIN sage.TiposIva sti ON sti.CodigoIva = c.taxTypeSageFk + LEFT JOIN sage.TiposTransacciones stt ON stt.CodigoTransaccion = c.transactionTypeSageFk + LEFT JOIN vn.address a ON a.id = c.defaultAddressFk + ` + ); + + stmt.merge(conn.makeWhere(filter.where)); + stmt.merge(conn.makePagination(filter)); + + const clientsIndex = stmts.push(stmt) - 1; + const sql = ParameterizedSQL.join(stmts, ';'); + const result = await conn.executeStmt(sql, myOptions); + + return clientsIndex === 0 ? result : result[clientsIndex]; + }; +}; diff --git a/modules/client/back/models/client-methods.js b/modules/client/back/models/client-methods.js index 04d10413a..5134e3942 100644 --- a/modules/client/back/models/client-methods.js +++ b/modules/client/back/models/client-methods.js @@ -47,4 +47,5 @@ module.exports = Self => { require('../methods/client/incotermsAuthorizationHtml')(Self); require('../methods/client/incotermsAuthorizationEmail')(Self); require('../methods/client/consumptionSendQueued')(Self); + require('../methods/client/filter')(Self); }; diff --git a/modules/client/front/main/index.html b/modules/client/front/main/index.html index e8bc4b988..0787858ae 100644 --- a/modules/client/front/main/index.html +++ b/modules/client/front/main/index.html @@ -1,6 +1,6 @@ @@ -10,8 +10,7 @@ vn-focus panel="vn-client-search-panel" info="Search client by id or name" - model="model" - expr-builder="$ctrl.exprBuilder(param, value)"> + model="model"> diff --git a/modules/client/front/main/index.js b/modules/client/front/main/index.js index 1069d3487..346880f4c 100644 --- a/modules/client/front/main/index.js +++ b/modules/client/front/main/index.js @@ -2,32 +2,6 @@ import ngModule from '../module'; import ModuleMain from 'salix/components/module-main'; export default class Client extends ModuleMain { - exprBuilder(param, value) { - switch (param) { - case 'search': - return /^\d+$/.test(value) - ? {id: value} - : {or: [{name: {like: `%${value}%`}}, {socialName: {like: `%${value}%`}}]}; - case 'phone': - return { - or: [ - {phone: value}, - {mobile: value} - ] - }; - case 'name': - case 'socialName': - case 'city': - case 'email': - return {[param]: {like: `%${value}%`}}; - case 'id': - case 'fi': - case 'postcode': - case 'provinceFk': - case 'salesPersonFk': - return {[param]: value}; - } - } } ngModule.vnComponent('vnClient', { diff --git a/modules/client/front/search-panel/index.html b/modules/client/front/search-panel/index.html index 234cb6f53..a02f93882 100644 --- a/modules/client/front/search-panel/index.html +++ b/modules/client/front/search-panel/index.html @@ -58,6 +58,13 @@ value-field="id" label="Province"> + + Date: Wed, 26 Oct 2022 13:10:17 +0200 Subject: [PATCH 50/55] =?UTF-8?q?refactor:=20a=C3=B1adido=20salto=20de=20l?= =?UTF-8?q?ineas?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- modules/client/back/methods/client/filter.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/modules/client/back/methods/client/filter.js b/modules/client/back/methods/client/filter.js index 0e9eaf160..7cf4ba2ea 100644 --- a/modules/client/back/methods/client/filter.js +++ b/modules/client/back/methods/client/filter.js @@ -75,8 +75,10 @@ module.exports = Self => { const myOptions = {}; const postalCode = []; const args = ctx.args; + if (typeof options == 'object') Object.assign(myOptions, options); + if (args.zoneFk) { query = `CALL vn.zone_getPostalCode(?)`; const [geos] = await Self.rawSql(query, [args.zoneFk]); From fa89d1f944d724e11b8b93d4cdf389a8405a5531 Mon Sep 17 00:00:00 2001 From: vicent Date: Wed, 26 Oct 2022 13:10:50 +0200 Subject: [PATCH 51/55] fix: comentario corregido --- db/changes/10500-november/00-zone_getPostalCode.sql | 2 -- 1 file changed, 2 deletions(-) diff --git a/db/changes/10500-november/00-zone_getPostalCode.sql b/db/changes/10500-november/00-zone_getPostalCode.sql index b71306a58..58a281cb2 100644 --- a/db/changes/10500-november/00-zone_getPostalCode.sql +++ b/db/changes/10500-november/00-zone_getPostalCode.sql @@ -6,8 +6,6 @@ CREATE DEFINER=`root`@`localhost` PROCEDURE `vn`.`zone_getPostalCode`(vSelf INT) BEGIN /** * Devuelve los códigos postales incluidos en una zona - * - * @return vNewTicket */ DECLARE vGeoFk INT DEFAULT NULL; From c0b95564c3fc5bd764603524fffa1e99d8125541 Mon Sep 17 00:00:00 2001 From: vicent Date: Wed, 26 Oct 2022 14:25:17 +0200 Subject: [PATCH 52/55] refactor: borrado codigo sql innecesario --- modules/client/back/methods/client/filter.js | 37 +++----------------- 1 file changed, 4 insertions(+), 33 deletions(-) diff --git a/modules/client/back/methods/client/filter.js b/modules/client/back/methods/client/filter.js index 7cf4ba2ea..3e1ea43bb 100644 --- a/modules/client/back/methods/client/filter.js +++ b/modules/client/back/methods/client/filter.js @@ -114,53 +114,24 @@ module.exports = Self => { const stmts = []; const stmt = new ParameterizedSQL( `SELECT - c.id, + DISTINCT c.id, c.name, - c.socialName, c.fi, - c.credit, - c.creditInsurance, + c.socialName, c.phone, - c.mobile, - c.street, c.city, c.postcode, c.email, - c.created, c.isActive, - c.isVies, - c.isTaxDataChecked, - c.isEqualizated, c.isFreezed, - c.hasToInvoice, - c.hasToInvoiceByAddress, - c.isToBeMailed, - c.hasSepaVnl, - c.hasLcr, - c.hasCoreVnl, - ct.id AS countryFk, - ct.country, p.id AS provinceFk, p.name AS province, u.id AS salesPersonFk, - u.name AS salesPerson, - bt.code AS businessTypeFk, - bt.description AS businessType, - pm.id AS payMethodFk, - pm.name AS payMethod, - sti.CodigoIva AS sageTaxTypeFk, - sti.Iva AS sageTaxType, - stt.CodigoTransaccion AS sageTransactionTypeFk, - stt.Transaccion AS sageTransactionType + u.name AS salesPerson FROM client c LEFT JOIN account.user u ON u.id = c.salesPersonFk - LEFT JOIN country ct ON ct.id = c.countryFk LEFT JOIN province p ON p.id = c.provinceFk - LEFT JOIN businessType bt ON bt.code = c.businessTypeFk - LEFT JOIN payMethod pm ON pm.id = c.payMethodFk - LEFT JOIN sage.TiposIva sti ON sti.CodigoIva = c.taxTypeSageFk - LEFT JOIN sage.TiposTransacciones stt ON stt.CodigoTransaccion = c.transactionTypeSageFk - LEFT JOIN vn.address a ON a.id = c.defaultAddressFk + JOIN vn.address a ON a.clientFk = c.id ` ); From 1d908002e22481c39bd5e72f8c0add5e45161514 Mon Sep 17 00:00:00 2001 From: vicent Date: Wed, 26 Oct 2022 14:25:27 +0200 Subject: [PATCH 53/55] feat: add backTest --- db/dump/fixtures.sql | 85 ++++---- .../back/methods/client/specs/filter.spec.js | 199 ++++++++++++++++++ 2 files changed, 242 insertions(+), 42 deletions(-) create mode 100644 modules/client/back/methods/client/specs/filter.spec.js diff --git a/db/dump/fixtures.sql b/db/dump/fixtures.sql index 5b769e285..beed24739 100644 --- a/db/dump/fixtures.sql +++ b/db/dump/fixtures.sql @@ -353,48 +353,48 @@ INSERT INTO `vn`.`clientConfig`(`riskTolerance`, `maxCreditRows`) INSERT INTO `vn`.`address`(`id`, `nickname`, `street`, `city`, `postalCode`, `provinceFk`, `phone`, `mobile`, `isActive`, `clientFk`, `agencyModeFk`, `longitude`, `latitude`, `isEqualizated`, `isDefaultAddress`) VALUES - (1, 'Bruce Wayne', '1007 Mountain Drive, Gotham', 'Gotham', 46460, 1, 1111111111, 222222222, 1, 1101, 2, NULL, NULL, 0, 1), - (2, 'Petter Parker', '20 Ingram Street', 'Gotham', 46460, 1, 1111111111, 222222222, 1, 1102, 2, NULL, NULL, 0, 1), - (3, 'Clark Kent', '344 Clinton Street', 'Gotham', 46460, 1, 1111111111, 222222222, 1, 1103, 2, NULL, NULL, 0, 1), - (4, 'Tony Stark', '10880 Malibu Point', 'Gotham', 46460, 1, 1111111111, 222222222, 1, 1104, 2, NULL, NULL, 0, 1), - (5, 'Max Eisenhardt', 'Unknown Whereabouts', 'Gotham', 46460, 1, 1111111111, 222222222, 1, 1105, 2, NULL, NULL, 0, 1), - (6, 'DavidCharlesHaller', 'Evil hideout', 'Gotham', 46460, 1, 1111111111, 222222222, 1, 1106, 2, NULL, NULL, 0, 1), - (7, 'Hank Pym', 'Anthill', 'Gotham', 46460, 1, 1111111111, 222222222, 1, 1107, 2, NULL, NULL, 0, 1), - (8, 'Charles Xavier', '3800 Victory Pkwy, Cincinnati, OH 45207, USA', 'Gotham', 46460, 1, 1111111111, 222222222, 1, 1108, 2, NULL, NULL, 0, 1), - (9, 'Bruce Banner', 'Somewhere in New York', 'Gotham', 46460, 1, 1111111111, 222222222, 1, 1109, 2, NULL, NULL, 0, 1), - (10, 'Jessica Jones', 'NYCC 2015 Poster', 'Gotham', 46460, 1, 1111111111, 222222222, 1, 1110, 2, NULL, NULL, 0, 1), - (11, 'Missing', 'The space', 'Gotham', 46460, 1, 1111111111, 222222222, 1, 1111, 10, NULL, NULL, 0, 1), - (12, 'Trash', 'New York city', 'Gotham', 46460, 1, 1111111111, 222222222, 1, 1112, 10, NULL, NULL, 0, 1), - (101, 'Somewhere in Thailand', 'address 01', 'Gotham', 46460, 1, 1111111111, 222222222, 1, 1109, 2, NULL, NULL, 0, 0), - (102, 'Somewhere in Poland', 'address 02', 'Gotham', 46460, 1, 3333333333, 444444444, 1, 1109, 2, NULL, NULL, 0, 0), - (103, 'Somewhere in Japan', 'address 03', 'Gotham', 46460, 1, 3333333333, 444444444, 1, 1109, 2, NULL, NULL, 0, 0), - (104, 'Somewhere in Spain', 'address 04', 'Gotham', 46460, 1, 3333333333, 444444444, 1, 1109, 2, NULL, NULL, 0, 0), - (105, 'Somewhere in Potugal', 'address 05', 'Gotham', 46460, 1, 5555555555, 666666666, 1, 1109, 2, NULL, NULL, 0, 0), - (106, 'Somewhere in UK', 'address 06', 'Gotham', 46460, 1, 5555555555, 666666666, 1, 1109, 2, NULL, NULL, 0, 0), - (107, 'Somewhere in Valencia', 'address 07', 'Gotham', 46460, 1, 5555555555, 666666666, 1, 1109, 2, NULL, NULL, 0, 0), - (108, 'Somewhere in Gotham', 'address 08', 'Gotham', 46460, 1, 5555555555, 666666666, 1, 1109, 2, NULL, NULL, 0, 0), - (109, 'Somewhere in London', 'address 09', 'Gotham', 46460, 1, 1111111111, 222222222, 1, 1109, 2, NULL, NULL, 0, 0), - (110, 'Somewhere in Algemesi', 'address 10', 'Gotham', 46460, 1, 1111111111, 222222222, 1, 1109, 2, NULL, NULL, 0, 0), - (111, 'Somewhere in Carlet', 'address 11', 'Gotham', 46460, 1, 1111111111, 222222222, 1, 1109, 2, NULL, NULL, 0, 0), - (112, 'Somewhere in Campanar', 'address 12', 'Gotham', 46460, 1, 1111111111, 222222222, 1, 1109, 2, NULL, NULL, 0, 0), - (113, 'Somewhere in Malilla', 'address 13', 'Gotham', 46460, 1, 1111111111, 222222222, 1, 1109, 2, NULL, NULL, 0, 0), - (114, 'Somewhere in France', 'address 14', 'Gotham', 46460, 1, 1111111111, 222222222, 1, 1109, 2, NULL, NULL, 0, 0), - (115, 'Somewhere in Birmingham', 'address 15', 'Gotham', 46460, 1, 1111111111, 222222222, 1, 1109, 2, NULL, NULL, 0, 0), - (116, 'Somewhere in Scotland', 'address 16', 'Gotham', 46460, 1, 1111111111, 222222222, 1, 1109, 2, NULL, NULL, 0, 0), - (117, 'Somewhere in nowhere', 'address 17', 'Gotham', 46460, 1, 1111111111, 222222222, 1, 1109, 2, NULL, NULL, 0, 0), - (118, 'Somewhere over the rainbow', 'address 18', 'Gotham', 46460, 1, 1111111111, 222222222, 1, 1109, 2, NULL, NULL, 0, 0), - (119, 'Somewhere in Alberic', 'address 19', 'Gotham', 46460, 1, 1111111111, 222222222, 1, 1109, 2, NULL, NULL, 0, 0), - (120, 'Somewhere in Montortal', 'address 20', 'Gotham', 46460, 1, 1111111111, 222222222, 1, 1109, 2, NULL, NULL, 0, 0), - (121, 'the bat cave', 'address 21', 'Gotham', 46460, 1, 1111111111, 222222222, 1, 1101, 2, NULL, NULL, 0, 0), - (122, 'NY roofs', 'address 22', 'Gotham', 46460, 1, 1111111111, 222222222, 1, 1102, 2, NULL, NULL, 0, 0), - (123, 'The phone box', 'address 23', 'Gotham', 46460, 1, 1111111111, 222222222, 1, 1103, 2, NULL, NULL, 0, 0), - (124, 'Stark tower Gotham', 'address 24', 'Gotham', 46460, 1, 1111111111, 222222222, 1, 1104, 2, NULL, NULL, 0, 0), - (125, 'The plastic cell', 'address 25', 'Gotham', 46460, 1, 1111111111, 222222222, 1, 1105, 2, NULL, NULL, 0, 0), - (126, 'Many places', 'address 26', 'Gotham', 46460, 1, 1111111111, 222222222, 1, 1106, 2, NULL, NULL, 0, 0), - (127, 'Your pocket', 'address 27', 'Gotham', 46460, 1, 1111111111, 222222222, 1, 1107, 2, NULL, NULL, 0, 0), - (128, 'Cerebro', 'address 28', 'Gotham', 46460, 1, 1111111111, 222222222, 1, 1108, 2, NULL, NULL, 0, 0), - (129, 'Luke Cages Bar', 'address 29', 'Gotham', 46460, 1, 1111111111, 222222222, 1, 1110, 2, NULL, NULL, 0, 0), - (130, 'Non valid address', 'address 30', 'Gotham', 46460, 1, 1111111111, 222222222, 0, 1101, 2, NULL, NULL, 0, 0); + (1, 'Bruce Wayne', '1007 Mountain Drive, Gotham', 'Gotham', 46460, 1, 1111111111, 222222222, 1, 1101, 2, NULL, NULL, 0, 1), + (2, 'Petter Parker', '20 Ingram Street', 'Gotham', 46460, 1, 1111111111, 222222222, 1, 1102, 2, NULL, NULL, 0, 1), + (3, 'Clark Kent', '344 Clinton Street', 'Gotham', 46460, 1, 1111111111, 222222222, 1, 1103, 2, NULL, NULL, 0, 1), + (4, 'Tony Stark', '10880 Malibu Point', 'Gotham', 46460, 1, 1111111111, 222222222, 1 , 1104, 2, NULL, NULL, 0, 1), + (5, 'Max Eisenhardt', 'Unknown Whereabouts', 'Gotham', 46460, 1, 1111111111, 222222222, 1, 1105, 2, NULL, NULL, 0, 1), + (6, 'DavidCharlesHaller', 'Evil hideout', 'Gotham', 46460, 1, 1111111111, 222222222, 1, 1106, 2, NULL, NULL, 0, 1), + (7, 'Hank Pym', 'Anthill', 'Gotham', 46460, 1, 1111111111, 222222222, 1, 1107, 2, NULL, NULL, 0, 1), + (8, 'Charles Xavier', '3800 Victory Pkwy, Cincinnati, OH 45207, USA', 'Gotham', 46460, 1, 1111111111, 222222222, 1, 1108, 2, NULL, NULL, 0, 1), + (9, 'Bruce Banner', 'Somewhere in New York', 'Gotham', 46460, 1, 1111111111, 222222222, 1, 1109, 2, NULL, NULL, 0, 1), + (10, 'Jessica Jones', 'NYCC 2015 Poster', 'Gotham', 46460, 1, 1111111111, 222222222, 1, 1110, 2, NULL, NULL, 0, 1), + (11, 'Missing', 'The space', 'Gotham', 46460, 1, 1111111111, 222222222, 1, 1111, 10, NULL, NULL, 0, 1), + (12, 'Trash', 'New York city', 'Gotham', 46460, 1, 1111111111, 222222222, 1, 1112, 10, NULL, NULL, 0, 1), + (101, 'Somewhere in Thailand', 'address 01', 'Gotham', 46460, 1, 1111111111, 222222222, 1, 1109, 2, NULL, NULL, 0, 0), + (102, 'Somewhere in Poland', 'address 02', 'Gotham', 46460, 1, 3333333333, 444444444, 1, 1109, 2, NULL, NULL, 0, 0), + (103, 'Somewhere in Japan', 'address 03', 'Gotham', 46460, 1, 3333333333, 444444444, 1, 1109, 2, NULL, NULL, 0, 0), + (104, 'Somewhere in Spain', 'address 04', 'Gotham', 46460, 1, 3333333333, 444444444, 1, 1109, 2, NULL, NULL, 0, 0), + (105, 'Somewhere in Potugal', 'address 05', 'Gotham', 46460, 1, 5555555555, 666666666, 1, 1109, 2, NULL, NULL, 0, 0), + (106, 'Somewhere in UK', 'address 06', 'Gotham', 46460, 1, 5555555555, 666666666, 1, 1109, 2, NULL, NULL, 0, 0), + (107, 'Somewhere in Valencia', 'address 07', 'Gotham', 46460, 1, 5555555555, 666666666, 1, 1109, 2, NULL, NULL, 0, 0), + (108, 'Somewhere in Gotham', 'address 08', 'Gotham', 46460, 1, 5555555555, 666666666, 1, 1109, 2, NULL, NULL, 0, 0), + (109, 'Somewhere in London', 'address 09', 'Gotham', 46460, 1, 1111111111, 222222222, 1, 1109, 2, NULL, NULL, 0, 0), + (110, 'Somewhere in Algemesi', 'address 10', 'Gotham', 46460, 1, 1111111111, 222222222, 1, 1109, 2, NULL, NULL, 0, 0), + (111, 'Somewhere in Carlet', 'address 11', 'Gotham', 46460, 1, 1111111111, 222222222, 1, 1109, 2, NULL, NULL, 0, 0), + (112, 'Somewhere in Campanar', 'address 12', 'Gotham', 46460, 1, 1111111111, 222222222, 1, 1109, 2, NULL, NULL, 0, 0), + (113, 'Somewhere in Malilla', 'address 13', 'Gotham', 46460, 1, 1111111111, 222222222, 1, 1109, 2, NULL, NULL, 0, 0), + (114, 'Somewhere in France', 'address 14', 'Gotham', 46460, 1, 1111111111, 222222222, 1, 1109, 2, NULL, NULL, 0, 0), + (115, 'Somewhere in Birmingham', 'address 15', 'Gotham', 46460, 1, 1111111111, 222222222, 1, 1109, 2, NULL, NULL, 0, 0), + (116, 'Somewhere in Scotland', 'address 16', 'Gotham', 46460, 1, 1111111111, 222222222, 1, 1109, 2, NULL, NULL, 0, 0), + (117, 'Somewhere in nowhere', 'address 17', 'Gotham', 46460, 1, 1111111111, 222222222, 1, 1109, 2, NULL, NULL, 0, 0), + (118, 'Somewhere over the rainbow', 'address 18', 'Gotham', 46460, 1, 1111111111, 222222222, 1, 1109, 2, NULL, NULL, 0, 0), + (119, 'Somewhere in Alberic', 'address 19', 'Gotham', 46460, 1, 1111111111, 222222222, 1, 1109, 2, NULL, NULL, 0, 0), + (120, 'Somewhere in Montortal', 'address 20', 'Gotham', 46460, 1, 1111111111, 222222222, 1, 1109, 2, NULL, NULL, 0, 0), + (121, 'the bat cave', 'address 21', 'Gotham', 46460, 1, 1111111111, 222222222, 1, 1101, 2, NULL, NULL, 0, 0), + (122, 'NY roofs', 'address 22', 'Gotham', 46460, 1, 1111111111, 222222222, 1, 1102, 2, NULL, NULL, 0, 0), + (123, 'The phone box', 'address 23', 'Gotham', 46460, 1, 1111111111, 222222222, 1, 1103, 2, NULL, NULL, 0, 0), + (124, 'Stark tower Gotham', 'address 24', 'Gotham', 46460, 1, 1111111111, 222222222, 1, 1104, 2, NULL, NULL, 0, 0), + (125, 'The plastic cell', 'address 25', 'Gotham', 46460, 1, 1111111111, 222222222, 1, 1105, 2, NULL, NULL, 0, 0), + (126, 'Many places', 'address 26', 'Gotham', 46460, 1, 1111111111, 222222222, 1, 1106, 2, NULL, NULL, 0, 0), + (127, 'Your pocket', 'address 27', 'Gotham', 46460, 1, 1111111111, 222222222, 1, 1107, 2, NULL, NULL, 0, 0), + (128, 'Cerebro', 'address 28', 'Gotham', 46460, 1, 1111111111, 222222222, 1, 1108, 2, NULL, NULL, 0, 0), + (129, 'Luke Cages Bar', 'address 29', 'Gotham', 'EC170150', 1, 1111111111, 222222222, 1, 1110, 2, NULL, NULL, 0, 0), + (130, 'Non valid address', 'address 30', 'Gotham', 46460, 1, 1111111111, 222222222, 0, 1101, 2, NULL, NULL, 0, 0); INSERT INTO `vn`.`address`( `nickname`, `street`, `city`, `postalCode`, `provinceFk`, `isActive`, `clientFk`, `agencyModeFk`, `isDefaultAddress`) SELECT name, CONCAT(name, 'Street'), 'GOTHAM', 46460, 1, 1, id, 2, 1 @@ -2047,6 +2047,7 @@ INSERT INTO `vn`.`zoneIncluded` (`zoneFk`, `geoFk`, `isIncluded`) (8, 4, 0), (8, 5, 0), (8, 1, 1), + (9, 7, 1), (10, 14, 1); INSERT INTO `vn`.`zoneEvent`(`zoneFk`, `type`, `dated`) diff --git a/modules/client/back/methods/client/specs/filter.spec.js b/modules/client/back/methods/client/specs/filter.spec.js new file mode 100644 index 000000000..679585050 --- /dev/null +++ b/modules/client/back/methods/client/specs/filter.spec.js @@ -0,0 +1,199 @@ +const {models} = require('vn-loopback/server/server'); + +describe('client filter()', () => { + it('should return the clients matching the filter with a limit of 20 rows', async() => { + const tx = await models.Client.beginTransaction({}); + + try { + const options = {transaction: tx}; + + const ctx = {req: {accessToken: {userId: 1}}, args: {}}; + const filter = {limit: '8'}; + const result = await models.Client.filter(ctx, filter, options); + + expect(result.length).toEqual(8); + + await tx.rollback(); + } catch (e) { + await tx.rollback(); + throw e; + } + }); + + it('should return the client "Bruce Wayne" matching the search argument with his name', async() => { + const tx = await models.Client.beginTransaction({}); + + try { + const options = {transaction: tx}; + + const ctx = {req: {accessToken: {userId: 1}}, args: {search: 'Bruce Wayne'}}; + const filter = {}; + const result = await models.Client.filter(ctx, filter, options); + + const firstResult = result[0]; + + expect(result.length).toEqual(1); + expect(firstResult.name).toEqual('Bruce Wayne'); + + await tx.rollback(); + } catch (e) { + await tx.rollback(); + throw e; + } + }); + + it('should return the client "Bruce Wayne" matching the search argument with his id', async() => { + const tx = await models.Client.beginTransaction({}); + + try { + const options = {transaction: tx}; + + const ctx = {req: {accessToken: {userId: 1}}, args: {search: '1101'}}; + const filter = {}; + const result = await models.Client.filter(ctx, filter, options); + + const firstResult = result[0]; + + expect(result.length).toEqual(1); + expect(firstResult.name).toEqual('Bruce Wayne'); + + await tx.rollback(); + } catch (e) { + await tx.rollback(); + throw e; + } + }); + + it('should return the client "Bruce Wayne" matching the name argument', async() => { + const tx = await models.Client.beginTransaction({}); + + try { + const options = {transaction: tx}; + + const ctx = {req: {accessToken: {userId: 1}}, args: {name: 'Bruce Wayne'}}; + const filter = {}; + const result = await models.Client.filter(ctx, filter, options); + + const firstResult = result[0]; + + expect(result.length).toEqual(1); + expect(firstResult.name).toEqual('Bruce Wayne'); + + await tx.rollback(); + } catch (e) { + await tx.rollback(); + throw e; + } + }); + + it('should return the clients matching the "salesPersonFk" argument', async() => { + const tx = await models.Client.beginTransaction({}); + const salesPersonId = 18; + + try { + const options = {transaction: tx}; + + const ctx = {req: {accessToken: {userId: 1}}, args: {salesPersonFk: salesPersonId}}; + const filter = {}; + const result = await models.Client.filter(ctx, filter, options); + + const randomIndex = Math.floor(Math.random() * result.length); + const randomResultClient = result[randomIndex]; + + expect(result.length).toBeGreaterThanOrEqual(5); + expect(randomResultClient.salesPersonFk).toEqual(salesPersonId); + + await tx.rollback(); + } catch (e) { + await tx.rollback(); + throw e; + } + }); + + it('should return the clients matching the "fi" argument', async() => { + const tx = await models.Client.beginTransaction({}); + + try { + const options = {transaction: tx}; + + const ctx = {req: {accessToken: {userId: 1}}, args: {fi: '251628698'}}; + const filter = {}; + const result = await models.Client.filter(ctx, filter, options); + + const firstClient = result[0]; + + expect(result.length).toEqual(1); + expect(firstClient.name).toEqual('Max Eisenhardt'); + + await tx.rollback(); + } catch (e) { + await tx.rollback(); + throw e; + } + }); + + it('should return the clients matching the "city" argument', async() => { + const tx = await models.Client.beginTransaction({}); + + try { + const options = {transaction: tx}; + + const ctx = {req: {accessToken: {userId: 1}}, args: {city: 'Gotham'}}; + const filter = {}; + const result = await models.Client.filter(ctx, filter, options); + + const randomIndex = Math.floor(Math.random() * result.length); + const randomResultClient = result[randomIndex]; + + expect(result.length).toBeGreaterThanOrEqual(20); + expect(randomResultClient.city.toLowerCase()).toEqual('gotham'); + + await tx.rollback(); + } catch (e) { + await tx.rollback(); + throw e; + } + }); + + it('should return the clients matching the "postcode" argument', async() => { + const tx = await models.Client.beginTransaction({}); + + try { + const options = {transaction: tx}; + + const ctx = {req: {accessToken: {userId: 1}}, args: {postcode: '46460'}}; + const filter = {}; + const result = await models.Client.filter(ctx, filter, options); + + const randomIndex = Math.floor(Math.random() * result.length); + const randomResultClient = result[randomIndex]; + + expect(result.length).toBeGreaterThanOrEqual(20); + expect(randomResultClient.postcode).toEqual('46460'); + + await tx.rollback(); + } catch (e) { + await tx.rollback(); + throw e; + } + }); + + it('should return the clients matching the "zoneFk" argument', async() => { + const tx = await models.Client.beginTransaction({}); + + try { + const options = {transaction: tx}; + + const ctx = {req: {accessToken: {userId: 1}}, args: {zoneFk: 9}}; + const filter = {}; + const result = await models.Client.filter(ctx, filter, options); + + expect(result.length).toBe(1); + + await tx.rollback(); + } catch (e) { + await tx.rollback(); + throw e; + } + }); +}); From 736de00e77da5cf492a7e1e9a433233d97053c71 Mon Sep 17 00:00:00 2001 From: Pau Navarro Date: Thu, 27 Oct 2022 09:18:00 +0200 Subject: [PATCH 54/55] deleted the test as requested on #1885 --- db/tests/vn/orderConfirmWithUser.spec.js | 37 ------------------------ 1 file changed, 37 deletions(-) delete mode 100644 db/tests/vn/orderConfirmWithUser.spec.js diff --git a/db/tests/vn/orderConfirmWithUser.spec.js b/db/tests/vn/orderConfirmWithUser.spec.js deleted file mode 100644 index f2a3d0c4e..000000000 --- a/db/tests/vn/orderConfirmWithUser.spec.js +++ /dev/null @@ -1,37 +0,0 @@ -const app = require('vn-loopback/server/server'); -const ParameterizedSQL = require('loopback-connector').ParameterizedSQL; - -// #1885 -xdescribe('order_confirmWithUser()', () => { - it('should confirm an order', async() => { - let stmts = []; - let stmt; - - stmts.push('START TRANSACTION'); - - let params = { - orderFk: 10, - userId: 9 - }; - // problema: la funcion order_confirmWithUser tiene una transacción, por tanto esta nunca hace rollback - stmt = new ParameterizedSQL('CALL hedera.order_confirmWithUser(?, ?)', [ - params.orderFk, - params.userId - ]); - stmts.push(stmt); - - stmt = new ParameterizedSQL('SELECT confirmed FROM hedera.order WHERE id = ?', [ - params.orderFk - ]); - let orderIndex = stmts.push(stmt) - 1; - - stmts.push('ROLLBACK'); - - let sql = ParameterizedSQL.join(stmts, ';'); - let result = await app.models.Ticket.rawStmt(sql); - - savedDescription = result[orderIndex][0].confirmed; - - expect(savedDescription).toBeTruthy(); - }); -}); From a7b1ee85fec2bcd7eab29fed84c642de265224f7 Mon Sep 17 00:00:00 2001 From: alexm Date: Wed, 2 Nov 2022 07:27:57 +0100 Subject: [PATCH 55/55] fix changes folder --- .../{10490-goldenSummer => 10500-november}/00-aclNotification.sql | 0 .../{10490-august => 10500-november}/00-packingSiteConfig.sql | 0 .../{10490-august => 10500-november}/00-packingSiteUpdate.sql | 0 db/changes/{10490-august => 10500-november}/00-salix_url.sql | 0 4 files changed, 0 insertions(+), 0 deletions(-) rename db/changes/{10490-goldenSummer => 10500-november}/00-aclNotification.sql (100%) rename db/changes/{10490-august => 10500-november}/00-packingSiteConfig.sql (100%) rename db/changes/{10490-august => 10500-november}/00-packingSiteUpdate.sql (100%) rename db/changes/{10490-august => 10500-november}/00-salix_url.sql (100%) diff --git a/db/changes/10490-goldenSummer/00-aclNotification.sql b/db/changes/10500-november/00-aclNotification.sql similarity index 100% rename from db/changes/10490-goldenSummer/00-aclNotification.sql rename to db/changes/10500-november/00-aclNotification.sql diff --git a/db/changes/10490-august/00-packingSiteConfig.sql b/db/changes/10500-november/00-packingSiteConfig.sql similarity index 100% rename from db/changes/10490-august/00-packingSiteConfig.sql rename to db/changes/10500-november/00-packingSiteConfig.sql diff --git a/db/changes/10490-august/00-packingSiteUpdate.sql b/db/changes/10500-november/00-packingSiteUpdate.sql similarity index 100% rename from db/changes/10490-august/00-packingSiteUpdate.sql rename to db/changes/10500-november/00-packingSiteUpdate.sql diff --git a/db/changes/10490-august/00-salix_url.sql b/db/changes/10500-november/00-salix_url.sql similarity index 100% rename from db/changes/10490-august/00-salix_url.sql rename to db/changes/10500-november/00-salix_url.sql