Merge pull request '2974- Set user company as default on client balance' (#674) from 2974-client_balance into dev
gitea/salix/pipeline/head This commit looks good
Details
gitea/salix/pipeline/head This commit looks good
Details
Reviewed-on: #674 Reviewed-by: Carlos Jimenez Ruiz <carlosjr@verdnatura.es>
This commit is contained in:
commit
790c3729aa
|
@ -20,9 +20,8 @@
|
|||
label="Company"
|
||||
show-field="code"
|
||||
value-field="id"
|
||||
ng-model="$ctrl.receipt.companyFk"
|
||||
required="true"
|
||||
rule>
|
||||
ng-model="$ctrl.companyFk"
|
||||
required="true">
|
||||
</vn-autocomplete>
|
||||
</vn-horizontal>
|
||||
<vn-horizontal>
|
||||
|
@ -78,6 +77,12 @@
|
|||
on-change="$ctrl.accountShortToStandard(value)">
|
||||
</vn-textfield>
|
||||
</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-buttons>
|
||||
<input type="button" response="cancel" translate-attr="{value: 'Cancel'}"/>
|
||||
|
|
|
@ -2,9 +2,10 @@ import ngModule from '../../module';
|
|||
import Dialog from 'core/components/dialog';
|
||||
|
||||
class Controller extends Dialog {
|
||||
constructor($element, $, $transclude) {
|
||||
constructor($element, $, $transclude, vnReport) {
|
||||
super($element, $, $transclude);
|
||||
|
||||
this.vnReport = vnReport;
|
||||
this.receipt = {
|
||||
payed: new Date()
|
||||
};
|
||||
|
@ -31,6 +32,12 @@ class Controller extends Dialog {
|
|||
return this.receipt.clientFk;
|
||||
}
|
||||
|
||||
get companyFk() {
|
||||
if (!this.receipt.companyFk)
|
||||
this.receipt.companyFk = this.vnConfig.companyFk;
|
||||
return this.receipt.companyFk;
|
||||
}
|
||||
|
||||
set companyFk(value) {
|
||||
this.receipt.companyFk = value;
|
||||
this.getAmountPaid();
|
||||
|
@ -62,6 +69,22 @@ class Controller extends Dialog {
|
|||
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() {
|
||||
return this._deliveredAmount;
|
||||
}
|
||||
|
@ -98,12 +121,26 @@ class Controller extends Dialog {
|
|||
if (response !== 'accept')
|
||||
return super.responseHandler(response);
|
||||
|
||||
let receiptId;
|
||||
return this.$http.post(`Clients/${this.clientFk}/createReceipt`, this.receipt)
|
||||
.then(() => super.responseHandler(response))
|
||||
.then(() => this.vnApp.showSuccess(this.$t('Data saved!')));
|
||||
.then(res => {
|
||||
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', {
|
||||
slotTemplate: require('./index.html'),
|
||||
controller: Controller,
|
||||
|
|
|
@ -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()', () => {
|
||||
it('should make an http GET query and then set the receipt amountPaid property', () => {
|
||||
controller.$params = {id: 101};
|
||||
|
@ -62,6 +70,7 @@ describe('Client', () => {
|
|||
describe('responseHandler()', () => {
|
||||
it('should make an http POST query and then call to the parent responseHandler() method', () => {
|
||||
jest.spyOn(controller.vnApp, 'showSuccess');
|
||||
jest.spyOn(controller.vnReport, 'show');
|
||||
|
||||
controller.$params = {id: 101};
|
||||
|
||||
|
@ -70,6 +79,25 @@ describe('Client', () => {
|
|||
$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: 101};
|
||||
controller.viewReceipt = true;
|
||||
|
||||
$httpBackend.expect('POST', `Clients/101/createReceipt`).respond({id: 1});
|
||||
controller.responseHandler('accept');
|
||||
$httpBackend.flush();
|
||||
|
||||
const expectedParams = {receiptId: 1, companyId: 442};
|
||||
|
||||
expect(controller.vnApp.showSuccess).toHaveBeenCalled();
|
||||
expect(controller.vnReport.show).toHaveBeenCalledWith('receipt', expectedParams);
|
||||
});
|
||||
});
|
||||
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
View receipt: Ver recibo
|
Loading…
Reference in New Issue