Merge pull request '2727 - Send consumption report to an email address' (#615) from 2727-supplier_consumption into dev
gitea/salix/pipeline/head This commit looks good
Details
gitea/salix/pipeline/head This commit looks good
Details
Reviewed-on: #615 Reviewed-by: Carlos Jimenez Ruiz <carlosjr@verdnatura.es>
This commit is contained in:
commit
7c47b85567
|
@ -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);
|
||||
|
||||
|
|
|
@ -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
|
||||
}
|
||||
}
|
|
@ -150,6 +150,11 @@
|
|||
"model": "SageWithholding",
|
||||
"foreignKey": "sageWithholdingFk"
|
||||
},
|
||||
"contacts": {
|
||||
"type": "hasMany",
|
||||
"model": "SupplierContact",
|
||||
"foreignKey": "supplierFk"
|
||||
},
|
||||
"addresses": {
|
||||
"type": "hasMany",
|
||||
"model": "SupplierAddress",
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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('<vn-supplier-consumption></vn-supplier-consumption');
|
||||
controller = $componentController('vnSupplierConsumption', {$element, $scope});
|
||||
controller.$.model = crudModel;
|
||||
controller.$params = {id: supplierId};
|
||||
controller.supplier = {
|
||||
id: 2
|
||||
id: supplierId
|
||||
};
|
||||
}));
|
||||
|
||||
|
@ -47,7 +49,42 @@ describe('Supplier', () => {
|
|||
});
|
||||
|
||||
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({});
|
||||
|
|
|
@ -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
|
Loading…
Reference in New Issue