feat(invoiceIn.tax): add button for create an expence
gitea/salix/pipeline/head There was a failure building this commit Details

This commit is contained in:
Vicent Llopis 2022-05-09 14:34:20 +02:00
parent f380d5fd28
commit a6b8674302
6 changed files with 106 additions and 14 deletions

View File

@ -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');

View File

@ -33,6 +33,13 @@
show-field="id" show-field="id"
rule> rule>
<tpl-item>{{id}}: {{name}}</tpl-item> <tpl-item>{{id}}: {{name}}</tpl-item>
<append>
<vn-icon-button
vn-tooltip="Create expence"
icon="add_circle"
vn-click-stop="createExpense.show()">
</vn-icon-button>
</append>
</vn-autocomplete> </vn-autocomplete>
<vn-input-number vn-one <vn-input-number vn-one
disabled="$ctrl.invoiceIn.currency.code != 'EUR'" disabled="$ctrl.invoiceIn.currency.code != 'EUR'"
@ -97,3 +104,39 @@
</vn-submit> </vn-submit>
</vn-button-bar> </vn-button-bar>
</form> </form>
<!-- Dialog of add notes button -->
<vn-dialog
vn-id="createExpense"
on-accept="$ctrl.onResponse()">
<tpl-body>
<section class="SMSDialog">
<h5 class="vn-py-sm">{{$ctrl.$t('New expence')}}</h5>
<vn-horizontal>
<vn-textfield vn-one
vn-id="code"
label="Code"
ng-model="$ctrl.expence.code"
required="true">
</vn-textfield>
<vn-check
vn-one
label="It's a withholding"
ng-model="$ctrl.expence.isWithheld">
</vn-check>
</vn-horizontal>
<vn-horizontal>
<vn-textfield vn-one
vn-id="description"
label="Description"
ng-model="$ctrl.expence.description"
required="true">
</vn-textfield>
</vn-horizontal>
</section>
</tpl-body>
<tpl-buttons>
<input type="button" response="cancel" translate-attr="{value: 'Cancel'}"/>
<button response="accept" translate>Save</button>
</tpl-buttons>
</vn-dialog>

View File

@ -1,5 +1,6 @@
import ngModule from '../module'; import ngModule from '../module';
import Section from 'salix/components/section'; import Section from 'salix/components/section';
import UserError from 'core/lib/user-error';
class Controller extends Section { class Controller extends Section {
taxRate(invoiceInTax, taxRateSelection) { taxRate(invoiceInTax, taxRateSelection) {
@ -26,6 +27,26 @@ class Controller extends Section {
this.card.reload(); 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', { ngModule.vnComponent('vnInvoiceInTax', {

View File

@ -7,10 +7,12 @@ describe('InvoiceIn', () => {
let controller; let controller;
let $scope; let $scope;
let vnApp; let vnApp;
let $httpBackend;
beforeEach(ngModule('invoiceIn')); beforeEach(ngModule('invoiceIn'));
beforeEach(inject(($componentController, $rootScope, _vnApp_) => { beforeEach(inject(($componentController, $rootScope, _vnApp_, _$httpBackend_) => {
$httpBackend = _$httpBackend_;
vnApp = _vnApp_; vnApp = _vnApp_;
jest.spyOn(vnApp, 'showError'); jest.spyOn(vnApp, 'showError');
$scope = $rootScope.$new(); $scope = $rootScope.$new();
@ -19,6 +21,7 @@ describe('InvoiceIn', () => {
const $element = angular.element('<vn-invoice-in-tax></vn-invoice-in-tax>'); const $element = angular.element('<vn-invoice-in-tax></vn-invoice-in-tax>');
controller = $componentController('vnInvoiceInTax', {$element, $scope}); controller = $componentController('vnInvoiceInTax', {$element, $scope});
controller.$.model = crudModel;
controller.invoiceIn = {id: 1}; controller.invoiceIn = {id: 1};
})); }));
@ -55,5 +58,30 @@ describe('InvoiceIn', () => {
expect(controller.card.reload).toHaveBeenCalledWith(); 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!');
});
});
}); });
}); });

View File

@ -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

View File

@ -17,9 +17,6 @@
}, },
"isWithheld": { "isWithheld": {
"type": "number" "type": "number"
},
"taxTypeFk": {
"type": "number"
} }
}, },
"relations": { "relations": {
@ -28,13 +25,5 @@
"model": "TaxType", "model": "TaxType",
"foreignKey": "taxTypeFk" "foreignKey": "taxTypeFk"
} }
}, }
"acls": [
{
"accessType": "READ",
"principalType": "ROLE",
"principalId": "$everyone",
"permission": "ALLOW"
}
]
} }