2727 - Send consumption report to an email address #615
|
@ -34,7 +34,7 @@ export default class Controller extends Component {
|
||||||
button.addEventListener('click', () => this.onButtonClick(shape));
|
button.addEventListener('click', () => this.onButtonClick(shape));
|
||||||
element.appendChild(button);
|
element.appendChild(button);
|
||||||
|
|
||||||
let buttonText = shape.actionText || this.$t('Hide');
|
let buttonText = '✖';
|
||||||
buttonText = document.createTextNode(buttonText);
|
buttonText = document.createTextNode(buttonText);
|
||||||
button.appendChild(buttonText);
|
button.appendChild(buttonText);
|
||||||
|
|
||||||
|
|
|
@ -19,7 +19,7 @@ vn-snackbar .shape {
|
||||||
border-radius: 3px;
|
border-radius: 3px;
|
||||||
margin-bottom: 15px;
|
margin-bottom: 15px;
|
||||||
color: white;
|
color: white;
|
||||||
padding: 12px;
|
padding: 12px 25px 12px 12px;
|
||||||
|
|
||||||
& > .text {
|
& > .text {
|
||||||
text-align: center;
|
text-align: center;
|
||||||
|
@ -55,13 +55,13 @@ vn-snackbar .shape {
|
||||||
& > button {
|
& > button {
|
||||||
background-color: transparent;
|
background-color: transparent;
|
||||||
text-transform: uppercase;
|
text-transform: uppercase;
|
||||||
margin-left: 8px;
|
|
||||||
font-weight: bold;
|
font-weight: bold;
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
color: $color-main;
|
color: $color-main;
|
||||||
float: right;
|
position: absolute;
|
||||||
border: none;
|
border: none;
|
||||||
padding: 8px;
|
padding: 5px;
|
||||||
margin: -8px;
|
top: 0;
|
||||||
|
right: 0
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -150,6 +150,11 @@
|
||||||
"model": "SageWithholding",
|
"model": "SageWithholding",
|
||||||
"foreignKey": "sageWithholdingFk"
|
"foreignKey": "sageWithholdingFk"
|
||||||
},
|
},
|
||||||
|
"contacts": {
|
||||||
|
"type": "hasMany",
|
||||||
|
"model": "SupplierContact",
|
||||||
|
"foreignKey": "supplierFk"
|
||||||
|
},
|
||||||
"addresses": {
|
"addresses": {
|
||||||
"type": "hasMany",
|
"type": "hasMany",
|
||||||
"model": "SupplierAddress",
|
"model": "SupplierAddress",
|
||||||
|
|
|
@ -37,7 +37,27 @@ class Controller extends Section {
|
||||||
}
|
}
|
||||||
|
|
||||||
sendEmail() {
|
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) {
|
getTotal(entry) {
|
||||||
|
|
|
@ -7,6 +7,7 @@ describe('Supplier', () => {
|
||||||
let controller;
|
let controller;
|
||||||
let $httpParamSerializer;
|
let $httpParamSerializer;
|
||||||
let $httpBackend;
|
let $httpBackend;
|
||||||
|
const supplierId = 2;
|
||||||
|
|
||||||
beforeEach(ngModule('supplier'));
|
beforeEach(ngModule('supplier'));
|
||||||
|
|
||||||
|
@ -17,8 +18,9 @@ describe('Supplier', () => {
|
||||||
const $element = angular.element('<vn-supplier-consumption></vn-supplier-consumption');
|
const $element = angular.element('<vn-supplier-consumption></vn-supplier-consumption');
|
||||||
controller = $componentController('vnSupplierConsumption', {$element, $scope});
|
controller = $componentController('vnSupplierConsumption', {$element, $scope});
|
||||||
controller.$.model = crudModel;
|
controller.$.model = crudModel;
|
||||||
|
controller.$params = {id: supplierId};
|
||||||
controller.supplier = {
|
controller.supplier = {
|
||||||
id: 2
|
id: supplierId
|
||||||
};
|
};
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
@ -47,7 +49,42 @@ describe('Supplier', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('sendEmail()', () => {
|
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', () => {
|
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();
|
const now = new Date();
|
||||||
controller.$.model.userParams = {
|
controller.$.model.userParams = {
|
||||||
from: now,
|
from: now,
|
||||||
|
@ -55,11 +92,12 @@ describe('Supplier', () => {
|
||||||
};
|
};
|
||||||
const expectedParams = {
|
const expectedParams = {
|
||||||
recipientId: 2,
|
recipientId: 2,
|
||||||
|
recipient: 'batman@gothamcity.com',
|
||||||
from: now,
|
from: now,
|
||||||
to: now
|
to: now
|
||||||
};
|
};
|
||||||
|
|
||||||
const serializedParams = $httpParamSerializer(expectedParams);
|
serializedParams = $httpParamSerializer(expectedParams);
|
||||||
const path = `email/supplier-campaign-metrics?${serializedParams}`;
|
const path = `email/supplier-campaign-metrics?${serializedParams}`;
|
||||||
|
|
||||||
$httpBackend.expect('GET', path).respond({});
|
$httpBackend.expect('GET', path).respond({});
|
||||||
|
|
|
@ -1,2 +1,3 @@
|
||||||
|
|
||||||
Total entry: Total entrada
|
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
|
Loading…
Reference in New Issue