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/e2e/helpers/selectors.js b/e2e/helpers/selectors.js
index 2ecb73960..48f483450 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 c495d44d2..acc9cf492 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 expense')}}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/modules/invoiceIn/front/tax/index.js b/modules/invoiceIn/front/tax/index.js
index 53cfc5598..d05a77f29 100644
--- a/modules/invoiceIn/front/tax/index.js
+++ b/modules/invoiceIn/front/tax/index.js
@@ -1,7 +1,12 @@
import ngModule from '../module';
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;
@@ -26,6 +31,27 @@ class Controller extends Section {
this.card.reload();
});
}
+
+ onResponse() {
+ 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 data = [{
+ id: this.expense.code,
+ isWithheld: this.expense.isWithheld,
+ name: this.expense.description
+ }];
+
+ this.$http.post(`Expenses`, data) .then(() => {
+ this.vnApp.showSuccess(this.$t('Expense saved!'));
+ });
+ } catch (e) {
+ this.vnApp.showError(this.$t(e.message));
+ }
+ }
}
ngModule.vnComponent('vnInvoiceInTax', {
diff --git a/modules/invoiceIn/front/tax/index.spec.js b/modules/invoiceIn/front/tax/index.spec.js
index 20d5d40d8..c62ada9ca 100644
--- a/modules/invoiceIn/front/tax/index.spec.js
+++ b/modules/invoiceIn/front/tax/index.spec.js
@@ -1,16 +1,19 @@
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', () => {
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 +22,7 @@ describe('InvoiceIn', () => {
const $element = angular.element('');
controller = $componentController('vnInvoiceInTax', {$element, $scope});
+ controller.$.model = crudModel;
controller.invoiceIn = {id: 1};
}));
@@ -55,5 +59,56 @@ describe('InvoiceIn', () => {
expect(controller.card.reload).toHaveBeenCalledWith();
});
});
+
+ describe('onResponse()', () => {
+ it('should return success message', () => {
+ controller.expense = {
+ code: 7050000005,
+ isWithheld: 0,
+ description: 'Test'
+ };
+
+ const data = [{
+ id: controller.expense.code,
+ isWithheld: controller.expense.isWithheld,
+ name: controller.expense.description
+ }];
+
+ jest.spyOn(controller.vnApp, 'showSuccess');
+ $httpBackend.expect('POST', `Expenses`, data).respond();
+
+ controller.onResponse();
+ $httpBackend.flush();
+
+ 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
new file mode 100644
index 000000000..3ff68ea40
--- /dev/null
+++ b/modules/invoiceIn/front/tax/locale/es.yml
@@ -0,0 +1,7 @@
+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
+Expense saved!: Gasto guardado!
\ 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