2502-supplier_summary + e2e #425

Merged
joan merged 15 commits from 2502-supplier_summary into dev 2020-10-29 07:55:38 +00:00
21 changed files with 105 additions and 148 deletions
Showing only changes of commit 58168e78ab - Show all commits

View File

@ -1,2 +0,0 @@
ALTER TABLE `vn`.`supplier`
ADD COLUMN `email` VARCHAR(45) NULL AFTER `isTrucker`;

View File

@ -1208,11 +1208,11 @@ INSERT INTO `vn`.`annualAverageInvoiced`(`clientFk`, `invoiced`)
(104, 500), (104, 500),
(105, 5000); (105, 5000);
INSERT INTO `vn`.`supplier`(`id`, `name`, `nickname`,`account`,`countryFk`,`nif`,`isFarmer`,`retAccount`,`commission`, `created`, `postcodeFk`, `isActive`, `street`, `city`, `provinceFk`, `postCode`, `payMethodFk`, `payDemFk`, `phone`, `payDay`, `email`) INSERT INTO `vn`.`supplier`(`id`, `name`, `nickname`,`account`,`countryFk`,`nif`,`isFarmer`,`retAccount`,`commission`, `created`, `postcodeFk`, `isActive`, `street`, `city`, `provinceFk`, `postCode`, `payMethodFk`, `payDemFk`, `payDay`)
VALUES VALUES
(1, 'Plants SL', 'Plants nick', 4000000001, 1, '06089160W', 0, NULL, 0, CURDATE(), 1111, 1, 'supplier address 1', 'PONTEVEDRA', 1, 15214, 1, 1, 123456789, 15, 'supplier_one@gmail.es'), (1, 'Plants SL', 'Plants nick', 4000000001, 1, '06089160W', 0, NULL, 0, CURDATE(), 1111, 1, 'supplier address 1', 'PONTEVEDRA', 1, 15214, 1, 1, 15),
(2, 'Flower King', 'The king', 4000000002, 1, 'B22222222', 0, NULL, 0, CURDATE(), 2222, 1, 'supplier address 2', 'LONDON', 2, 45671, 1, 2, 987654321, 10, 'supplier_two@gmail.es'), (2, 'Flower King', 'The king', 4000000002, 1, 'B22222222', 0, NULL, 0, CURDATE(), 2222, 1, 'supplier address 2', 'LONDON', 2, 45671, 1, 2, 10),
(442, 'Verdnatura Levante SL', 'Verdnatura', 4000000442, 1, 'C33333333', 0, NULL, 0, CURDATE(), 3333, 1, 'supplier address 3', 'SILLA', 1, 43022, 1, 2, 987123654, 15, 'supplier_three@gmail.es'); (442, 'Verdnatura Levante SL', 'Verdnatura', 4000000442, 1, 'C33333333', 0, NULL, 0, CURDATE(), 3333, 1, 'supplier address 3', 'SILLA', 1, 43022, 1, 2, 15);
INSERT INTO `cache`.`cache_calc`(`id`, `cache_id`, `cacheName`, `params`, `last_refresh`, `expires`, `created`, `connection_id`) INSERT INTO `cache`.`cache_calc`(`id`, `cache_id`, `cacheName`, `params`, `last_refresh`, `expires`, `created`, `connection_id`)
VALUES VALUES

View File

@ -56,7 +56,7 @@ describe('Update Claim', () => {
hasToPickUp: false hasToPickUp: false
} }
}; };
await app.models.Claim.updateClaim(ctx, newClaim.id,); await app.models.Claim.updateClaim(ctx, newClaim.id);
let updatedClaim = await app.models.Claim.findById(newClaim.id); let updatedClaim = await app.models.Claim.findById(newClaim.id);

View File

@ -186,12 +186,6 @@
"model": "BankEntity", "model": "BankEntity",
"foreignKey": "bankEntityFk" "foreignKey": "bankEntityFk"
}, },
"supplier": {
"type": "belongsTo",
"model": "Supplier",
"foreignKey": "fi",
"primaryKey": "nif"
},
"defaulters": { "defaulters": {
"type": "hasMany", "type": "hasMany",
"model": "Defaulter", "model": "Defaulter",

View File

@ -51,7 +51,7 @@ describe('Client', () => {
} }
}; };
const serializedParams = $httpParamSerializer({filter}); const serializedParams = $httpParamSerializer({filter});
$httpBackend.expect('GET', `ClientRisks?${serializedParams}`,).respond([{amount: 20}]); $httpBackend.expect('GET', `ClientRisks?${serializedParams}`).respond([{amount: 20}]);
controller.getAmountPaid(); controller.getAmountPaid();
$httpBackend.flush(); $httpBackend.flush();
@ -65,7 +65,7 @@ describe('Client', () => {
controller.$params = {id: 101}; controller.$params = {id: 101};
$httpBackend.expect('POST', `Receipts`,).respond({id: 1}); $httpBackend.expect('POST', `Receipts`).respond({id: 1});
controller.responseHandler('accept'); controller.responseHandler('accept');
$httpBackend.flush(); $httpBackend.flush();

View File

@ -18,7 +18,7 @@ describe('Component vnOrderIndex', () => {
beforeEach(ngModule('order')); beforeEach(ngModule('order'));
beforeEach(inject(($componentController, _$window_,) => { beforeEach(inject(($componentController, _$window_) => {
$window = _$window_; $window = _$window_;
const $element = angular.element('<vn-order-index></vn-order-index>'); const $element = angular.element('<vn-order-index></vn-order-index>');
controller = $componentController('vnOrderIndex', {$element}); controller = $componentController('vnOrderIndex', {$element});

View File

@ -1,25 +0,0 @@
module.exports = Self => {
Self.remoteMethod('isAClient', {
description: 'Returns the supplier summary',
accessType: 'READ',
accepts: {
arg: 'nif',
type: 'string',
required: true,
description: 'The supplier nif',
http: {source: 'path'}
},
returns: {
type: 'object',
root: true
},
http: {
path: `/:nif/isAClient`,
verb: 'GET'
}
});
Self.isAClient = async nif => {
const client = await Self.app.models.Client.findOne({where: {fi: nif}});
return client;
};
};

View File

@ -1,28 +1,28 @@
const app = require('vn-loopback/server/server'); const app = require('vn-loopback/server/server');
describe('Supplier getSummary()', () => { describe('Supplier getSummary()', () => {
// it('should return the supplier matching "search"', async() => { it('should return a summary object containing data from one supplier', async() => {
// let ctx = { const supplier = await app.models.Supplier.getSummary(1);
// args: {
// search: 1
// }
// };
// let result = await app.models.Supplier.filter(ctx); expect(supplier.id).toEqual(1);
expect(supplier.name).toEqual('Plants SL');
expect(supplier.nif).toEqual('06089160W');
});
// expect(result.length).toEqual(1); it(`should return a summary object containing it's supplier country`, async() => {
joan marked this conversation as resolved
Review

containing it's supplier country relation

containing it's supplier country relation
// expect(result[0].id).toEqual(1); const supplier = await app.models.Supplier.getSummary(1);
// }); const country = supplier.country();
// it('should return the supplier matching the province', async() => { expect(country.id).toEqual(1);
// let ctx = { expect(country.code).toEqual('ES');
// args: { });
// provinceFk: 1
// }
// };
// let result = await app.models.Supplier.filter(ctx); it(`should return a summary object containing it's billing data`, async() => {
const supplier = await app.models.Supplier.getSummary(1);
const payMethod = supplier.payMethod();
// expect(result.length).toEqual(2); expect(supplier.account).toEqual(4000000001);
// }); expect(supplier.payDay).toEqual(15);
expect(payMethod.name).toEqual('PayMethod one');
});
}); });

View File

@ -1,5 +1,4 @@
module.exports = Self => { module.exports = Self => {
require('../methods/supplier/filter')(Self); require('../methods/supplier/filter')(Self);
require('../methods/supplier/getSummary')(Self); require('../methods/supplier/getSummary')(Self);
require('../methods/supplier/isAClient')(Self);
}; };

View File

@ -100,8 +100,8 @@
"client": { "client": {
"type": "belongsTo", "type": "belongsTo",
"model": "Client", "model": "Client",
"foreignKey": "fi", "foreignKey": "nif",
"primaryKey": "nif" "primaryKey": "fi"
} }
}, },
"acls": [ "acls": [

View File

@ -44,9 +44,9 @@
</div> </div>
<div ng-transclude="btnTwo"> <div ng-transclude="btnTwo">
<vn-quick-link <vn-quick-link
ng-if="$ctrl.isAClient" ng-if="$ctrl.supplier.client.fi"
tooltip="Go to client" tooltip="Go to client"
state="['client.card.summary', {id: $ctrl.isAClient.id}]" state="['client.card.summary', {id: $ctrl.supplier.client.id}]"
icon="person"> icon="person">
</vn-quick-link> </vn-quick-link>
</div> </div>

View File

@ -8,8 +8,6 @@ class Controller extends Descriptor {
set supplier(value) { set supplier(value) {
this.entity = value; this.entity = value;
console.log('this.entity', this.entity);
// this.iSupplierAClient();
} }
get entryFilter() { get entryFilter() {
@ -30,22 +28,6 @@ class Controller extends Descriptor {
to to
}); });
} }
// iSupplierAClient() {
// if (!this.supplier) return;
// const filter = {
// where: {fi: this.supplier.nif}
// };
// this.$http.get('Clients/findOne', {filter}).then(res => {
// if (res.data)
// this.isAClient = res.data;
// }).catch(error => {
// return this.isAClient = false;
// });
// // this.$http.get(`Suppliers/${this.supplier.nif}/isAClient`).then(res => {
// // this.isAClient = res.data;
// // });
// }
loadData() { loadData() {
const filter = { const filter = {
@ -83,8 +65,8 @@ class Controller extends Descriptor {
] ]
}; };
return this.getData(`Suppliers/${this.id}`, {filter}) return this.getData(`Suppliers/${this.supplier.id}`, {filter})
.then(res => this.entity = res.data); .then(res => this.supplier = res.data);
} }
} }

View File

@ -1,43 +1,64 @@
import './index.js'; import './index.js';
describe('Entry Component vnEntryDescriptor', () => { describe('Supplier Component vnSupplierDescriptor', () => {
let $httpBackend; let $httpBackend;
let controller; let controller;
const entry = {id: 2}; let $httpParamSerializer;
const supplier = {id: 1};
beforeEach(ngModule('entry')); beforeEach(ngModule('supplier'));
beforeEach(inject(($componentController, _$httpBackend_) => { beforeEach(inject(($componentController, _$httpBackend_, _$httpParamSerializer_) => {
$httpBackend = _$httpBackend_; $httpBackend = _$httpBackend_;
controller = $componentController('vnEntryDescriptor', {$element: null}, {entry}); $httpParamSerializer = _$httpParamSerializer_;
controller = $componentController('vnSupplierDescriptor', {$element: null}, {supplier});
})); }));
describe('showEntryReport()', () => {
it('should open a new window showing a delivery note PDF document', () => {
jest.spyOn(controller.vnReport, 'show');
window.open = jasmine.createSpy('open');
const params = {
clientId: controller.vnConfig.storage.currentUserWorkerId,
entryId: entry.id
};
controller.showEntryReport();
expect(controller.vnReport.show).toHaveBeenCalledWith('entry-order', params);
});
});
describe('loadData()', () => { describe('loadData()', () => {
it('should perform ask for the entry', () => { it('should perform ask for the supplier', () => {
let query = `Entries/${entry.id}`; const filter = {
fields: [
'id',
'name',
'nickname',
'nif',
'payMethodFk',
'payDemFk',
'payDay',
'isActive',
'isOfficial',
'account'
],
include: [
{
relation: 'payMethod',
scope: {
fields: ['id', 'name']
}
},
{
relation: 'payDem',
scope: {
fields: ['id', 'payDem']
}
},
{
relation: 'client',
scope: {
fields: ['id', 'fi']
}
}
]
};
const serializedParams = $httpParamSerializer({filter});
let query = `Suppliers/${controller.supplier.id}?${serializedParams}`;
jest.spyOn(controller, 'getData'); jest.spyOn(controller, 'getData');
$httpBackend.expectGET(query).respond(); $httpBackend.expect('GET', query).respond({id: 1});
controller.loadData(); controller.loadData();
$httpBackend.flush(); $httpBackend.flush();
expect(controller.getData).toHaveBeenCalledTimes(1); expect(controller.getData).toHaveBeenCalledTimes(1);
expect(controller.getData).toHaveBeenCalledWith(query, jasmine.any(Object));
}); });
}); });
}); });

View File

@ -1 +1,3 @@
Tax number: NIF / CIF Tax number: NIF / CIF
All entries with current supplier: Todas las entradas con el proveedor actual
Go to client: Ir al cliente

View File

@ -8,7 +8,7 @@
<vn-searchbar <vn-searchbar
vn-focus vn-focus
panel="vn-supplier-search-panel" panel="vn-supplier-search-panel"
info="Search suppliers by id name or alias" info="Search suppliers by id, name or alias"
model="model"> model="model">
</vn-searchbar> </vn-searchbar>
</vn-portal> </vn-portal>

View File

@ -5,7 +5,7 @@
vn-one vn-one
label="General search" label="General search"
ng-model="filter.search" ng-model="filter.search"
info="Search suppliers by id name or alias" info="Search suppliers by id, name or alias"
vn-focus> vn-focus>
</vn-textfield> </vn-textfield>
</vn-horizontal> </vn-horizontal>

View File

@ -1,3 +1,4 @@
Province: Provincia Province: Provincia
Country: País Country: País
Tax number: Nif Tax number: Nif

NIF

NIF
Search suppliers by id, name or alias: Busca proveedores por el id, el nombre o el alias

Busca proveedores por id, nombre o alias

Busca proveedores por id, nombre o alias

View File

@ -6,7 +6,7 @@
<vn-label-value label="Id" <vn-label-value label="Id"
value="{{$ctrl.summary.id}}"> value="{{$ctrl.summary.id}}">
</vn-label-value> </vn-label-value>
<vn-label-value label="Supplier alias" <vn-label-value label="Alias"
value="{{$ctrl.summary.nickname}}"> value="{{$ctrl.summary.nickname}}">
</vn-label-value> </vn-label-value>
<vn-check <vn-check
@ -52,7 +52,7 @@
<vn-label-value label="Pay method" <vn-label-value label="Pay method"
value="{{$ctrl.summary.payMethod.name}}"> value="{{$ctrl.summary.payMethod.name}}">
</vn-label-value> </vn-label-value>
<vn-label-value label="Pay dem" <vn-label-value label="Payment deadline"
value="{{$ctrl.summary.payDem.payDem}}"> value="{{$ctrl.summary.payDem.payDem}}">
</vn-label-value> </vn-label-value>
<vn-label-value label="Pay day" <vn-label-value label="Pay day"

View File

@ -11,7 +11,7 @@ class Controller extends Section {
} }
getSummary() { getSummary() {
this.$http.get(`Suppliers/${this.supplier.id}/getSummary`).then(response => { return this.$http.get(`Suppliers/${this.supplier.id}/getSummary`).then(response => {
this.summary = response.data; this.summary = response.data;
}); });
} }

View File

@ -1,51 +1,31 @@
import './index'; import './index';
describe('Client', () => { describe('Supplier', () => {
describe('Component vnClientSummary', () => { describe('Component vnSupplierSummary', () => {
let controller; let controller;
let $httpBackend; let $httpBackend;
let $scope; let $scope;
beforeEach(ngModule('client')); beforeEach(ngModule('supplier'));
beforeEach(inject(($componentController, _$httpBackend_, $rootScope) => { beforeEach(inject(($componentController, _$httpBackend_, $rootScope) => {
$httpBackend = _$httpBackend_; $httpBackend = _$httpBackend_;
$scope = $rootScope.$new(); $scope = $rootScope.$new();
const $element = angular.element('<vn-client-summary></vn-client-summary>'); const $element = angular.element('<vn-supplier-summary></vn-supplier-summary>');
controller = $componentController('vnClientSummary', {$element, $scope}); controller = $componentController('vnSupplierSummary', {$element, $scope});
controller.client = {id: 101};
})); }));
describe('$onChanges()', () => { describe('getSummary()', () => {
it('should perform a GET query and then define the summary property', () => { it('should perform a get asking for the supplier data', () => {
let res = {name: 'Superman', classifications: []}; controller.supplier = {id: 1};
jest.spyOn(controller, 'sumRisk').mockReturnThis(); const query = `Suppliers/${controller.supplier.id}/getSummary`;
$httpBackend.expect('GET', `Clients/101/summary`).respond(200, res);
controller.$onChanges(); $httpBackend.expectGET(query).respond({id: 1});
controller.getSummary();
$httpBackend.flush(); $httpBackend.flush();
expect(controller.summary).toBeDefined(); expect(controller.summary).toEqual({id: 1});
expect(controller.summary.name).toEqual('Superman');
});
});
describe('sumRisk()', () => {
it('should sum property amount of an array', () => {
controller.summary = {
clientRisks: [{
companyFk: 442,
amount: 100
},
{
companyFk: 567,
amount: 200
}]};
let result = controller.sumRisk();
expect(result).toEqual(300);
}); });
}); });
}); });

View File

@ -0,0 +1,5 @@
Is official: Es oficial
Country: País
Tax number: Nif

NIF y CIF?

NIF y CIF?
Search suppliers by id, name or alias: Busca proveedores por el id, el nombre o el alias

-el

-el
Is Farmer: Es agrícola