refactor: pull request changes
gitea/salix/pipeline/head There was a failure building this commit
Details
gitea/salix/pipeline/head There was a failure building this commit
Details
This commit is contained in:
parent
c749438f32
commit
568579f461
|
@ -35,7 +35,7 @@
|
||||||
<tpl-item>{{id}}: {{name}}</tpl-item>
|
<tpl-item>{{id}}: {{name}}</tpl-item>
|
||||||
<append>
|
<append>
|
||||||
<vn-icon-button
|
<vn-icon-button
|
||||||
vn-tooltip="Create expence"
|
vn-tooltip="Create expense"
|
||||||
icon="add_circle"
|
icon="add_circle"
|
||||||
vn-click-stop="createExpense.show()">
|
vn-click-stop="createExpense.show()">
|
||||||
</vn-icon-button>
|
</vn-icon-button>
|
||||||
|
@ -105,31 +105,32 @@
|
||||||
</vn-button-bar>
|
</vn-button-bar>
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
<!-- Dialog of create expence-->
|
<!-- Dialog of create expense-->
|
||||||
<vn-dialog
|
<vn-dialog
|
||||||
vn-id="createExpense"
|
vn-id="createExpense"
|
||||||
on-accept="$ctrl.onResponse()">
|
on-accept="$ctrl.onResponse()">
|
||||||
<tpl-body>
|
<tpl-body>
|
||||||
<section class="SMSDialog">
|
<section>
|
||||||
<h5 class="vn-py-sm">{{$ctrl.$t('New expence')}}</h5>
|
<h5 class="vn-py-sm">{{$ctrl.$t('New expense')}}</h5>
|
||||||
<vn-horizontal>
|
<vn-horizontal>
|
||||||
<vn-textfield vn-one
|
<vn-textfield vn-one
|
||||||
vn-id="code"
|
vn-id="code"
|
||||||
label="Code"
|
label="Code"
|
||||||
ng-model="$ctrl.expence.code"
|
ng-model="$ctrl.expense.code"
|
||||||
required="true">
|
required="true"
|
||||||
|
vn-focus>
|
||||||
</vn-textfield>
|
</vn-textfield>
|
||||||
<vn-check
|
<vn-check
|
||||||
vn-one
|
vn-one
|
||||||
label="It's a withholding"
|
label="It's a withholding"
|
||||||
ng-model="$ctrl.expence.isWithheld">
|
ng-model="$ctrl.expense.isWithheld">
|
||||||
</vn-check>
|
</vn-check>
|
||||||
</vn-horizontal>
|
</vn-horizontal>
|
||||||
<vn-horizontal>
|
<vn-horizontal>
|
||||||
<vn-textfield vn-one
|
<vn-textfield vn-one
|
||||||
vn-id="description"
|
vn-id="description"
|
||||||
label="Description"
|
label="Description"
|
||||||
ng-model="$ctrl.expence.description"
|
ng-model="$ctrl.expense.description"
|
||||||
required="true">
|
required="true">
|
||||||
</vn-textfield>
|
</vn-textfield>
|
||||||
</vn-horizontal>
|
</vn-horizontal>
|
||||||
|
|
|
@ -3,6 +3,10 @@ import Section from 'salix/components/section';
|
||||||
import UserError from 'core/lib/user-error';
|
import UserError from 'core/lib/user-error';
|
||||||
|
|
||||||
class Controller extends Section {
|
class Controller extends Section {
|
||||||
|
constructor($element, $, vnWeekDays) {
|
||||||
|
super($element, $);
|
||||||
|
this.expense = {};
|
||||||
|
}
|
||||||
taxRate(invoiceInTax, taxRateSelection) {
|
taxRate(invoiceInTax, taxRateSelection) {
|
||||||
const taxTypeSage = taxRateSelection && taxRateSelection.rate;
|
const taxTypeSage = taxRateSelection && taxRateSelection.rate;
|
||||||
const taxableBase = invoiceInTax && invoiceInTax.taxableBase;
|
const taxableBase = invoiceInTax && invoiceInTax.taxableBase;
|
||||||
|
@ -29,23 +33,24 @@ class Controller extends Section {
|
||||||
}
|
}
|
||||||
|
|
||||||
onResponse() {
|
onResponse() {
|
||||||
if (!this.expence)
|
try {
|
||||||
throw new UserError(`The fields can't be empty`);
|
if (!this.expense.code)
|
||||||
else if (!this.expence.code)
|
throw new Error(`The code can't be empty`);
|
||||||
throw new UserError(`The code can't be empty`);
|
if (!this.expense.description)
|
||||||
else if (!this.expence.description)
|
throw new UserError(`The description can't be empty`);
|
||||||
throw new UserError(`The description can't be empty`);
|
|
||||||
|
|
||||||
const params = [];
|
const data = [{
|
||||||
params.push({
|
id: this.expense.code,
|
||||||
id: this.expence.code,
|
isWithheld: this.expense.isWithheld,
|
||||||
isWithheld: this.expence.isWithheld,
|
name: this.expense.description
|
||||||
name: this.expence.description
|
}];
|
||||||
});
|
|
||||||
|
|
||||||
this.$http.post(`Expenses`, params) .then(() => {
|
this.$http.post(`Expenses`, data) .then(() => {
|
||||||
this.vnApp.showSuccess(this.$t('Expence saved!'));
|
this.vnApp.showSuccess(this.$t('Expense saved!'));
|
||||||
});
|
});
|
||||||
|
} catch (e) {
|
||||||
|
this.vnApp.showError(this.$t(e.message));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
import './index.js';
|
import './index.js';
|
||||||
import watcher from 'core/mocks/watcher';
|
import watcher from 'core/mocks/watcher';
|
||||||
import crudModel from 'core/mocks/crud-model';
|
import crudModel from 'core/mocks/crud-model';
|
||||||
|
const UserError = require('vn-loopback/util/user-error');
|
||||||
|
|
||||||
describe('InvoiceIn', () => {
|
describe('InvoiceIn', () => {
|
||||||
describe('Component tax', () => {
|
describe('Component tax', () => {
|
||||||
|
@ -61,25 +62,51 @@ describe('InvoiceIn', () => {
|
||||||
|
|
||||||
describe('onResponse()', () => {
|
describe('onResponse()', () => {
|
||||||
it('should return success message', () => {
|
it('should return success message', () => {
|
||||||
controller.expence = {
|
controller.expense = {
|
||||||
code: 7050000005,
|
code: 7050000005,
|
||||||
isWithheld: 0,
|
isWithheld: 0,
|
||||||
description: 'Test'
|
description: 'Test'
|
||||||
};
|
};
|
||||||
|
|
||||||
const params = [{
|
const data = [{
|
||||||
id: controller.expence.code,
|
id: controller.expense.code,
|
||||||
isWithheld: controller.expence.isWithheld,
|
isWithheld: controller.expense.isWithheld,
|
||||||
name: controller.expence.description
|
name: controller.expense.description
|
||||||
}];
|
}];
|
||||||
|
|
||||||
jest.spyOn(controller.vnApp, 'showSuccess');
|
jest.spyOn(controller.vnApp, 'showSuccess');
|
||||||
$httpBackend.expect('POST', `Expenses`, params).respond();
|
$httpBackend.expect('POST', `Expenses`, data).respond();
|
||||||
|
|
||||||
controller.onResponse();
|
controller.onResponse();
|
||||||
$httpBackend.flush();
|
$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`);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
Create expence: Crear gasto
|
Create expense: Crear gasto
|
||||||
New expence: Nuevo gasto
|
New expense: Nuevo gasto
|
||||||
It's a withholding: Es una retención
|
It's a withholding: Es una retención
|
||||||
The fields can't be empty: Los campos no pueden estar vacíos
|
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 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
|
The description can't be empty: La descripción no puede estar vacía
|
||||||
|
Expense saved!: Gasto guardado!
|
Loading…
Reference in New Issue