From e9f77bb9b4b90a5ca7bda4386359b6d2219d8f7c Mon Sep 17 00:00:00 2001 From: alexm Date: Wed, 29 Dec 2021 11:51:56 +0100 Subject: [PATCH 1/6] feat(supplier_summary): remove supplier.isFarmer and add verification by sageWithholdingFk --- db/dump/fixtures.sql | 10 +++++----- modules/supplier/back/methods/supplier/getSummary.js | 1 - modules/supplier/back/models/supplier.json | 3 --- modules/supplier/front/summary/index.js | 4 ++++ 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/db/dump/fixtures.sql b/db/dump/fixtures.sql index 1bc5a4fad..8dc7221d3 100644 --- a/db/dump/fixtures.sql +++ b/db/dump/fixtures.sql @@ -1275,7 +1275,7 @@ INSERT INTO `vn`.`annualAverageInvoiced`(`clientFk`, `invoiced`) INSERT INTO `vn`.`supplierActivity`(`code`, `name`) VALUES ('animals', 'Food and complements for pets'), - ('complements', 'Other complements'), + ('complements', 'Other complements'), ('flowerPlants', 'Wholesale of flowers and plants'), ('vegetablesFruits', 'Fruit and vegetable trade'); @@ -1288,11 +1288,11 @@ INSERT INTO `vn`.`supplierAddress`(`id`, `supplierFk`, `nickname`, `street`, `pr (5, 442, 'GCR building', 'Bristol district', 1, '46000', 'Gotham', '111111111', '222222222'), (6, 442, 'The Gotham Tonight building', 'Bristol district', 1, '46000', 'Gotham', '111111111', '222222222'); -INSERT INTO `vn`.`supplier`(`id`, `name`, `nickname`,`account`,`countryFk`,`nif`,`isFarmer`,`commission`, `created`, `isActive`, `street`, `city`, `provinceFk`, `postCode`, `payMethodFk`, `payDemFk`, `payDay`, `taxTypeSageFk`, `withholdingSageFk`, `transactionTypeSageFk`, `workerFk`, `supplierActivityFk`, `isPayMethodChecked`) +INSERT INTO `vn`.`supplier`(`id`, `name`, `nickname`,`account`,`countryFk`,`nif`, `commission`, `created`, `isActive`, `street`, `city`, `provinceFk`, `postCode`, `payMethodFk`, `payDemFk`, `payDay`, `taxTypeSageFk`, `withholdingSageFk`, `transactionTypeSageFk`, `workerFk`, `supplierActivityFk`, `isPayMethodChecked`) VALUES - (1, 'Plants SL', 'Plants nick', 4100000001, 1, '06089160W', 0, 0, CURDATE(), 1, 'supplier address 1', 'PONTEVEDRA', 1, 15214, 1, 1, 15, 4, 1, 1, 18, 'flowerPlants', 1), - (2, 'Farmer King', 'The farmer', 4000020002, 1, '87945234L', 1, 0, CURDATE(), 1, 'supplier address 2', 'SILLA', 2, 43022, 1, 2, 10, 93, 2, 8, 18, 'animals', 1), - (442, 'Verdnatura Levante SL', 'Verdnatura', 5115000442, 1, '06815934E', 0, 0, CURDATE(), 1, 'supplier address 3', 'SILLA', 1, 43022, 1, 2, 15, 6, 9, 3, 18, 'flowerPlants', 1); + (1, 'Plants SL', 'Plants nick', 4100000001, 1, '06089160W', 0, CURDATE(), 1, 'supplier address 1', 'PONTEVEDRA', 1, 15214, 1, 1, 15, 4, 1, 1, 18, 'flowerPlants', 1), + (2, 'Farmer King', 'The farmer', 4000020002, 1, '87945234L', 0, CURDATE(), 1, 'supplier address 2', 'SILLA', 2, 43022, 1, 2, 10, 93, 2, 8, 18, 'animals', 1), + (442, 'Verdnatura Levante SL', 'Verdnatura', 5115000442, 1, '06815934E', 0, CURDATE(), 1, 'supplier address 3', 'SILLA', 1, 43022, 1, 2, 15, 6, 9, 3, 18, 'flowerPlants', 1); INSERT INTO `vn`.`supplierContact`(`id`, `supplierFk`, `phone`, `mobile`, `email`, `observation`, `name`) VALUES diff --git a/modules/supplier/back/methods/supplier/getSummary.js b/modules/supplier/back/methods/supplier/getSummary.js index 1148c16cb..d51f84947 100644 --- a/modules/supplier/back/methods/supplier/getSummary.js +++ b/modules/supplier/back/methods/supplier/getSummary.js @@ -38,7 +38,6 @@ module.exports = Self => { 'payDemFk', 'payDay', 'account', - 'isFarmer', 'sageTaxTypeFk', 'sageTransactionTypeFk', 'sageWithholdingFk', diff --git a/modules/supplier/back/models/supplier.json b/modules/supplier/back/models/supplier.json index 4a22144ba..8b4b8f26f 100644 --- a/modules/supplier/back/models/supplier.json +++ b/modules/supplier/back/models/supplier.json @@ -27,9 +27,6 @@ "nif": { "type": "string" }, - "isFarmer": { - "type": "boolean" - }, "phone": { "type": "number" }, diff --git a/modules/supplier/front/summary/index.js b/modules/supplier/front/summary/index.js index a828379bc..14c030da0 100644 --- a/modules/supplier/front/summary/index.js +++ b/modules/supplier/front/summary/index.js @@ -17,6 +17,10 @@ class Controller extends Summary { getSummary() { return this.$http.get(`Suppliers/${this.supplier.id}/getSummary`).then(response => { this.summary = response.data; + + this.summary.isFarmer = false; + if(response.data.sageWithholdingFk == 2) + this.summary.isFarmer = true; }); } } -- 2.40.1 From 83a28bc0ee91725752237b437ae40ddfd90038ca Mon Sep 17 00:00:00 2001 From: alexm Date: Wed, 29 Dec 2021 11:52:45 +0100 Subject: [PATCH 2/6] test(supplier_summary): test for sageWithholdingFk to isFarmer --- modules/supplier/front/summary/index.spec.js | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/modules/supplier/front/summary/index.spec.js b/modules/supplier/front/summary/index.spec.js index aa44cd14f..a1e418670 100644 --- a/modules/supplier/front/summary/index.spec.js +++ b/modules/supplier/front/summary/index.spec.js @@ -25,7 +25,19 @@ describe('Supplier', () => { controller.getSummary(); $httpBackend.flush(); - expect(controller.summary).toEqual({id: 1}); + expect(controller.summary).toEqual({id: 1, isFarmer: false}); + }); + + it('should get if supplier is farmer by sageWithholdingFk', () => { + controller.supplier = {id: 2}; + + const query = `Suppliers/${controller.supplier.id}/getSummary`; + + $httpBackend.expectGET(query).respond({id: 2, sageWithholdingFk: 2}); + controller.getSummary(); + $httpBackend.flush(); + + expect(controller.summary).toEqual({id: 2, isFarmer: true, sageWithholdingFk: 2}); }); }); }); -- 2.40.1 From a57999aaad32775d8c871f858c061519f64674fb Mon Sep 17 00:00:00 2001 From: alexm Date: Wed, 29 Dec 2021 11:55:48 +0100 Subject: [PATCH 3/6] unnecessary space --- db/dump/fixtures.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/db/dump/fixtures.sql b/db/dump/fixtures.sql index 8dc7221d3..a69972f71 100644 --- a/db/dump/fixtures.sql +++ b/db/dump/fixtures.sql @@ -1275,7 +1275,7 @@ INSERT INTO `vn`.`annualAverageInvoiced`(`clientFk`, `invoiced`) INSERT INTO `vn`.`supplierActivity`(`code`, `name`) VALUES ('animals', 'Food and complements for pets'), - ('complements', 'Other complements'), + ('complements', 'Other complements'), ('flowerPlants', 'Wholesale of flowers and plants'), ('vegetablesFruits', 'Fruit and vegetable trade'); -- 2.40.1 From a528161b93b33048173b02f0aced6171d62d15d0 Mon Sep 17 00:00:00 2001 From: alexm Date: Fri, 7 Jan 2022 08:08:41 +0100 Subject: [PATCH 4/6] refactor(supplier.summary): separate isFarmer() --- modules/supplier/front/summary/index.js | 12 ++++++++---- modules/supplier/front/summary/index.spec.js | 8 ++++---- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/modules/supplier/front/summary/index.js b/modules/supplier/front/summary/index.js index 14c030da0..85268a13d 100644 --- a/modules/supplier/front/summary/index.js +++ b/modules/supplier/front/summary/index.js @@ -17,12 +17,16 @@ class Controller extends Summary { getSummary() { return this.$http.get(`Suppliers/${this.supplier.id}/getSummary`).then(response => { this.summary = response.data; - - this.summary.isFarmer = false; - if(response.data.sageWithholdingFk == 2) - this.summary.isFarmer = true; + this.isFarmer(response.data.sageWithholdingFk); }); } + + isFarmer(sageWithholdingFk) { + const farmerCode = 2; + + if (sageWithholdingFk == farmerCode) + this.summary.isFarmer = true; + } } ngModule.vnComponent('vnSupplierSummary', { diff --git a/modules/supplier/front/summary/index.spec.js b/modules/supplier/front/summary/index.spec.js index a1e418670..7295a028c 100644 --- a/modules/supplier/front/summary/index.spec.js +++ b/modules/supplier/front/summary/index.spec.js @@ -1,6 +1,6 @@ import './index'; -describe('Supplier', () => { +fdescribe('Supplier', () => { describe('Component vnSupplierSummary', () => { let controller; let $httpBackend; @@ -15,7 +15,7 @@ describe('Supplier', () => { controller = $componentController('vnSupplierSummary', {$element, $scope}); })); - describe('getSummary()', () => { + fdescribe('getSummary()', () => { it('should perform a get asking for the supplier data', () => { controller.supplier = {id: 1}; @@ -25,11 +25,11 @@ describe('Supplier', () => { controller.getSummary(); $httpBackend.flush(); - expect(controller.summary).toEqual({id: 1, isFarmer: false}); + expect(controller.summary).toEqual({id: 1}); }); it('should get if supplier is farmer by sageWithholdingFk', () => { - controller.supplier = {id: 2}; + controller.supplier = {id: 2, sageWithholdingFk: 2}; const query = `Suppliers/${controller.supplier.id}/getSummary`; -- 2.40.1 From 4f799d3e00493b219f45bb693ba72a6a45155d9a Mon Sep 17 00:00:00 2001 From: alexm Date: Fri, 7 Jan 2022 08:10:13 +0100 Subject: [PATCH 5/6] remove focus test --- modules/supplier/front/summary/index.spec.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/supplier/front/summary/index.spec.js b/modules/supplier/front/summary/index.spec.js index 7295a028c..e8ab74220 100644 --- a/modules/supplier/front/summary/index.spec.js +++ b/modules/supplier/front/summary/index.spec.js @@ -1,6 +1,6 @@ import './index'; -fdescribe('Supplier', () => { +describe('Supplier', () => { describe('Component vnSupplierSummary', () => { let controller; let $httpBackend; @@ -15,7 +15,7 @@ fdescribe('Supplier', () => { controller = $componentController('vnSupplierSummary', {$element, $scope}); })); - fdescribe('getSummary()', () => { + describe('getSummary()', () => { it('should perform a get asking for the supplier data', () => { controller.supplier = {id: 1}; -- 2.40.1 From 94a2d3cc163e9be218f1b852cf310a6de4db6572 Mon Sep 17 00:00:00 2001 From: alexm Date: Tue, 11 Jan 2022 14:49:22 +0100 Subject: [PATCH 6/6] refactor(supplier): add isFarmer in getSummary --- modules/supplier/back/methods/supplier/getSummary.js | 5 +++++ .../back/methods/supplier/specs/getSummary.spec.js | 8 ++++++++ modules/supplier/front/summary/index.js | 8 -------- modules/supplier/front/summary/index.spec.js | 12 ------------ 4 files changed, 13 insertions(+), 20 deletions(-) diff --git a/modules/supplier/back/methods/supplier/getSummary.js b/modules/supplier/back/methods/supplier/getSummary.js index d51f84947..67f5267b6 100644 --- a/modules/supplier/back/methods/supplier/getSummary.js +++ b/modules/supplier/back/methods/supplier/getSummary.js @@ -101,6 +101,11 @@ module.exports = Self => { ] }; let supplier = await Self.app.models.Supplier.findOne(filter); + + const farmerCode = 2; + if (supplier.sageWithholdingFk == farmerCode) + supplier.isFarmer = true; + return supplier; }; }; diff --git a/modules/supplier/back/methods/supplier/specs/getSummary.spec.js b/modules/supplier/back/methods/supplier/specs/getSummary.spec.js index 30713f517..21e56882f 100644 --- a/modules/supplier/back/methods/supplier/specs/getSummary.spec.js +++ b/modules/supplier/back/methods/supplier/specs/getSummary.spec.js @@ -25,4 +25,12 @@ describe('Supplier getSummary()', () => { expect(payMethod.name).toEqual('PayMethod one'); }); + + it(`should get if supplier is farmer by sageWithholdingFk`, async() => { + const supplier = await app.models.Supplier.findById(2); + const supplierSummary = await app.models.Supplier.getSummary(2); + + expect(supplier.isFarmer).toBeUndefined(); + expect(supplierSummary.isFarmer).toEqual(true); + }); }); diff --git a/modules/supplier/front/summary/index.js b/modules/supplier/front/summary/index.js index 85268a13d..a828379bc 100644 --- a/modules/supplier/front/summary/index.js +++ b/modules/supplier/front/summary/index.js @@ -17,16 +17,8 @@ class Controller extends Summary { getSummary() { return this.$http.get(`Suppliers/${this.supplier.id}/getSummary`).then(response => { this.summary = response.data; - this.isFarmer(response.data.sageWithholdingFk); }); } - - isFarmer(sageWithholdingFk) { - const farmerCode = 2; - - if (sageWithholdingFk == farmerCode) - this.summary.isFarmer = true; - } } ngModule.vnComponent('vnSupplierSummary', { diff --git a/modules/supplier/front/summary/index.spec.js b/modules/supplier/front/summary/index.spec.js index e8ab74220..aa44cd14f 100644 --- a/modules/supplier/front/summary/index.spec.js +++ b/modules/supplier/front/summary/index.spec.js @@ -27,18 +27,6 @@ describe('Supplier', () => { expect(controller.summary).toEqual({id: 1}); }); - - it('should get if supplier is farmer by sageWithholdingFk', () => { - controller.supplier = {id: 2, sageWithholdingFk: 2}; - - const query = `Suppliers/${controller.supplier.id}/getSummary`; - - $httpBackend.expectGET(query).respond({id: 2, sageWithholdingFk: 2}); - controller.getSummary(); - $httpBackend.flush(); - - expect(controller.summary).toEqual({id: 2, isFarmer: true, sageWithholdingFk: 2}); - }); }); }); }); -- 2.40.1