Merge branch 'dev' of https://gitea.verdnatura.es/verdnatura/salix into 2997-export_production_rebuild

This commit is contained in:
Carlos Jimenez Ruiz 2021-06-23 14:20:12 +02:00
commit 2da72fc993
6 changed files with 82 additions and 12 deletions

View File

@ -1,10 +1,9 @@
<div ng-if="$ctrl.model.moreRows"> <div ng-if="$ctrl.model.moreRows">
<vn-icon-button <vn-button
ng-if="!$ctrl.model.isPaging" ng-if="!$ctrl.model.isPaging"
icon="more_horiz" label="Load more results"
vn-tooltip="Load more"
ng-click="$ctrl.onLoadClick()"> ng-click="$ctrl.onLoadClick()">
</vn-icon-button> </vn-button>
<vn-spinner <vn-spinner
ng-if="$ctrl.model.isPaging" ng-if="$ctrl.model.isPaging"
enable="::true"> enable="::true">

View File

@ -62,5 +62,5 @@ Go up: Ir arriba
Loading...: Cargando... Loading...: Cargando...
No results found: Sin resultados No results found: Sin resultados
No data: Sin datos No data: Sin datos
Load more: Cargar más Undo changes: Deshacer cambios
Undo changes: Deshacer cambios Load more results: Cargar más resultados

View File

@ -20,9 +20,8 @@
label="Company" label="Company"
show-field="code" show-field="code"
value-field="id" value-field="id"
ng-model="$ctrl.receipt.companyFk" ng-model="$ctrl.companyFk"
required="true" required="true">
rule>
</vn-autocomplete> </vn-autocomplete>
</vn-horizontal> </vn-horizontal>
<vn-horizontal> <vn-horizontal>
@ -78,6 +77,12 @@
on-change="$ctrl.accountShortToStandard(value)"> on-change="$ctrl.accountShortToStandard(value)">
</vn-textfield> </vn-textfield>
</vn-vertical> </vn-vertical>
<vn-horizontal ng-show="$ctrl.bankSelection.accountingType.code == 'cash'">
<vn-check
label="View receipt"
ng-model="$ctrl.viewReceipt">
</vn-check>
</vn-horizontal>
</tpl-body> </tpl-body>
<tpl-buttons> <tpl-buttons>
<input type="button" response="cancel" translate-attr="{value: 'Cancel'}"/> <input type="button" response="cancel" translate-attr="{value: 'Cancel'}"/>

View File

@ -2,9 +2,10 @@ import ngModule from '../../module';
import Dialog from 'core/components/dialog'; import Dialog from 'core/components/dialog';
class Controller extends Dialog { class Controller extends Dialog {
constructor($element, $, $transclude) { constructor($element, $, $transclude, vnReport) {
super($element, $, $transclude); super($element, $, $transclude);
this.vnReport = vnReport;
this.receipt = { this.receipt = {
payed: new Date() payed: new Date()
}; };
@ -31,6 +32,12 @@ class Controller extends Dialog {
return this.receipt.clientFk; return this.receipt.clientFk;
} }
get companyFk() {
if (!this.receipt.companyFk)
this.receipt.companyFk = this.vnConfig.companyFk;
return this.receipt.companyFk;
}
set companyFk(value) { set companyFk(value) {
this.receipt.companyFk = value; this.receipt.companyFk = value;
this.getAmountPaid(); this.getAmountPaid();
@ -62,6 +69,22 @@ class Controller extends Dialog {
this.amountToReturn = value - this.receipt.amountPaid; this.amountToReturn = value - this.receipt.amountPaid;
} }
get amountToReturn() {
return this._amountToReturn;
}
set amountToReturn(value) {
if (!value) return;
value = value.toFixed(2);
if (Number.isInteger(value))
value = parseInt(value);
else value = parseFloat(value);
this._amountToReturn = value;
}
get deliveredAmount() { get deliveredAmount() {
return this._deliveredAmount; return this._deliveredAmount;
} }
@ -98,12 +121,26 @@ class Controller extends Dialog {
if (response !== 'accept') if (response !== 'accept')
return super.responseHandler(response); return super.responseHandler(response);
let receiptId;
return this.$http.post(`Clients/${this.clientFk}/createReceipt`, this.receipt) return this.$http.post(`Clients/${this.clientFk}/createReceipt`, this.receipt)
.then(() => super.responseHandler(response)) .then(res => {
.then(() => this.vnApp.showSuccess(this.$t('Data saved!'))); receiptId = res.data.id;
super.responseHandler(response);
})
.then(() => this.vnApp.showSuccess(this.$t('Data saved!')))
.then(() => {
if (this.viewReceipt) {
this.vnReport.show('receipt', {
receiptId: receiptId,
companyId: this.companyFk
});
}
});
} }
} }
Controller.$inject = ['$element', '$scope', '$transclude', 'vnReport'];
ngModule.vnComponent('vnClientBalanceCreate', { ngModule.vnComponent('vnClientBalanceCreate', {
slotTemplate: require('./index.html'), slotTemplate: require('./index.html'),
controller: Controller, controller: Controller,

View File

@ -40,6 +40,14 @@ describe('Client', () => {
}); });
}); });
describe('amountToReturn() setter', () => {
it('should set the amount to return with a maximum of two decimals', () => {
controller.amountToReturn = 200.1451789;
expect(controller.amountToReturn).toEqual(200.15);
});
});
describe('getAmountPaid()', () => { describe('getAmountPaid()', () => {
it('should make an http GET query and then set the receipt amountPaid property', () => { it('should make an http GET query and then set the receipt amountPaid property', () => {
controller.$params = {id: 1101}; controller.$params = {id: 1101};
@ -62,14 +70,34 @@ describe('Client', () => {
describe('responseHandler()', () => { describe('responseHandler()', () => {
it('should make an http POST query and then call to the parent responseHandler() method', () => { it('should make an http POST query and then call to the parent responseHandler() method', () => {
jest.spyOn(controller.vnApp, 'showSuccess'); jest.spyOn(controller.vnApp, 'showSuccess');
jest.spyOn(controller.vnReport, 'show');
controller.$params = {id: 101};
$httpBackend.expect('POST', `Clients/101/createReceipt`).respond({id: 1});
controller.responseHandler('accept');
$httpBackend.flush();
expect(controller.vnApp.showSuccess).toHaveBeenCalled();
expect(controller.vnReport.show).not.toHaveBeenCalled();
});
it('should make an http POST query and then call to the report show() method', () => {
jest.spyOn(controller.vnApp, 'showSuccess');
jest.spyOn(controller.vnReport, 'show');
window.open = jest.fn();
controller.$params = {id: 1101}; controller.$params = {id: 1101};
controller.viewReceipt = true;
$httpBackend.expect('POST', `Clients/1101/createReceipt`).respond({id: 1}); $httpBackend.expect('POST', `Clients/1101/createReceipt`).respond({id: 1});
controller.responseHandler('accept'); controller.responseHandler('accept');
$httpBackend.flush(); $httpBackend.flush();
const expectedParams = {receiptId: 1, companyId: 442};
expect(controller.vnApp.showSuccess).toHaveBeenCalled(); expect(controller.vnApp.showSuccess).toHaveBeenCalled();
expect(controller.vnReport.show).toHaveBeenCalledWith('receipt', expectedParams);
}); });
}); });

View File

@ -0,0 +1 @@
View receipt: Ver recibo