From a6b867430253eeff957d5a4dd55c6404291ccf05 Mon Sep 17 00:00:00 2001 From: vicent Date: Mon, 9 May 2022 14:34:20 +0200 Subject: [PATCH] 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 0000000000..55ca8c3895 --- /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 c495d44d2f..7a3a9b3330 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 53cfc55980..48fb98d4ea 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 20d5d40d86..bc79638994 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 0000000000..220802d9af --- /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 65af020139..5120f07bc1 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