From 4a5d97996e023db54d703aeb0fd89caf0e58c475 Mon Sep 17 00:00:00 2001 From: Bernat Exposito Domenech Date: Tue, 10 Mar 2020 14:09:26 +0100 Subject: [PATCH 01/25] travel.index clonar --- front/core/components/watcher/watcher.js | 22 +++++++++-- loopback/locale/es.json | 3 +- modules/travel/back/models/travel.js | 8 ++++ modules/travel/front/create/index.js | 22 +++++++++++ modules/travel/front/create/index.spec.js | 17 ++++++++ modules/travel/front/index/index.html | 25 +++++++++--- modules/travel/front/index/index.js | 48 ++++++++++++++++++----- modules/travel/front/index/index.spec.js | 44 +++++++++++++++++++++ modules/travel/front/index/locale/es.yml | 2 + modules/travel/front/routes.json | 2 +- 10 files changed, 172 insertions(+), 21 deletions(-) create mode 100644 modules/travel/front/index/locale/es.yml diff --git a/front/core/components/watcher/watcher.js b/front/core/components/watcher/watcher.js index ddef745fda..04ccba45e6 100644 --- a/front/core/components/watcher/watcher.js +++ b/front/core/components/watcher/watcher.js @@ -100,7 +100,9 @@ export default class Watcher extends Component { */ submit() { try { - this.check(); + if (this.requestMethod() !== 'post') + this.check(); + else this.isInvalid(); } catch (err) { return this.$q.reject(err); } @@ -120,12 +122,12 @@ export default class Watcher extends Component { if (this.form) this.form.$setSubmitted(); - if (!this.dataChanged()) { + const isPost = (this.requestMethod() === 'post'); + if (!this.dataChanged() && !isPost) { this.updateOriginalData(); return this.$q.resolve(); } - let isPost = (this.$attrs.save && this.$attrs.save.toLowerCase() === 'post'); let changedData = isPost ? this.data : getModifiedData(this.data, this.orgData); @@ -158,7 +160,6 @@ export default class Watcher extends Component { }); } - return this.$q((resolve, reject) => { this.$http.post(this.url, changedData).then( json => this.writeData(json, resolve), @@ -167,6 +168,10 @@ export default class Watcher extends Component { }); } + requestMethod() { + return this.$attrs.save && this.$attrs.save.toLowerCase(); + } + /** * Checks if data is ready to send. */ @@ -177,6 +182,15 @@ export default class Watcher extends Component { throw new UserError('No changes to save'); } + /** + * Checks if data is ready to send. + */ + isInvalid() { + console.log(this.form.$invalid); + if (this.form && this.form.$invalid) + throw new UserError('Some fields are invalid'); + } + /** * Notifies the user that the data has been saved. */ diff --git a/loopback/locale/es.json b/loopback/locale/es.json index fe95bc0650..e975185041 100644 --- a/loopback/locale/es.json +++ b/loopback/locale/es.json @@ -128,5 +128,6 @@ "Client checked as validated despite of duplication": "Cliente comprobado a pesar de que existe el cliente id {{clientId}}", "ORDER_ROW_UNAVAILABLE": "No hay disponibilidad de este producto", "Distance must be lesser than 1000": "La distancia debe ser inferior a 1000", - "This ticket is deleted": "Este ticket está eliminado" + "This ticket is deleted": "Este ticket está eliminado", + "The introduced data already exists": "La información introducida ya existe" } \ No newline at end of file diff --git a/modules/travel/back/models/travel.js b/modules/travel/back/models/travel.js index 4643f79fd5..a7c045b314 100644 --- a/modules/travel/back/models/travel.js +++ b/modules/travel/back/models/travel.js @@ -1,3 +1,5 @@ +const UserError = require('vn-loopback/util/user-error'); + module.exports = Self => { require('../methods/travel/getTravel')(Self); require('../methods/travel/getEntries')(Self); @@ -5,4 +7,10 @@ module.exports = Self => { require('../methods/travel/createThermograph')(Self); require('../methods/travel/deleteThermograph')(Self); require('../methods/travel/updateThermograph')(Self); + + Self.rewriteDbError(function(err) { + if (err.code === 'ER_DUP_ENTRY') + return new UserError('The introduced data already exists'); + return err; + }); }; diff --git a/modules/travel/front/create/index.js b/modules/travel/front/create/index.js index 02be34ca78..513e1e0b13 100644 --- a/modules/travel/front/create/index.js +++ b/modules/travel/front/create/index.js @@ -2,6 +2,26 @@ import ngModule from '../module'; import Section from 'salix/components/section'; class Controller extends Section { + constructor($element, $, $stateParams) { + super($element, $); + this.$stateParams = $stateParams; + this.travel = {}; + } + + $onChanges() { + if (this.$stateParams && this.$stateParams.q) + this._travel = JSON.parse(this.$stateParams.q); + } + + get travel() { + return this._travel; + } + + set travel(value) { + this._travel = value; + if (!value) return; + } + onSubmit() { return this.$.watcher.submit().then( res => this.$state.go('travel.card.summary', {id: res.data.id}) @@ -9,6 +29,8 @@ class Controller extends Section { } } +Controller.$inject = ['$element', '$scope', '$stateParams']; + ngModule.component('vnTravelCreate', { template: require('./index.html'), controller: Controller diff --git a/modules/travel/front/create/index.spec.js b/modules/travel/front/create/index.spec.js index 63f0eda42f..ef83d98ff1 100644 --- a/modules/travel/front/create/index.spec.js +++ b/modules/travel/front/create/index.spec.js @@ -26,5 +26,22 @@ describe('Travel Component vnTravelCreate', () => { expect(controller.$state.go).toHaveBeenCalledWith('travel.card.summary', {id: 1234}); }); }); + + describe('$onChanges()', () => { + it('should update the travel data when stateParams.q is defined', () => { + controller.$stateParams = {q: { + ref: 1, + agencyModeFk: 1 + }}; + + const result = {q: { + ref: 1, + agencyModeFk: 1 + }}; + controller.$onChanges(); + + expect(controller._travel).toBe(result); + }); + }); }); diff --git a/modules/travel/front/index/index.html b/modules/travel/front/index/index.html index 3af99eb6bd..ee7f88507a 100644 --- a/modules/travel/front/index/index.html +++ b/modules/travel/front/index/index.html @@ -41,12 +41,19 @@ {{::travel.warehouseInName}} {{::travel.landed | date:'dd/MM/yyyy'}} - - - + + + + + + + @@ -65,4 +72,10 @@ fixed-bottom-right> + + \ No newline at end of file diff --git a/modules/travel/front/index/index.js b/modules/travel/front/index/index.js index a1e22d2e77..8402d00a26 100644 --- a/modules/travel/front/index/index.js +++ b/modules/travel/front/index/index.js @@ -1,16 +1,10 @@ import ngModule from '../module'; export default class Controller { - constructor($scope) { + constructor($scope, $state) { this.$ = $scope; this.ticketSelected = null; - } - - preview(event, travel) { - this.travelSelected = travel; - this.$.summary.show(); - event.preventDefault(); - event.stopImmediatePropagation(); + this.$state = $state; } getScopeDates(days) { @@ -35,9 +29,45 @@ export default class Controller { } else this.$.model.clear(); } + + stopEvent(event) { + event.preventDefault(); + event.stopImmediatePropagation(); + } + + cloneTravel(event, travel) { + this.stopEvent(event); + this.travelSelected = travel; + this.$.clone.show(); + } + + onCloneAccept(response) { + if (!(response == 'accept' && this.travelSelected)) + return; + if (this.travelSelected) { + console.log('this.travelSelected', this.travelSelected); + const travel = { + ref: this.travelSelected.ref, + agencyModeFk: this.travelSelected.agencyFk, + shipped: this.travelSelected.shipped, + landed: this.travelSelected.landed, + warehouseInFk: this.travelSelected.warehouseInFk, + warehouseOutFk: this.travelSelected.warehouseOutFk + }; + const queryParams = JSON.stringify(travel); + this.$state.go('travel.create', {q: queryParams}); + } + + this.travelSelected = null; + } + preview(event, travel) { + this.stopEvent(event); + this.travelSelected = travel; + this.$.summary.show(); + } } -Controller.$inject = ['$scope']; +Controller.$inject = ['$scope', '$state']; ngModule.component('vnTravelIndex', { template: require('./index.html'), diff --git a/modules/travel/front/index/index.spec.js b/modules/travel/front/index/index.spec.js index 5affc7c1a1..8e180e1685 100644 --- a/modules/travel/front/index/index.spec.js +++ b/modules/travel/front/index/index.spec.js @@ -61,4 +61,48 @@ describe('Travel Component vnTravelIndex', () => { expect(range - dayInMilliseconds).toEqual(dayInMilliseconds + millisecondsPerAddedDay); }); }); + + describe('onCloneAccept()', () => { + it('should do nothing if response is not accept', () => { + jest.spyOn(controller.$state, 'go'); + + let response = 'ERROR!'; + controller.travelSelected = 'check me'; + + controller.onCloneAccept(response); + + expect(controller.$state.go).not.toHaveBeenCalledWith(); + expect(controller.travelSelected).toEqual('check me'); + }); + + it('should do nothing if response is accept but travelSelected is not defined in the controller', () => { + jest.spyOn(controller.$state, 'go'); + + let response = 'accept'; + controller.travelSelected = undefined; + + controller.onCloneAccept(response); + + expect(controller.$state.go).not.toHaveBeenCalledWith(); + expect(controller.travelSelected).toBeUndefined(); + }); + + it('should call go() then update travelSelected in the controller', () => { + jest.spyOn(controller.$state, 'go'); + + let response = 'accept'; + controller.travelSelected = { + ref: 1, + agencyFk: 1}; + const travel = { + ref: controller.travelSelected.ref, + agencyModeFk: controller.travelSelected.agencyFk + }; + const queryParams = JSON.stringify(travel); + controller.onCloneAccept(response); + + expect(controller.$state.go).toHaveBeenCalledWith('travel.create', {q: queryParams}); + expect(controller.travelSelected).toBeNull(); + }); + }); }); diff --git a/modules/travel/front/index/locale/es.yml b/modules/travel/front/index/locale/es.yml new file mode 100644 index 0000000000..63d23affdd --- /dev/null +++ b/modules/travel/front/index/locale/es.yml @@ -0,0 +1,2 @@ +Do you want to clone this travel?: ¿Desea clonar este envio? +All it's properties will be copied: Todas sus propiedades serán copiadas \ No newline at end of file diff --git a/modules/travel/front/routes.json b/modules/travel/front/routes.json index 50e2368891..b802aaa4a3 100644 --- a/modules/travel/front/routes.json +++ b/modules/travel/front/routes.json @@ -54,7 +54,7 @@ "component": "vn-travel-log", "description": "Log" }, { - "url": "/create", + "url": "/create?q", "state": "travel.create", "component": "vn-travel-create", "description": "New travel" From 3736dcf792df3983175a4d1223c3bc5c81603466 Mon Sep 17 00:00:00 2001 From: Joan Sanchez Date: Tue, 10 Mar 2020 15:01:33 +0100 Subject: [PATCH 02/25] Added ticket sms options --- front/core/components/popover/index.js | 5 +++- modules/ticket/front/descriptor/index.js | 28 ++++++++++++++----- modules/ticket/front/descriptor/locale/en.yml | 5 ++-- modules/ticket/front/descriptor/locale/es.yml | 7 +++-- modules/ticket/front/index/locale/es.yml | 3 +- 5 files changed, 34 insertions(+), 14 deletions(-) diff --git a/front/core/components/popover/index.js b/front/core/components/popover/index.js index 7c54ce4949..96f1914f57 100644 --- a/front/core/components/popover/index.js +++ b/front/core/components/popover/index.js @@ -85,7 +85,10 @@ export default class Popover extends Popup { let maxWith = maxRight - margin; let maxHeight = maxBottom - margin - arrowHeight; - let width = clamp(popoverRect.width, parentRect.width, maxWith); + const scrollbarWidth = (popoverRect.width); + const innerEl = this.windowEl.querySelector('.content > *'); + console.log(innerEl); + let width = clamp(popoverRect.width, parentRect.width, maxWith) + 20; let height = popoverRect.height; let left = parentRect.left + parentRect.width / 2 - width / 2; diff --git a/modules/ticket/front/descriptor/index.js b/modules/ticket/front/descriptor/index.js index c633dd3c1e..478c1bd22d 100644 --- a/modules/ticket/front/descriptor/index.js +++ b/modules/ticket/front/descriptor/index.js @@ -16,7 +16,8 @@ class Controller extends Component { {name: 'Send Delivery Note', callback: this.confirmDeliveryNote}, {name: 'Delete ticket', callback: this.showDeleteTicketDialog}, {name: 'Change shipped hour', callback: this.showChangeShipped}, - {name: 'Send SMS', callback: this.showSMSDialog}, + {name: 'SMS: Pending payment', callback: this.sendPaymentSms}, + {name: 'SMS: Minimum import', callback: this.sendImportSms}, { name: 'Add stowaway', callback: this.showAddStowaway, @@ -240,17 +241,30 @@ class Controller extends Component { ); } + sendImportSms() { + const params = { + ticketId: this.ticket.id, + created: this.ticket.created + }; + const message = this.$params.message || this.$translate.instant('Minimum is needed', params); + this.newSMS = {message}; + this.showSMSDialog(); + } + + sendPaymentSms() { + const message = this.$params.message || this.$translate.instant('Make a payment'); + this.newSMS = {message}; + this.showSMSDialog(); + } + showSMSDialog() { const address = this.ticket.address; const client = this.ticket.client; const phone = this.$params.phone || address.mobile || address.phone || client.mobile || client.phone; - const message = this.$params.message || this.$translate.instant('SMSPayment'); - this.newSMS = { - destinationFk: this.ticket.clientFk, - destination: phone, - message: message - }; + + this.newSMS.destinationFk = this.ticket.clientFk; + this.newSMS.destination = phone; this.$.sms.open(); } diff --git a/modules/ticket/front/descriptor/locale/en.yml b/modules/ticket/front/descriptor/locale/en.yml index 4dca75a510..64075c7ef5 100644 --- a/modules/ticket/front/descriptor/locale/en.yml +++ b/modules/ticket/front/descriptor/locale/en.yml @@ -1,3 +1,2 @@ -SMSPayment: >- - Verdnatura communicates: Your order is pending of payment. - Please, enter the web page and make the payment with card. Thank you. \ No newline at end of file +Make a payment: "Verdnatura communicates:\rYour order is pending of payment.\rPlease, enter the web page and make the payment with card.\rThank you." +Minimum is needed: "Verdnatura communicates:\rA minimum import of 50€ (Without BAT) is needed for your order {{ticketId}} from date {{created | date: 'dd/MM/yyyy'}} to receive it with no extra fees." diff --git a/modules/ticket/front/descriptor/locale/es.yml b/modules/ticket/front/descriptor/locale/es.yml index 3df39fe28c..e2ea2f9aff 100644 --- a/modules/ticket/front/descriptor/locale/es.yml +++ b/modules/ticket/front/descriptor/locale/es.yml @@ -13,7 +13,8 @@ Send Delivery Note: Enviar albarán Show pallet report: Ver hoja de pallet Change shipped hour: Cambiar hora de envío Shipped hour: Hora de envío -SMSPayment: "Verdnatura le comunica:\rSu pedido está pendiente de pago.\rPor favor, entre en la página web y efectue el pago con tarjeta.\rMuchas gracias." +Make a payment: "Verdnatura le comunica:\rSu pedido está pendiente de pago.\rPor favor, entre en la página web y efectue el pago con tarjeta.\rMuchas gracias." +Minimum is needed: "Verdnatura le recuerda:\rEs necesario llegar a un importe mínimo de 50€ (Sin IVA) en su pedido {{ticketId}} del día {{created | date: 'dd/MM/yyyy'}} para recibirlo sin portes adicionales." Ticket invoiced: Ticket facturado Make invoice: Crear factura Regenerate invoice: Regenerar factura @@ -25,4 +26,6 @@ Invoice sent for a regeneration, will be available in a few minutes: La factura Shipped hour updated: Hora de envio modificada Deleted ticket: Ticket eliminado Recalculate components: Recalcular componentes -Are you sure you want to recalculate the components?: ¿Seguro que quieres recalcular los componentes? \ No newline at end of file +Are you sure you want to recalculate the components?: ¿Seguro que quieres recalcular los componentes? +SMS: Minimum import: 'SMS: Importe minimo' +SMS: Pending payment: 'SMS: Pago pendiente' \ No newline at end of file diff --git a/modules/ticket/front/index/locale/es.yml b/modules/ticket/front/index/locale/es.yml index b29c7399d3..dea55b199e 100644 --- a/modules/ticket/front/index/locale/es.yml +++ b/modules/ticket/front/index/locale/es.yml @@ -2,4 +2,5 @@ Weekly tickets: Tickets programados Go to lines: Ir a lineas Not available: No disponible Payment on account...: Pago a cuenta... -Closure: Cierre \ No newline at end of file +Closure: Cierre +You cannot make a payment on account from multiple clients: No puedes realizar un pago a cuenta de clientes diferentes \ No newline at end of file From 581e2fcd1f2a2b78b8fbdbb8d358354c48d4a93c Mon Sep 17 00:00:00 2001 From: Joan Sanchez Date: Wed, 11 Mar 2020 08:45:54 +0100 Subject: [PATCH 03/25] Updated unit test --- modules/ticket/front/descriptor/index.js | 4 +-- modules/ticket/front/descriptor/index.spec.js | 25 +++++++++++++++++-- modules/ticket/front/descriptor/locale/es.yml | 4 +-- 3 files changed, 27 insertions(+), 6 deletions(-) diff --git a/modules/ticket/front/descriptor/index.js b/modules/ticket/front/descriptor/index.js index 478c1bd22d..6ea2d18927 100644 --- a/modules/ticket/front/descriptor/index.js +++ b/modules/ticket/front/descriptor/index.js @@ -16,8 +16,8 @@ class Controller extends Component { {name: 'Send Delivery Note', callback: this.confirmDeliveryNote}, {name: 'Delete ticket', callback: this.showDeleteTicketDialog}, {name: 'Change shipped hour', callback: this.showChangeShipped}, - {name: 'SMS: Pending payment', callback: this.sendPaymentSms}, - {name: 'SMS: Minimum import', callback: this.sendImportSms}, + {name: 'SMS Pending payment', callback: this.sendPaymentSms}, + {name: 'SMS Minimum import', callback: this.sendImportSms}, { name: 'Add stowaway', callback: this.showAddStowaway, diff --git a/modules/ticket/front/descriptor/index.spec.js b/modules/ticket/front/descriptor/index.spec.js index a435618333..3f4b876828 100644 --- a/modules/ticket/front/descriptor/index.spec.js +++ b/modules/ticket/front/descriptor/index.spec.js @@ -20,7 +20,13 @@ describe('Ticket Component vnTicketDescriptor', () => { $httpBackend = _$httpBackend_; $httpParamSerializer = _$httpParamSerializer_; controller = $componentController('vnTicketDescriptor', {$element}); - controller._ticket = {id: 2, invoiceOut: {id: 1}, client: {id: 101, email: 'client@email'}}; + controller._ticket = { + id: 2, + clientFk: 101, + invoiceOut: {id: 1}, + client: {id: 101, email: 'client@email'}, + address: {id: 101, mobile: 111111111, phone: 2222222222} + }; controller.cardReload = ()=> { return true; }; @@ -161,7 +167,6 @@ describe('Ticket Component vnTicketDescriptor', () => { }); }); - describe('showAddStowaway()', () => { it('should show a dialog with a list of tickets available for an stowaway', () => { controller.$.addStowaway = {}; @@ -223,4 +228,20 @@ describe('Ticket Component vnTicketDescriptor', () => { expect(controller.vnApp.showSuccess).toHaveBeenCalledWith('Data saved!'); }); }); + + describe('showSMSDialog()', () => { + it('should set the destionationFk and destination properties and then call the sms open() method', () => { + controller.$.sms = {open: () => {}}; + jest.spyOn(controller.$.sms, 'open'); + + const clientId = 101; + const expectedPhone = 111111111; + controller.newSMS = {}; + controller.showSMSDialog(); + + expect(controller.newSMS.destinationFk).toEqual(clientId); + expect(controller.newSMS.destination).toEqual(expectedPhone); + expect(controller.$.sms.open).toHaveBeenCalledWith(); + }); + }); }); diff --git a/modules/ticket/front/descriptor/locale/es.yml b/modules/ticket/front/descriptor/locale/es.yml index e2ea2f9aff..d0e8b7bf57 100644 --- a/modules/ticket/front/descriptor/locale/es.yml +++ b/modules/ticket/front/descriptor/locale/es.yml @@ -27,5 +27,5 @@ Shipped hour updated: Hora de envio modificada Deleted ticket: Ticket eliminado Recalculate components: Recalcular componentes Are you sure you want to recalculate the components?: ¿Seguro que quieres recalcular los componentes? -SMS: Minimum import: 'SMS: Importe minimo' -SMS: Pending payment: 'SMS: Pago pendiente' \ No newline at end of file +SMS Minimum import: 'SMS Importe minimo' +SMS Pending payment: 'SMS Pago pendiente' \ No newline at end of file From 43ad139681ecd6596058a59830e51a5460cb37a1 Mon Sep 17 00:00:00 2001 From: Joan Sanchez Date: Wed, 11 Mar 2020 09:14:19 +0100 Subject: [PATCH 04/25] Updated selector --- e2e/helpers/selectors.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/e2e/helpers/selectors.js b/e2e/helpers/selectors.js index 2f1c5d893c..4eebe0d666 100644 --- a/e2e/helpers/selectors.js +++ b/e2e/helpers/selectors.js @@ -824,7 +824,7 @@ export default { travelThermograph: { add: 'vn-travel-thermograph-index vn-float-button[icon="add"]', thermographID: 'vn-travel-thermograph-create vn-autocomplete[ng-model="$ctrl.dms.thermographId"]', - uploadIcon: 'vn-travel-thermograph-create vn-icon[icon="attach_file"]', + uploadIcon: 'vn-travel-thermograph-create vn-icon[icon="icon-attach"]', createdThermograph: 'vn-travel-thermograph-index vn-tbody > vn-tr', upload: 'vn-travel-thermograph-create button[type=submit]' }, From 278839b2b39febf63e242f388f8569975b2ff5ec Mon Sep 17 00:00:00 2001 From: Joan Sanchez Date: Wed, 11 Mar 2020 09:15:23 +0100 Subject: [PATCH 05/25] Updated selector --- e2e/helpers/selectors.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/e2e/helpers/selectors.js b/e2e/helpers/selectors.js index 2f1c5d893c..4eebe0d666 100644 --- a/e2e/helpers/selectors.js +++ b/e2e/helpers/selectors.js @@ -824,7 +824,7 @@ export default { travelThermograph: { add: 'vn-travel-thermograph-index vn-float-button[icon="add"]', thermographID: 'vn-travel-thermograph-create vn-autocomplete[ng-model="$ctrl.dms.thermographId"]', - uploadIcon: 'vn-travel-thermograph-create vn-icon[icon="attach_file"]', + uploadIcon: 'vn-travel-thermograph-create vn-icon[icon="icon-attach"]', createdThermograph: 'vn-travel-thermograph-index vn-tbody > vn-tr', upload: 'vn-travel-thermograph-create button[type=submit]' }, From e92030ec6eea033e50895e632da7ab7dce7628e9 Mon Sep 17 00:00:00 2001 From: Bernat Exposito Domenech Date: Wed, 11 Mar 2020 09:17:14 +0100 Subject: [PATCH 06/25] test --- front/core/components/watcher/watcher.js | 1 - modules/travel/front/create/index.spec.js | 14 +++++--------- modules/travel/front/index/index.js | 1 - 3 files changed, 5 insertions(+), 11 deletions(-) diff --git a/front/core/components/watcher/watcher.js b/front/core/components/watcher/watcher.js index 04ccba45e6..0ab41edf95 100644 --- a/front/core/components/watcher/watcher.js +++ b/front/core/components/watcher/watcher.js @@ -186,7 +186,6 @@ export default class Watcher extends Component { * Checks if data is ready to send. */ isInvalid() { - console.log(this.form.$invalid); if (this.form && this.form.$invalid) throw new UserError('Some fields are invalid'); } diff --git a/modules/travel/front/create/index.spec.js b/modules/travel/front/create/index.spec.js index ef83d98ff1..e1095d35bc 100644 --- a/modules/travel/front/create/index.spec.js +++ b/modules/travel/front/create/index.spec.js @@ -29,18 +29,14 @@ describe('Travel Component vnTravelCreate', () => { describe('$onChanges()', () => { it('should update the travel data when stateParams.q is defined', () => { - controller.$stateParams = {q: { - ref: 1, - agencyModeFk: 1 - }}; + controller.$stateParams = {q: '{"ref": 1,"agencyModeFk": 1}'}; + + const params = {q: '{"ref": 1, "agencyModeFk": 1}'}; + const json = JSON.parse(params.q); - const result = {q: { - ref: 1, - agencyModeFk: 1 - }}; controller.$onChanges(); - expect(controller._travel).toBe(result); + expect(controller._travel).toEqual(json); }); }); }); diff --git a/modules/travel/front/index/index.js b/modules/travel/front/index/index.js index 8402d00a26..b3e24e0e61 100644 --- a/modules/travel/front/index/index.js +++ b/modules/travel/front/index/index.js @@ -45,7 +45,6 @@ export default class Controller { if (!(response == 'accept' && this.travelSelected)) return; if (this.travelSelected) { - console.log('this.travelSelected', this.travelSelected); const travel = { ref: this.travelSelected.ref, agencyModeFk: this.travelSelected.agencyFk, From 17c8336b232284be8de616ee2e592b40d0c99f2e Mon Sep 17 00:00:00 2001 From: Joan Sanchez Date: Wed, 11 Mar 2020 09:39:05 +0100 Subject: [PATCH 07/25] Removed popover changes --- front/core/components/popover/index.js | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/front/core/components/popover/index.js b/front/core/components/popover/index.js index 96f1914f57..7c54ce4949 100644 --- a/front/core/components/popover/index.js +++ b/front/core/components/popover/index.js @@ -85,10 +85,7 @@ export default class Popover extends Popup { let maxWith = maxRight - margin; let maxHeight = maxBottom - margin - arrowHeight; - const scrollbarWidth = (popoverRect.width); - const innerEl = this.windowEl.querySelector('.content > *'); - console.log(innerEl); - let width = clamp(popoverRect.width, parentRect.width, maxWith) + 20; + let width = clamp(popoverRect.width, parentRect.width, maxWith); let height = popoverRect.height; let left = parentRect.left + parentRect.width / 2 - width / 2; From 8fe6c651e3669a291fc4977a1830c694e7b32906 Mon Sep 17 00:00:00 2001 From: Joan Sanchez Date: Wed, 11 Mar 2020 12:02:12 +0100 Subject: [PATCH 08/25] Updated translations --- modules/ticket/front/sale/index.js | 7 +++---- modules/ticket/front/sale/locale/en.yml | 2 +- modules/ticket/front/sale/locale/es.yml | 3 ++- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/modules/ticket/front/sale/index.js b/modules/ticket/front/sale/index.js index e7bf61cfe0..6ccc05e9d3 100644 --- a/modules/ticket/front/sale/index.js +++ b/modules/ticket/front/sale/index.js @@ -12,7 +12,7 @@ class Controller { this.edit = {}; this.moreOptions = [ { - name: 'Send SMS', + name: 'Send shortage SMS', callback: this.showSMSDialog }, { name: 'Mark as reserved', @@ -179,10 +179,9 @@ class Controller { totalCheckedLines() { const checkedLines = this.checkedLines(); if (checkedLines) - return checkedLines.length; + return checkedLines.lengt; } - removeCheckedLines() { const sales = this.checkedLines(); @@ -448,7 +447,7 @@ class Controller { this.newSMS = { destinationFk: this.ticket.clientFk, destination: phone, - message: this.$translate.instant('SMSAvailability', params) + message: this.$translate.instant('Product not available', params) }; this.$scope.sms.open(); } diff --git a/modules/ticket/front/sale/locale/en.yml b/modules/ticket/front/sale/locale/en.yml index 469e2a04ed..ec7f541609 100644 --- a/modules/ticket/front/sale/locale/en.yml +++ b/modules/ticket/front/sale/locale/en.yml @@ -1,3 +1,3 @@ -SMSAvailability: >- +Product not available: >- Verdnatura communicates: Your order {{ticketFk}} created on {{created | date: "dd/MM/yyyy"}}. {{notAvailables}} not available. Sorry for the inconvenience. \ No newline at end of file diff --git a/modules/ticket/front/sale/locale/es.yml b/modules/ticket/front/sale/locale/es.yml index 74f888f569..8de8427b9a 100644 --- a/modules/ticket/front/sale/locale/es.yml +++ b/modules/ticket/front/sale/locale/es.yml @@ -24,7 +24,8 @@ Sales to transfer: Líneas a transferir Destination ticket: Ticket destinatario Change ticket state to 'Ok': Cambiar estado del ticket a 'Ok' Reserved: Reservado -SMSAvailability: "Verdnatura le comunica:\rPedido {{ticketFk}} día {{created | date: 'dd/MM/yyyy'}}.\r{{notAvailables}} no disponible/s.\rDisculpe las molestias." +Send shortage SMS: Enviar SMS faltas +Product not available: "Verdnatura le comunica:\rPedido {{ticketFk}} día {{created | date: 'dd/MM/yyyy'}}.\r{{notAvailables}} no disponible/s.\rDisculpe las molestias." Continue anyway?: ¿Continuar de todas formas? This ticket is now empty: El ticket ha quedado vacio Do you want to delete it?: ¿Quieres eliminarlo? From d0b0c9d0606d90d75356a8a01a6ae7dbc014079c Mon Sep 17 00:00:00 2001 From: Bernat Exposito Domenech Date: Wed, 11 Mar 2020 12:03:55 +0100 Subject: [PATCH 09/25] pull request changes --- front/core/components/watcher/watcher.js | 5 ++++- loopback/locale/es.json | 2 +- modules/travel/back/models/travel.js | 2 +- modules/travel/front/create/index.js | 12 +----------- modules/travel/front/create/index.spec.js | 2 +- modules/travel/front/index/locale/es.yml | 3 ++- 6 files changed, 10 insertions(+), 16 deletions(-) diff --git a/front/core/components/watcher/watcher.js b/front/core/components/watcher/watcher.js index 0ab41edf95..1a1abffa55 100644 --- a/front/core/components/watcher/watcher.js +++ b/front/core/components/watcher/watcher.js @@ -167,6 +167,9 @@ export default class Watcher extends Component { ); }); } + /** + * return the request method. + */ requestMethod() { return this.$attrs.save && this.$attrs.save.toLowerCase(); @@ -183,7 +186,7 @@ export default class Watcher extends Component { } /** - * Checks if data is ready to send. + * Checks if the form is valid. */ isInvalid() { if (this.form && this.form.$invalid) diff --git a/loopback/locale/es.json b/loopback/locale/es.json index e975185041..5f41c9931c 100644 --- a/loopback/locale/es.json +++ b/loopback/locale/es.json @@ -129,5 +129,5 @@ "ORDER_ROW_UNAVAILABLE": "No hay disponibilidad de este producto", "Distance must be lesser than 1000": "La distancia debe ser inferior a 1000", "This ticket is deleted": "Este ticket está eliminado", - "The introduced data already exists": "La información introducida ya existe" + "A travel with this data already exists": "Ya existe un travel con estos datos" } \ No newline at end of file diff --git a/modules/travel/back/models/travel.js b/modules/travel/back/models/travel.js index a7c045b314..b47742c263 100644 --- a/modules/travel/back/models/travel.js +++ b/modules/travel/back/models/travel.js @@ -10,7 +10,7 @@ module.exports = Self => { Self.rewriteDbError(function(err) { if (err.code === 'ER_DUP_ENTRY') - return new UserError('The introduced data already exists'); + return new UserError('A travel with this data already exists'); return err; }); }; diff --git a/modules/travel/front/create/index.js b/modules/travel/front/create/index.js index 513e1e0b13..0d5a2cc018 100644 --- a/modules/travel/front/create/index.js +++ b/modules/travel/front/create/index.js @@ -5,21 +5,11 @@ class Controller extends Section { constructor($element, $, $stateParams) { super($element, $); this.$stateParams = $stateParams; - this.travel = {}; } $onChanges() { if (this.$stateParams && this.$stateParams.q) - this._travel = JSON.parse(this.$stateParams.q); - } - - get travel() { - return this._travel; - } - - set travel(value) { - this._travel = value; - if (!value) return; + this.travel = JSON.parse(this.$stateParams.q); } onSubmit() { diff --git a/modules/travel/front/create/index.spec.js b/modules/travel/front/create/index.spec.js index e1095d35bc..a6fa5a9b18 100644 --- a/modules/travel/front/create/index.spec.js +++ b/modules/travel/front/create/index.spec.js @@ -36,7 +36,7 @@ describe('Travel Component vnTravelCreate', () => { controller.$onChanges(); - expect(controller._travel).toEqual(json); + expect(controller.travel).toEqual(json); }); }); }); diff --git a/modules/travel/front/index/locale/es.yml b/modules/travel/front/index/locale/es.yml index 63d23affdd..5ce4c502f4 100644 --- a/modules/travel/front/index/locale/es.yml +++ b/modules/travel/front/index/locale/es.yml @@ -1,2 +1,3 @@ Do you want to clone this travel?: ¿Desea clonar este envio? -All it's properties will be copied: Todas sus propiedades serán copiadas \ No newline at end of file +All it's properties will be copied: Todas sus propiedades serán copiadas +Clone: Clonar \ No newline at end of file From 14d471fc3225466e498dc0ee5c1ce9876e9e6574 Mon Sep 17 00:00:00 2001 From: Joan Sanchez Date: Wed, 11 Mar 2020 12:20:15 +0100 Subject: [PATCH 10/25] 2187 - Sort by translated module name --- front/core/services/modules.js | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/front/core/services/modules.js b/front/core/services/modules.js index 1021bc4fab..6b4e9dfe1f 100644 --- a/front/core/services/modules.js +++ b/front/core/services/modules.js @@ -2,10 +2,11 @@ import ngModule from '../module'; import getMainRoute from '../lib/get-main-route'; export default class Modules { - constructor(aclService, $window) { + constructor(aclService, $window, $translate) { Object.assign(this, { aclService, - $window + $window, + $translate }); } @@ -17,7 +18,7 @@ export default class Modules { if (this.modules) return this.modules; - this.modules = []; + const modules = []; for (let mod of this.$window.routes) { if (!mod || !mod.routes) continue; @@ -31,7 +32,7 @@ export default class Modules { if (res) keyBind = res.key.toUpperCase(); } - this.modules.push({ + modules.push({ name: mod.name || mod.module, icon: mod.icon || null, route, @@ -39,9 +40,15 @@ export default class Modules { }); } - return this.modules; + const sortedModules = modules.sort((a, b) => { + const translatedNameA = this.$translate.instant(a.name); + const translatedNameB = this.$translate.instant(b.name); + return translatedNameA.localeCompare(translatedNameB); + }); + + return sortedModules; } } -Modules.$inject = ['aclService', '$window']; +Modules.$inject = ['aclService', '$window', '$translate']; ngModule.service('vnModules', Modules); From 1086e13b2e904f7821c7b8efad7c42333f67e77d Mon Sep 17 00:00:00 2001 From: Joan Sanchez Date: Wed, 11 Mar 2020 12:20:15 +0100 Subject: [PATCH 11/25] 2187 - Sort by translated module name --- front/core/services/modules.js | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/front/core/services/modules.js b/front/core/services/modules.js index 1021bc4fab..6b4e9dfe1f 100644 --- a/front/core/services/modules.js +++ b/front/core/services/modules.js @@ -2,10 +2,11 @@ import ngModule from '../module'; import getMainRoute from '../lib/get-main-route'; export default class Modules { - constructor(aclService, $window) { + constructor(aclService, $window, $translate) { Object.assign(this, { aclService, - $window + $window, + $translate }); } @@ -17,7 +18,7 @@ export default class Modules { if (this.modules) return this.modules; - this.modules = []; + const modules = []; for (let mod of this.$window.routes) { if (!mod || !mod.routes) continue; @@ -31,7 +32,7 @@ export default class Modules { if (res) keyBind = res.key.toUpperCase(); } - this.modules.push({ + modules.push({ name: mod.name || mod.module, icon: mod.icon || null, route, @@ -39,9 +40,15 @@ export default class Modules { }); } - return this.modules; + const sortedModules = modules.sort((a, b) => { + const translatedNameA = this.$translate.instant(a.name); + const translatedNameB = this.$translate.instant(b.name); + return translatedNameA.localeCompare(translatedNameB); + }); + + return sortedModules; } } -Modules.$inject = ['aclService', '$window']; +Modules.$inject = ['aclService', '$window', '$translate']; ngModule.service('vnModules', Modules); From 1c8541376b513b34d41f195285bc3aa4f8fc9e62 Mon Sep 17 00:00:00 2001 From: Joan Sanchez Date: Wed, 11 Mar 2020 12:54:28 +0100 Subject: [PATCH 12/25] Fixed removed letter --- modules/ticket/front/sale/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/ticket/front/sale/index.js b/modules/ticket/front/sale/index.js index 6ccc05e9d3..42ff5f116a 100644 --- a/modules/ticket/front/sale/index.js +++ b/modules/ticket/front/sale/index.js @@ -179,7 +179,7 @@ class Controller { totalCheckedLines() { const checkedLines = this.checkedLines(); if (checkedLines) - return checkedLines.lengt; + return checkedLines.length; } removeCheckedLines() { From 91c354e3947f5df8ef01990cc09dd550c36d98dd Mon Sep 17 00:00:00 2001 From: Joan Sanchez Date: Wed, 11 Mar 2020 12:57:49 +0100 Subject: [PATCH 13/25] Removed console.log --- front/core/directives/specs/http-click.spec.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/front/core/directives/specs/http-click.spec.js b/front/core/directives/specs/http-click.spec.js index 70a79bcffc..1b0979f13b 100644 --- a/front/core/directives/specs/http-click.spec.js +++ b/front/core/directives/specs/http-click.spec.js @@ -60,7 +60,7 @@ describe('Directive http-click', () => { }).finally(() => { expect(finalValue).toEqual('called!'); }).catch(err => { - console.log(err); + throw err; }); }); }); From aba24292cf1057fc70a80a464132b5d16c70f511 Mon Sep 17 00:00:00 2001 From: Joan Sanchez Date: Wed, 11 Mar 2020 13:36:56 +0100 Subject: [PATCH 14/25] Module translations --- front/core/services/modules.js | 3 ++- front/salix/components/home/home.html | 2 +- modules/ticket/front/sale/index.js | 1 - 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/front/core/services/modules.js b/front/core/services/modules.js index 6b4e9dfe1f..874a4a97b0 100644 --- a/front/core/services/modules.js +++ b/front/core/services/modules.js @@ -45,8 +45,9 @@ export default class Modules { const translatedNameB = this.$translate.instant(b.name); return translatedNameA.localeCompare(translatedNameB); }); + this.modules = sortedModules; - return sortedModules; + return this.modules; } } Modules.$inject = ['aclService', '$window', '$translate']; diff --git a/front/salix/components/home/home.html b/front/salix/components/home/home.html index b3fc02d0db..ada51d76fb 100644 --- a/front/salix/components/home/home.html +++ b/front/salix/components/home/home.html @@ -8,7 +8,7 @@
-

+

diff --git a/modules/ticket/front/sale/index.js b/modules/ticket/front/sale/index.js index e7bf61cfe0..ff7daba03b 100644 --- a/modules/ticket/front/sale/index.js +++ b/modules/ticket/front/sale/index.js @@ -182,7 +182,6 @@ class Controller { return checkedLines.length; } - removeCheckedLines() { const sales = this.checkedLines(); From b9a482fc37b7ed8d818aa104204e1a3707d977ef Mon Sep 17 00:00:00 2001 From: Joan Sanchez Date: Wed, 11 Mar 2020 15:56:02 +0100 Subject: [PATCH 15/25] 2181 - Ticket sale fix item search --- modules/item/back/models/item.json | 7 +++++++ modules/ticket/front/sale/index.html | 20 ++++++++++++-------- modules/ticket/front/sale/index.js | 6 ++++++ 3 files changed, 25 insertions(+), 8 deletions(-) diff --git a/modules/item/back/models/item.json b/modules/item/back/models/item.json index dbaa3a4090..5d2e47d2a3 100644 --- a/modules/item/back/models/item.json +++ b/modules/item/back/models/item.json @@ -175,5 +175,12 @@ "model": "ItemNiche", "foreignKey": "itemFk" } + }, + "scope": { + "where": { + "name": { + "neq": "" + } + } } } \ No newline at end of file diff --git a/modules/ticket/front/sale/index.html b/modules/ticket/front/sale/index.html index 41ef74c38d..9fb0337f23 100644 --- a/modules/ticket/front/sale/index.html +++ b/modules/ticket/front/sale/index.html @@ -105,20 +105,22 @@ on-error-src/>
- - {{sale.itemFk | zeroFill:6}} + {{sale.itemFk}} + search-function="$ctrl.itemSearchFunc($search)" + on-change="sale.quantity && $ctrl.onChangeQuantity(sale)" + order="id DESC" + tabindex="1"> {{id}} - {{name}} @@ -137,7 +139,8 @@ + on-change="$ctrl.onChangeQuantity(sale)" + tabindex="2"> @@ -150,7 +153,7 @@ - @@ -167,7 +170,8 @@ + ng-click="$ctrl.showEditDiscountPopover($event, sale)" + ng-if="sale.id"> {{(sale.discount / 100) | percentage}} diff --git a/modules/ticket/front/sale/index.js b/modules/ticket/front/sale/index.js index 42ff5f116a..09b5c7deaf 100644 --- a/modules/ticket/front/sale/index.js +++ b/modules/ticket/front/sale/index.js @@ -560,6 +560,12 @@ class Controller { this.$scope.model.refresh(); }); } + + itemSearchFunc($search) { + return /^\d+$/.test($search) + ? {id: $search} + : {name: {like: '%' + $search + '%'}}; + } } Controller.$inject = ['$scope', '$state', '$http', 'vnApp', '$translate']; From 6798f9709c1baa5e147323659948644f498f2963 Mon Sep 17 00:00:00 2001 From: Bernat Exposito Domenech Date: Thu, 12 Mar 2020 10:59:41 +0100 Subject: [PATCH 16/25] update view holiday --- .../worker/back/methods/holiday/getByWarehouse.js | 12 ++++++------ modules/worker/back/model-config.json | 2 +- .../back/models/{holiday.js => calendar-holiday.js} | 0 .../models/{holiday.json => calendar-holiday.json} | 8 ++++---- modules/worker/back/models/work-center.json | 2 +- 5 files changed, 12 insertions(+), 12 deletions(-) rename modules/worker/back/models/{holiday.js => calendar-holiday.js} (100%) rename modules/worker/back/models/{holiday.json => calendar-holiday.json} (85%) diff --git a/modules/worker/back/methods/holiday/getByWarehouse.js b/modules/worker/back/methods/holiday/getByWarehouse.js index 8a7fd8be37..093885d137 100644 --- a/modules/worker/back/methods/holiday/getByWarehouse.js +++ b/modules/worker/back/methods/holiday/getByWarehouse.js @@ -23,12 +23,12 @@ module.exports = Self => { beginningYear.setHours(0, 0, 0, 0); let holidays = await Self.rawSql( - `SELECT lh.dated, chn.name, cht.name, w.id - FROM vn.holiday lh - JOIN vn.workCenter w ON w.id = lh.workcenterFk - LEFT JOIN vn.calendarHolidaysName chn ON chn.id = lh.holidayDetailFk - LEFT JOIN vn.calendarHolidaysType cht ON cht.id = lh.holidayTypeFk - WHERE w.warehouseFk = ? AND lh.dated >= ?`, [warehouseFk, beginningYear]); + `SELECT clh.dated, chn.name, cht.name, w.id + FROM vn.calendarHolidays clh + JOIN vn.workCenter w ON w.id = clh.workcenterFk + LEFT JOIN vn.calendarHolidaysName chn ON chn.id = clh.calendarHolidaysNameFk + LEFT JOIN vn.calendarHolidaysType cht ON cht.id = clh.calendarHolidaysTypeFk + WHERE w.warehouseFk = ? AND clh.dated >= ?`, [warehouseFk, beginningYear]); return holidays.map(holiday => { holiday.dated = new Date(holiday.dated); diff --git a/modules/worker/back/model-config.json b/modules/worker/back/model-config.json index 5b9136f68c..884759bc95 100644 --- a/modules/worker/back/model-config.json +++ b/modules/worker/back/model-config.json @@ -5,7 +5,7 @@ "Department": { "dataSource": "vn" }, - "Holiday": { + "CalendarHoliday": { "dataSource": "vn" }, "CalendarHolidaysName": { diff --git a/modules/worker/back/models/holiday.js b/modules/worker/back/models/calendar-holiday.js similarity index 100% rename from modules/worker/back/models/holiday.js rename to modules/worker/back/models/calendar-holiday.js diff --git a/modules/worker/back/models/holiday.json b/modules/worker/back/models/calendar-holiday.json similarity index 85% rename from modules/worker/back/models/holiday.json rename to modules/worker/back/models/calendar-holiday.json index a820c0d518..0956893aec 100644 --- a/modules/worker/back/models/holiday.json +++ b/modules/worker/back/models/calendar-holiday.json @@ -1,17 +1,17 @@ { - "name": "Holiday", + "name": "CalendarHoliday", "base": "VnModel", "options": { "mysql": { - "table": "holiday" + "table": "calendarHolidays" } }, "properties": { - "holidayDetailFk": { + "calendarHolidaysNameFk": { "id": true, "type": "Number" }, - "holidayTypeFk": { + "calendarHolidaysTypeFk": { "id": true, "type": "Number" }, diff --git a/modules/worker/back/models/work-center.json b/modules/worker/back/models/work-center.json index 03a3350223..a0e651bba5 100644 --- a/modules/worker/back/models/work-center.json +++ b/modules/worker/back/models/work-center.json @@ -23,7 +23,7 @@ }, "holidays": { "type": "hasMany", - "model": "Holiday", + "model": "CalendarHoliday", "foreignKey": "workCenterFk" } }, From d51356f11b91b060fd7241e721d879e0e2af4898 Mon Sep 17 00:00:00 2001 From: Joan Sanchez Date: Fri, 13 Mar 2020 08:20:30 +0100 Subject: [PATCH 17/25] Add line on change item --- modules/ticket/front/sale/index.html | 2 +- modules/ticket/front/sale/index.js | 8 +++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/modules/ticket/front/sale/index.html b/modules/ticket/front/sale/index.html index 9fb0337f23..b050d3579f 100644 --- a/modules/ticket/front/sale/index.html +++ b/modules/ticket/front/sale/index.html @@ -118,7 +118,7 @@ show-field="name" value-field="id" search-function="$ctrl.itemSearchFunc($search)" - on-change="sale.quantity && $ctrl.onChangeQuantity(sale)" + on-change="$ctrl.onChangeQuantity(sale)" order="id DESC" tabindex="1"> diff --git a/modules/ticket/front/sale/index.js b/modules/ticket/front/sale/index.js index 09b5c7deaf..c5e947d237 100644 --- a/modules/ticket/front/sale/index.js +++ b/modules/ticket/front/sale/index.js @@ -464,10 +464,12 @@ class Controller { * Updates the sale quantity for existing instance */ onChangeQuantity(sale) { + if (!sale.quantity) return; + if (!sale.id) - this.addSale(sale); - else - this.updateQuantity(sale); + return this.addSale(sale); + + this.updateQuantity(sale); } /* From f8c69306f4672e1105bbcd1a806a0bb36ad322ec Mon Sep 17 00:00:00 2001 From: Joan Sanchez Date: Fri, 13 Mar 2020 08:44:01 +0100 Subject: [PATCH 18/25] Updated unit test --- modules/ticket/front/sale/specs/index.spec.js | 35 ++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/modules/ticket/front/sale/specs/index.spec.js b/modules/ticket/front/sale/specs/index.spec.js index 2e7979faa0..14000e01af 100644 --- a/modules/ticket/front/sale/specs/index.spec.js +++ b/modules/ticket/front/sale/specs/index.spec.js @@ -2,7 +2,7 @@ import '../index.js'; import watcher from 'core/mocks/watcher'; import crudModel from 'core/mocks/crud-model'; -describe('Ticket', () => { +fdescribe('Ticket', () => { describe('Component vnTicketSale', () => { let controller; let $scope; @@ -207,6 +207,39 @@ describe('Ticket', () => { }); }); + describe('onChangeQuantity()', () => { + it('should not call addSale() or updateQuantity() methods', () => { + jest.spyOn(controller, 'addSale'); + jest.spyOn(controller, 'updateQuantity'); + + const sale = {itemFk: 4}; + controller.onChangeQuantity(sale); + + expect(controller.addSale).not.toHaveBeenCalled(); + expect(controller.updateQuantity).not.toHaveBeenCalled(); + }); + + it('should call addSale() method', () => { + jest.spyOn(controller, 'addSale'); + + const sale = {itemFk: 4, quantity: 5}; + controller.onChangeQuantity(sale); + + expect(controller.addSale).toHaveBeenCalledWith(sale); + }); + + it('should call updateQuantity() method', () => { + jest.spyOn(controller, 'updateQuantity'); + jest.spyOn(controller, 'addSale'); + + const sale = {id: 1, itemFk: 4, quantity: 5}; + controller.onChangeQuantity(sale); + + expect(controller.addSale).not.toHaveBeenCalled(); + expect(controller.updateQuantity).toHaveBeenCalledWith(sale); + }); + }); + describe('updateQuantity()', () => { it('should make a POST query saving sale quantity', () => { jest.spyOn(controller.$scope.watcher, 'updateOriginalData'); From 2d755c90944feadc86e1df691a8002a24016e7d2 Mon Sep 17 00:00:00 2001 From: Joan Sanchez Date: Fri, 13 Mar 2020 08:47:41 +0100 Subject: [PATCH 19/25] Updated unit test --- modules/ticket/front/sale/specs/index.spec.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/ticket/front/sale/specs/index.spec.js b/modules/ticket/front/sale/specs/index.spec.js index 14000e01af..3b0f04a82c 100644 --- a/modules/ticket/front/sale/specs/index.spec.js +++ b/modules/ticket/front/sale/specs/index.spec.js @@ -2,7 +2,7 @@ import '../index.js'; import watcher from 'core/mocks/watcher'; import crudModel from 'core/mocks/crud-model'; -fdescribe('Ticket', () => { +describe('Ticket', () => { describe('Component vnTicketSale', () => { let controller; let $scope; From 298e52e055e61f0649a9e231fb05c2c2806d3534 Mon Sep 17 00:00:00 2001 From: Joan Sanchez Date: Fri, 13 Mar 2020 10:49:44 +0100 Subject: [PATCH 20/25] 2193 - Chrome datalist hotfix --- front/core/components/datalist/index.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/front/core/components/datalist/index.js b/front/core/components/datalist/index.js index d52e6ca230..d74de46438 100644 --- a/front/core/components/datalist/index.js +++ b/front/core/components/datalist/index.js @@ -14,6 +14,9 @@ export default class Datalist extends Textfield { this.buildInput('text'); this.input.setAttribute('autocomplete', 'off'); + this.input.addEventListener('blur', () => { + console.log('focus out'); + }); } get field() { @@ -258,7 +261,8 @@ export default class Datalist extends Textfield { fragment.appendChild(option); } - list.appendChild(fragment); + this.$.$applyAsync(() => + list.appendChild(fragment)); } } From ba19c9069a178b3b158216d140972197b9c2ff51 Mon Sep 17 00:00:00 2001 From: Joan Sanchez Date: Fri, 13 Mar 2020 10:52:56 +0100 Subject: [PATCH 21/25] Removed event --- front/core/components/datalist/index.js | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/front/core/components/datalist/index.js b/front/core/components/datalist/index.js index d74de46438..3ac787d462 100644 --- a/front/core/components/datalist/index.js +++ b/front/core/components/datalist/index.js @@ -13,10 +13,7 @@ export default class Datalist extends Textfield { this._selection = null; this.buildInput('text'); - this.input.setAttribute('autocomplete', 'off'); - this.input.addEventListener('blur', () => { - console.log('focus out'); - }); + this.autocomplete = 'off'; } get field() { From 269bd8e69a64212192c7f6c49a2fd0c436439073 Mon Sep 17 00:00:00 2001 From: Joan Sanchez Date: Wed, 11 Mar 2020 15:56:02 +0100 Subject: [PATCH 22/25] 2181 - Ticket sale fix item search --- modules/item/back/models/item.json | 7 +++++++ modules/ticket/front/sale/index.html | 20 ++++++++++++-------- modules/ticket/front/sale/index.js | 6 ++++++ 3 files changed, 25 insertions(+), 8 deletions(-) diff --git a/modules/item/back/models/item.json b/modules/item/back/models/item.json index dbaa3a4090..5d2e47d2a3 100644 --- a/modules/item/back/models/item.json +++ b/modules/item/back/models/item.json @@ -175,5 +175,12 @@ "model": "ItemNiche", "foreignKey": "itemFk" } + }, + "scope": { + "where": { + "name": { + "neq": "" + } + } } } \ No newline at end of file diff --git a/modules/ticket/front/sale/index.html b/modules/ticket/front/sale/index.html index 41ef74c38d..9fb0337f23 100644 --- a/modules/ticket/front/sale/index.html +++ b/modules/ticket/front/sale/index.html @@ -105,20 +105,22 @@ on-error-src/> - - {{sale.itemFk | zeroFill:6}} + {{sale.itemFk}} + search-function="$ctrl.itemSearchFunc($search)" + on-change="sale.quantity && $ctrl.onChangeQuantity(sale)" + order="id DESC" + tabindex="1"> {{id}} - {{name}} @@ -137,7 +139,8 @@ + on-change="$ctrl.onChangeQuantity(sale)" + tabindex="2"> @@ -150,7 +153,7 @@ - @@ -167,7 +170,8 @@ + ng-click="$ctrl.showEditDiscountPopover($event, sale)" + ng-if="sale.id"> {{(sale.discount / 100) | percentage}} diff --git a/modules/ticket/front/sale/index.js b/modules/ticket/front/sale/index.js index ff7daba03b..fd52bd970d 100644 --- a/modules/ticket/front/sale/index.js +++ b/modules/ticket/front/sale/index.js @@ -560,6 +560,12 @@ class Controller { this.$scope.model.refresh(); }); } + + itemSearchFunc($search) { + return /^\d+$/.test($search) + ? {id: $search} + : {name: {like: '%' + $search + '%'}}; + } } Controller.$inject = ['$scope', '$state', '$http', 'vnApp', '$translate']; From d9176728b07469c170c7f36cff2a137ec3120902 Mon Sep 17 00:00:00 2001 From: Joan Sanchez Date: Fri, 13 Mar 2020 08:20:30 +0100 Subject: [PATCH 23/25] Add line on change item --- modules/ticket/front/sale/index.html | 2 +- modules/ticket/front/sale/index.js | 8 +++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/modules/ticket/front/sale/index.html b/modules/ticket/front/sale/index.html index 9fb0337f23..b050d3579f 100644 --- a/modules/ticket/front/sale/index.html +++ b/modules/ticket/front/sale/index.html @@ -118,7 +118,7 @@ show-field="name" value-field="id" search-function="$ctrl.itemSearchFunc($search)" - on-change="sale.quantity && $ctrl.onChangeQuantity(sale)" + on-change="$ctrl.onChangeQuantity(sale)" order="id DESC" tabindex="1"> diff --git a/modules/ticket/front/sale/index.js b/modules/ticket/front/sale/index.js index fd52bd970d..0b4b8f176d 100644 --- a/modules/ticket/front/sale/index.js +++ b/modules/ticket/front/sale/index.js @@ -464,10 +464,12 @@ class Controller { * Updates the sale quantity for existing instance */ onChangeQuantity(sale) { + if (!sale.quantity) return; + if (!sale.id) - this.addSale(sale); - else - this.updateQuantity(sale); + return this.addSale(sale); + + this.updateQuantity(sale); } /* From db89e3f5d428ad80ea0ce6fcadcfa6fac04e026f Mon Sep 17 00:00:00 2001 From: Joan Sanchez Date: Fri, 13 Mar 2020 08:44:01 +0100 Subject: [PATCH 24/25] Updated unit test --- modules/ticket/front/sale/specs/index.spec.js | 35 ++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/modules/ticket/front/sale/specs/index.spec.js b/modules/ticket/front/sale/specs/index.spec.js index 2e7979faa0..14000e01af 100644 --- a/modules/ticket/front/sale/specs/index.spec.js +++ b/modules/ticket/front/sale/specs/index.spec.js @@ -2,7 +2,7 @@ import '../index.js'; import watcher from 'core/mocks/watcher'; import crudModel from 'core/mocks/crud-model'; -describe('Ticket', () => { +fdescribe('Ticket', () => { describe('Component vnTicketSale', () => { let controller; let $scope; @@ -207,6 +207,39 @@ describe('Ticket', () => { }); }); + describe('onChangeQuantity()', () => { + it('should not call addSale() or updateQuantity() methods', () => { + jest.spyOn(controller, 'addSale'); + jest.spyOn(controller, 'updateQuantity'); + + const sale = {itemFk: 4}; + controller.onChangeQuantity(sale); + + expect(controller.addSale).not.toHaveBeenCalled(); + expect(controller.updateQuantity).not.toHaveBeenCalled(); + }); + + it('should call addSale() method', () => { + jest.spyOn(controller, 'addSale'); + + const sale = {itemFk: 4, quantity: 5}; + controller.onChangeQuantity(sale); + + expect(controller.addSale).toHaveBeenCalledWith(sale); + }); + + it('should call updateQuantity() method', () => { + jest.spyOn(controller, 'updateQuantity'); + jest.spyOn(controller, 'addSale'); + + const sale = {id: 1, itemFk: 4, quantity: 5}; + controller.onChangeQuantity(sale); + + expect(controller.addSale).not.toHaveBeenCalled(); + expect(controller.updateQuantity).toHaveBeenCalledWith(sale); + }); + }); + describe('updateQuantity()', () => { it('should make a POST query saving sale quantity', () => { jest.spyOn(controller.$scope.watcher, 'updateOriginalData'); From d2346471129c16dd37bd092904dff1061e2afb5b Mon Sep 17 00:00:00 2001 From: Joan Sanchez Date: Fri, 13 Mar 2020 08:47:41 +0100 Subject: [PATCH 25/25] Updated unit test --- modules/ticket/front/sale/specs/index.spec.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/ticket/front/sale/specs/index.spec.js b/modules/ticket/front/sale/specs/index.spec.js index 14000e01af..3b0f04a82c 100644 --- a/modules/ticket/front/sale/specs/index.spec.js +++ b/modules/ticket/front/sale/specs/index.spec.js @@ -2,7 +2,7 @@ import '../index.js'; import watcher from 'core/mocks/watcher'; import crudModel from 'core/mocks/crud-model'; -fdescribe('Ticket', () => { +describe('Ticket', () => { describe('Component vnTicketSale', () => { let controller; let $scope;