diff --git a/front/core/components/snackbar/snackbar.js b/front/core/components/snackbar/snackbar.js index 14d920211..e68c22f3f 100644 --- a/front/core/components/snackbar/snackbar.js +++ b/front/core/components/snackbar/snackbar.js @@ -34,7 +34,7 @@ export default class Controller extends Component { button.addEventListener('click', () => this.onButtonClick(shape)); element.appendChild(button); - let buttonText = shape.actionText || this.$t('Hide'); + let buttonText = '✖'; buttonText = document.createTextNode(buttonText); button.appendChild(buttonText); diff --git a/front/core/components/snackbar/style.scss b/front/core/components/snackbar/style.scss index 465c53851..23e8223e5 100644 --- a/front/core/components/snackbar/style.scss +++ b/front/core/components/snackbar/style.scss @@ -19,7 +19,7 @@ vn-snackbar .shape { border-radius: 3px; margin-bottom: 15px; color: white; - padding: 12px; + padding: 12px 25px 12px 12px; & > .text { text-align: center; @@ -55,13 +55,13 @@ vn-snackbar .shape { & > button { background-color: transparent; text-transform: uppercase; - margin-left: 8px; font-weight: bold; cursor: pointer; color: $color-main; - float: right; + position: absolute; border: none; - padding: 8px; - margin: -8px; + padding: 5px; + top: 0; + right: 0 } } \ No newline at end of file diff --git a/modules/supplier/back/models/supplier.json b/modules/supplier/back/models/supplier.json index 9567be785..30ed721a5 100644 --- a/modules/supplier/back/models/supplier.json +++ b/modules/supplier/back/models/supplier.json @@ -150,6 +150,11 @@ "model": "SageWithholding", "foreignKey": "sageWithholdingFk" }, + "contacts": { + "type": "hasMany", + "model": "SupplierContact", + "foreignKey": "supplierFk" + }, "addresses": { "type": "hasMany", "model": "SupplierAddress", diff --git a/modules/supplier/front/consumption/index.js b/modules/supplier/front/consumption/index.js index 9e1357a9f..21a30929d 100644 --- a/modules/supplier/front/consumption/index.js +++ b/modules/supplier/front/consumption/index.js @@ -37,7 +37,27 @@ class Controller extends Section { } sendEmail() { - this.vnEmail.send('supplier-campaign-metrics', this.reportParams); + const params = { + filter: { + where: { + supplierFk: this.$params.id, + email: {neq: null} + }, + limit: 1 + } + }; + this.$http.get('SupplierContacts', params).then(({data}) => { + if (data.length) { + const contact = data[0]; + const params = Object.assign({ + recipient: contact.email + }, this.reportParams); + this.vnEmail.send('supplier-campaign-metrics', params); + } else { + const message = this.$t(`This supplier doesn't have a contact with an email address`); + this.vnApp.showError(message); + } + }); } getTotal(entry) { diff --git a/modules/supplier/front/consumption/index.spec.js b/modules/supplier/front/consumption/index.spec.js index 35eb6935c..d095a174b 100644 --- a/modules/supplier/front/consumption/index.spec.js +++ b/modules/supplier/front/consumption/index.spec.js @@ -7,6 +7,7 @@ describe('Supplier', () => { let controller; let $httpParamSerializer; let $httpBackend; + const supplierId = 2; beforeEach(ngModule('supplier')); @@ -17,8 +18,9 @@ describe('Supplier', () => { const $element = angular.element(' { }); describe('sendEmail()', () => { + it('should throw an error', () => { + jest.spyOn(controller.vnApp, 'showError'); + + const expectedParams = { + filter: { + where: { + supplierFk: supplierId, + email: {neq: null} + }, + limit: 1 + } + }; + const serializedParams = $httpParamSerializer(expectedParams); + $httpBackend.expectGET(`SupplierContacts?${serializedParams}`).respond({}); + controller.sendEmail(); + $httpBackend.flush(); + + expect(controller.vnApp.showError).toHaveBeenCalledWith(`This supplier doesn't have a contact with an email address`); + }); + it('should make a GET query sending the report', () => { + let serializedParams; + const params = { + filter: { + where: { + supplierFk: supplierId, + email: {neq: null} + }, + limit: 1 + } + }; + serializedParams = $httpParamSerializer(params); + $httpBackend.whenGET(`SupplierContacts?${serializedParams}`).respond([ + {id: 1, email: 'batman@gothamcity.com'} + ]); + const now = new Date(); controller.$.model.userParams = { from: now, @@ -55,11 +92,12 @@ describe('Supplier', () => { }; const expectedParams = { recipientId: 2, + recipient: 'batman@gothamcity.com', from: now, to: now }; - const serializedParams = $httpParamSerializer(expectedParams); + serializedParams = $httpParamSerializer(expectedParams); const path = `email/supplier-campaign-metrics?${serializedParams}`; $httpBackend.expect('GET', path).respond({}); diff --git a/modules/supplier/front/consumption/locale/es.yml b/modules/supplier/front/consumption/locale/es.yml index dd052696c..6ef67ab2b 100644 --- a/modules/supplier/front/consumption/locale/es.yml +++ b/modules/supplier/front/consumption/locale/es.yml @@ -1,2 +1,3 @@ Total entry: Total entrada +This supplier doesn't have a contact with an email address: Este proveedor no tiene ningún contacto con una dirección de email \ No newline at end of file