refactor: pull request changes
gitea/salix/pipeline/head There was a failure building this commit Details

This commit is contained in:
Vicent Llopis 2022-05-12 08:27:04 +02:00
parent c749438f32
commit 568579f461
4 changed files with 67 additions and 33 deletions

View File

@ -35,7 +35,7 @@
<tpl-item>{{id}}: {{name}}</tpl-item>
<append>
<vn-icon-button
vn-tooltip="Create expence"
vn-tooltip="Create expense"
icon="add_circle"
vn-click-stop="createExpense.show()">
</vn-icon-button>
@ -105,31 +105,32 @@
</vn-button-bar>
</form>
<!-- Dialog of create expence-->
<!-- Dialog of create expense-->
<vn-dialog
vn-id="createExpense"
on-accept="$ctrl.onResponse()">
<tpl-body>
<section class="SMSDialog">
<h5 class="vn-py-sm">{{$ctrl.$t('New expence')}}</h5>
<section>
<h5 class="vn-py-sm">{{$ctrl.$t('New expense')}}</h5>
<vn-horizontal>
<vn-textfield vn-one
vn-id="code"
label="Code"
ng-model="$ctrl.expence.code"
required="true">
ng-model="$ctrl.expense.code"
required="true"
vn-focus>
</vn-textfield>
<vn-check
vn-one
label="It's a withholding"
ng-model="$ctrl.expence.isWithheld">
ng-model="$ctrl.expense.isWithheld">
</vn-check>
</vn-horizontal>
<vn-horizontal>
<vn-textfield vn-one
vn-id="description"
label="Description"
ng-model="$ctrl.expence.description"
ng-model="$ctrl.expense.description"
required="true">
</vn-textfield>
</vn-horizontal>

View File

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

View File

@ -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`);
});
});
});

View File

@ -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
The description can't be empty: La descripción no puede estar vacía
Expense saved!: Gasto guardado!