fixes #5633 Reutilizar accountShortToStandard en un nuevo componente #1541

Closed
alexandre wants to merge 20 commits from 5633-accountShortToStandard into dev
9 changed files with 91 additions and 19 deletions

View File

@ -625,6 +625,7 @@ let actions = {
switch (tagName) { switch (tagName) {
case 'vn-textfield': case 'vn-textfield':
case 'vn-account-number':
case 'vn-datalist': case 'vn-datalist':
case 'vn-input-number': case 'vn-input-number':
await this.clearInput(selector); await this.clearInput(selector);
@ -667,6 +668,7 @@ let actions = {
switch (tagName) { switch (tagName) {
case 'vn-textfield': case 'vn-textfield':
case 'vn-account-number':
case 'vn-autocomplete': case 'vn-autocomplete':
case 'vn-worker-autocomplete': case 'vn-worker-autocomplete':
case 'vn-input-time': case 'vn-input-time':

View File

@ -37,6 +37,7 @@ describe('Supplier fiscal data path', () => {
const message = await page.sendForm(form, values); const message = await page.sendForm(form, values);
await page.reloadSection('supplier.card.fiscalData'); await page.reloadSection('supplier.card.fiscalData');
const formValues = await page.fetchForm(form, Object.keys(values)); const formValues = await page.fetchForm(form, Object.keys(values));
expect(errorMessage.text).toContain('Invalid Tax number'); expect(errorMessage.text).toContain('Invalid Tax number');

View File

@ -0,0 +1,22 @@
import Textfield from '../textfield/textfield';
import ngModule from '../../module';
export default class AccountNumber extends Textfield {
constructor($element, $) {
super($element, $);
super.insertable = true;
super.maxLength = 10;
this.element.addEventListener('change', () => this.accountShortToStandard());
}
accountShortToStandard() {
this.field = this.field.replace('.', '0'.repeat(11 - this.field.length));
this.$.$emit('accountShortToStandard', this.field);
}
}
AccountNumber.$inject = ['$element', '$scope'];
ngModule.vnComponent('vnAccountNumber', {
controller: AccountNumber,
});

View File

@ -0,0 +1,27 @@
describe('Component vnAccountNumber', () => {
let controller;
let $element;
beforeEach(ngModule('vnCore'));
beforeEach(inject(($compile, $rootScope) => {
$element = $compile(`<vn-account-number></vn-account-number>`)($rootScope);
controller = $element.controller('vnAccountNumber');
controller.$ = {$emit: jest.fn()};
}));
afterEach(() => {
$element.remove();
});
describe('accountShortToStandard', () => {
it('should replace dots and emit event with account number', () => {
controller.field = '41.1';
const expectedAccountNumber = '4100000001';
controller.accountShortToStandard();
expect(controller.$.$emit).toHaveBeenCalledWith('accountShortToStandard', expectedAccountNumber);
});
});
});

View File

@ -57,4 +57,5 @@ import './datalist';
import './contextmenu'; import './contextmenu';
import './rating'; import './rating';
import './smart-table'; import './smart-table';
import './account-number';
import './support-dialog'; import './support-dialog';

View File

@ -54,12 +54,12 @@
</vn-horizontal> </vn-horizontal>
<vn-vertical ng-show="$ctrl.bankSelection.accountingType.code == 'compensation'"> <vn-vertical ng-show="$ctrl.bankSelection.accountingType.code == 'compensation'">
<h6 translate>Compensation</h6> <h6 translate>Compensation</h6>
<vn-textfield <vn-account-number
ng-model="$ctrl.receipt.compensationAccount" vn-one
vn-name="compensationAccount"
label="Compensation Account" label="Compensation Account"
on-change="$ctrl.accountShortToStandard(value)"> vn-name="compensationAccount"
</vn-textfield> ng-model="$ctrl.receipt.compensationAccount">
</vn-account-number>
</vn-vertical> </vn-vertical>
<vn-horizontal> <vn-horizontal>
<vn-textfield <vn-textfield

View File

@ -127,9 +127,9 @@ class Controller extends Dialog {
this.receipt.bankFk = value; this.receipt.bankFk = value;
} }
accountShortToStandard(value) { getClientOrSupplierReference(value) {
if (value) { this.receipt.compensationAccount = value;
this.receipt.compensationAccount = value.replace('.', '0'.repeat(11 - value.length)); if (this.receipt.compensationAccount) {
const params = {bankAccount: this.receipt.compensationAccount}; const params = {bankAccount: this.receipt.compensationAccount};
this.$http.get(`Clients/getClientOrSupplierReference`, {params}) this.$http.get(`Clients/getClientOrSupplierReference`, {params})
.then(res => { .then(res => {

View File

@ -112,12 +112,34 @@ describe('Client', () => {
}); });
}); });
describe('accountShortToStandard()', () => { describe('getClientOrSupplierReference', () => {
it('should get de account in stardard format', () => { it('should update receipt description when compensation account is provided', async() => {
const shortAccount = '4.3'; jest.spyOn(controller, '$t');
controller.accountShortToStandard(shortAccount); const mockValue = '4100000001';
const mockResponse = {
clientId: '1',
clientName: 'Client mocked'
};
expect(controller.receipt.compensationAccount).toEqual('4000000003'); $httpBackend
.expectGET(`Clients/getClientOrSupplierReference?bankAccount=${mockValue}`)
.respond(mockResponse);
controller.getClientOrSupplierReference(mockValue);
$httpBackend.flush();
expect(controller.receipt.compensationAccount).toBe(mockValue);
expect(controller.receipt.description).toBe('Client Compensation Reference');
expect(controller.$t).toHaveBeenCalledWith('Client Compensation Reference', {
clientId: mockResponse.clientId,
clientName: mockResponse.clientName
});
});
it('should update receipt description to empty string if compensation account is not provided', async() => {
controller.getClientOrSupplierReference('');
expect(controller.receipt.compensationAccount).toBe('');
expect(controller.receipt.description).toBe('');
}); });
}); });

View File

@ -58,15 +58,12 @@
</vn-textfield> </vn-textfield>
</vn-horizontal> </vn-horizontal>
<vn-horizontal> <vn-horizontal>
<vn-textfield <vn-account-number
vn-one vn-one
label="Account" label="Account"
vn-name="account" vn-name="account"
ng-model="$ctrl.supplier.account" ng-model="$ctrl.supplier.account">
insertable="true" </vn-account-number>
max-length="10"
rule>
</vn-textfield>
<vn-autocomplete <vn-autocomplete
vn-one vn-one
label="Sage tax type" label="Sage tax type"