From a6b867430253eeff957d5a4dd55c6404291ccf05 Mon Sep 17 00:00:00 2001 From: vicent Date: Mon, 9 May 2022 14:34:20 +0200 Subject: [PATCH 1/3] feat(invoiceIn.tax): add button for create an expence --- db/changes/10451-april/00-aclExpense.sql | 5 +++ modules/invoiceIn/front/tax/index.html | 45 ++++++++++++++++++++++- modules/invoiceIn/front/tax/index.js | 21 +++++++++++ modules/invoiceIn/front/tax/index.spec.js | 30 ++++++++++++++- modules/invoiceIn/front/tax/locale/es.yml | 6 +++ modules/item/back/models/expense.json | 13 +------ 6 files changed, 106 insertions(+), 14 deletions(-) create mode 100644 db/changes/10451-april/00-aclExpense.sql create mode 100644 modules/invoiceIn/front/tax/locale/es.yml diff --git a/db/changes/10451-april/00-aclExpense.sql b/db/changes/10451-april/00-aclExpense.sql new file mode 100644 index 000000000..55ca8c389 --- /dev/null +++ b/db/changes/10451-april/00-aclExpense.sql @@ -0,0 +1,5 @@ +INSERT INTO `salix`.`ACL`(`model`, `property`, `accessType`, `permission`, `principalType`, `principalId`) + VALUES('Expense', '*', 'READ', 'ALLOW', 'ROLE', 'employee'); + +INSERT INTO `salix`.`ACL`(`model`, `property`, `accessType`, `permission`, `principalType`, `principalId`) + VALUES('Expense', '*', 'WRITE', 'ALLOW', 'ROLE', 'administrative'); diff --git a/modules/invoiceIn/front/tax/index.html b/modules/invoiceIn/front/tax/index.html index c495d44d2..7a3a9b333 100644 --- a/modules/invoiceIn/front/tax/index.html +++ b/modules/invoiceIn/front/tax/index.html @@ -33,6 +33,13 @@ show-field="id" rule> {{id}}: {{name}} + + + + - \ No newline at end of file + + + + + +
+
{{$ctrl.$t('New expence')}}
+ + + + + + + + + + +
+
+ + + + +
\ No newline at end of file diff --git a/modules/invoiceIn/front/tax/index.js b/modules/invoiceIn/front/tax/index.js index 53cfc5598..48fb98d4e 100644 --- a/modules/invoiceIn/front/tax/index.js +++ b/modules/invoiceIn/front/tax/index.js @@ -1,5 +1,6 @@ import ngModule from '../module'; import Section from 'salix/components/section'; +import UserError from 'core/lib/user-error'; class Controller extends Section { taxRate(invoiceInTax, taxRateSelection) { @@ -26,6 +27,26 @@ class Controller extends Section { this.card.reload(); }); } + + onResponse() { + if (!this.expence) + throw new UserError(`The fields can't be empty`); + else if (!this.expence.code) + throw new UserError(`The code can't be empty`); + else if (!this.expence.description) + throw new UserError(`The description can't be empty`); + + const params = []; + params.push({ + id: this.expence.code, + isWithheld: this.expence.isWithheld, + name: this.expence.description + }); + + this.$http.post(`Expenses`, params) .then(() => { + this.vnApp.showSuccess(this.$t('Expence saved!')); + }); + } } ngModule.vnComponent('vnInvoiceInTax', { diff --git a/modules/invoiceIn/front/tax/index.spec.js b/modules/invoiceIn/front/tax/index.spec.js index 20d5d40d8..bc7963899 100644 --- a/modules/invoiceIn/front/tax/index.spec.js +++ b/modules/invoiceIn/front/tax/index.spec.js @@ -7,10 +7,12 @@ describe('InvoiceIn', () => { let controller; let $scope; let vnApp; + let $httpBackend; beforeEach(ngModule('invoiceIn')); - beforeEach(inject(($componentController, $rootScope, _vnApp_) => { + beforeEach(inject(($componentController, $rootScope, _vnApp_, _$httpBackend_) => { + $httpBackend = _$httpBackend_; vnApp = _vnApp_; jest.spyOn(vnApp, 'showError'); $scope = $rootScope.$new(); @@ -19,6 +21,7 @@ describe('InvoiceIn', () => { const $element = angular.element(''); controller = $componentController('vnInvoiceInTax', {$element, $scope}); + controller.$.model = crudModel; controller.invoiceIn = {id: 1}; })); @@ -55,5 +58,30 @@ describe('InvoiceIn', () => { expect(controller.card.reload).toHaveBeenCalledWith(); }); }); + + describe('onResponse()', () => { + it('should return success message', () => { + controller.expence = { + code: 7050000005, + isWithheld: 0, + description: 'Test' + }; + + const params = [{ + id: controller.expence.code, + isWithheld: controller.expence.isWithheld, + name: controller.expence.description + }]; + + jest.spyOn(controller.vnApp, 'showSuccess'); + $httpBackend.expect('POST', `Expenses`, params).respond(); + + controller.onResponse(); + $httpBackend.flush(); + + expect(controller.vnApp.showSuccess).toHaveBeenCalledWith('Expence saved!'); + }); + }); }); }); + diff --git a/modules/invoiceIn/front/tax/locale/es.yml b/modules/invoiceIn/front/tax/locale/es.yml new file mode 100644 index 000000000..220802d9a --- /dev/null +++ b/modules/invoiceIn/front/tax/locale/es.yml @@ -0,0 +1,6 @@ +Create expence: Crear gasto +New expence: Nuevo gasto +It's a withholding: Es una retención +The fields can't be empty: Los campos no pueden estar vacíos +The code can't be empty: El código no puede estar vacío +The description can't be empty: La descripción no puede estar vacía \ No newline at end of file diff --git a/modules/item/back/models/expense.json b/modules/item/back/models/expense.json index 65af02013..5120f07bc 100644 --- a/modules/item/back/models/expense.json +++ b/modules/item/back/models/expense.json @@ -17,9 +17,6 @@ }, "isWithheld": { "type": "number" - }, - "taxTypeFk": { - "type": "number" } }, "relations": { @@ -28,13 +25,5 @@ "model": "TaxType", "foreignKey": "taxTypeFk" } - }, - "acls": [ - { - "accessType": "READ", - "principalType": "ROLE", - "principalId": "$everyone", - "permission": "ALLOW" - } - ] + } } \ No newline at end of file -- 2.40.1 From f08a384a7cd304211272b55a3452011ac9305fb9 Mon Sep 17 00:00:00 2001 From: vicent Date: Mon, 9 May 2022 14:49:37 +0200 Subject: [PATCH 2/3] fix: e2e test --- e2e/helpers/selectors.js | 2 +- modules/invoiceIn/front/tax/index.html | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/e2e/helpers/selectors.js b/e2e/helpers/selectors.js index 799eb8fe7..189b7be67 100644 --- a/e2e/helpers/selectors.js +++ b/e2e/helpers/selectors.js @@ -982,7 +982,7 @@ export default { save: 'vn-invoice-in-basic-data button[type=submit]' }, invoiceInTax: { - addTaxButton: 'vn-invoice-in-tax vn-icon-button[icon="add_circle"]', + addTaxButton: 'vn-invoice-in-tax vn-icon-button[vn-tooltip="Add tax"]', thirdExpence: 'vn-invoice-in-tax vn-horizontal:nth-child(3) > vn-autocomplete[ng-model="invoiceInTax.expenseFk"]', thirdTaxableBase: 'vn-invoice-in-tax vn-horizontal:nth-child(3) > vn-input-number[ng-model="invoiceInTax.taxableBase"]', thirdTaxType: 'vn-invoice-in-tax vn-horizontal:nth-child(3) > vn-autocomplete[ng-model="invoiceInTax.taxTypeSageFk"]', diff --git a/modules/invoiceIn/front/tax/index.html b/modules/invoiceIn/front/tax/index.html index 7a3a9b333..44ceef807 100644 --- a/modules/invoiceIn/front/tax/index.html +++ b/modules/invoiceIn/front/tax/index.html @@ -105,7 +105,7 @@ - + -- 2.40.1 From 568579f46170736aeeaffa6fb1eb4d53aa9fd50f Mon Sep 17 00:00:00 2001 From: vicent Date: Thu, 12 May 2022 08:27:04 +0200 Subject: [PATCH 3/3] refactor: pull request changes --- modules/invoiceIn/front/tax/index.html | 17 +++++----- modules/invoiceIn/front/tax/index.js | 35 ++++++++++--------- modules/invoiceIn/front/tax/index.spec.js | 41 +++++++++++++++++++---- modules/invoiceIn/front/tax/locale/es.yml | 7 ++-- 4 files changed, 67 insertions(+), 33 deletions(-) diff --git a/modules/invoiceIn/front/tax/index.html b/modules/invoiceIn/front/tax/index.html index 44ceef807..acc9cf492 100644 --- a/modules/invoiceIn/front/tax/index.html +++ b/modules/invoiceIn/front/tax/index.html @@ -35,7 +35,7 @@ {{id}}: {{name}} @@ -105,31 +105,32 @@ - + -
-
{{$ctrl.$t('New expence')}}
+
+
{{$ctrl.$t('New expense')}}
+ ng-model="$ctrl.expense.code" + required="true" + vn-focus> + ng-model="$ctrl.expense.isWithheld"> diff --git a/modules/invoiceIn/front/tax/index.js b/modules/invoiceIn/front/tax/index.js index 48fb98d4e..d05a77f29 100644 --- a/modules/invoiceIn/front/tax/index.js +++ b/modules/invoiceIn/front/tax/index.js @@ -3,6 +3,10 @@ import Section from 'salix/components/section'; import UserError from 'core/lib/user-error'; class Controller extends Section { + constructor($element, $, vnWeekDays) { + super($element, $); + this.expense = {}; + } taxRate(invoiceInTax, taxRateSelection) { const taxTypeSage = taxRateSelection && taxRateSelection.rate; const taxableBase = invoiceInTax && invoiceInTax.taxableBase; @@ -29,23 +33,24 @@ class Controller extends Section { } onResponse() { - if (!this.expence) - throw new UserError(`The fields can't be empty`); - else if (!this.expence.code) - throw new UserError(`The code can't be empty`); - else if (!this.expence.description) - throw new UserError(`The description can't be empty`); + try { + if (!this.expense.code) + throw new Error(`The code can't be empty`); + if (!this.expense.description) + throw new UserError(`The description can't be empty`); - const params = []; - params.push({ - id: this.expence.code, - isWithheld: this.expence.isWithheld, - name: this.expence.description - }); + const data = [{ + id: this.expense.code, + isWithheld: this.expense.isWithheld, + name: this.expense.description + }]; - this.$http.post(`Expenses`, params) .then(() => { - this.vnApp.showSuccess(this.$t('Expence saved!')); - }); + this.$http.post(`Expenses`, data) .then(() => { + this.vnApp.showSuccess(this.$t('Expense saved!')); + }); + } catch (e) { + this.vnApp.showError(this.$t(e.message)); + } } } diff --git a/modules/invoiceIn/front/tax/index.spec.js b/modules/invoiceIn/front/tax/index.spec.js index bc7963899..c62ada9ca 100644 --- a/modules/invoiceIn/front/tax/index.spec.js +++ b/modules/invoiceIn/front/tax/index.spec.js @@ -1,6 +1,7 @@ import './index.js'; import watcher from 'core/mocks/watcher'; import crudModel from 'core/mocks/crud-model'; +const UserError = require('vn-loopback/util/user-error'); describe('InvoiceIn', () => { describe('Component tax', () => { @@ -61,25 +62,51 @@ describe('InvoiceIn', () => { describe('onResponse()', () => { it('should return success message', () => { - controller.expence = { + controller.expense = { code: 7050000005, isWithheld: 0, description: 'Test' }; - const params = [{ - id: controller.expence.code, - isWithheld: controller.expence.isWithheld, - name: controller.expence.description + const data = [{ + id: controller.expense.code, + isWithheld: controller.expense.isWithheld, + name: controller.expense.description }]; jest.spyOn(controller.vnApp, 'showSuccess'); - $httpBackend.expect('POST', `Expenses`, params).respond(); + $httpBackend.expect('POST', `Expenses`, data).respond(); controller.onResponse(); $httpBackend.flush(); - expect(controller.vnApp.showSuccess).toHaveBeenCalledWith('Expence saved!'); + expect(controller.vnApp.showSuccess).toHaveBeenCalledWith('Expense saved!'); + }); + + it('should return an error if code is empty', () => { + controller.expense = { + code: null, + isWithheld: 0, + description: 'Test' + }; + + jest.spyOn(controller.vnApp, 'showError'); + controller.onResponse(); + + expect(controller.vnApp.showError).toHaveBeenCalledWith(`The code can't be empty`); + }); + + it('should return an error if description is empty', () => { + controller.expense = { + code: 7050000005, + isWithheld: 0, + description: null + }; + + jest.spyOn(controller.vnApp, 'showError'); + controller.onResponse(); + + expect(controller.vnApp.showError).toHaveBeenCalledWith(`The description can't be empty`); }); }); }); diff --git a/modules/invoiceIn/front/tax/locale/es.yml b/modules/invoiceIn/front/tax/locale/es.yml index 220802d9a..3ff68ea40 100644 --- a/modules/invoiceIn/front/tax/locale/es.yml +++ b/modules/invoiceIn/front/tax/locale/es.yml @@ -1,6 +1,7 @@ -Create expence: Crear gasto -New expence: Nuevo gasto +Create expense: Crear gasto +New expense: Nuevo gasto It's a withholding: Es una retención The fields can't be empty: Los campos no pueden estar vacíos The code can't be empty: El código no puede estar vacío -The description can't be empty: La descripción no puede estar vacía \ No newline at end of file +The description can't be empty: La descripción no puede estar vacía +Expense saved!: Gasto guardado! \ No newline at end of file -- 2.40.1