2883-invoiceIn-Booking #786

Merged
carlosjr merged 17 commits from 2883-invoiceIn-Booking into dev 2022-01-24 15:29:57 +00:00
4 changed files with 21 additions and 26 deletions
Showing only changes of commit 2dee9fec20 - Show all commits

View File

@ -1,5 +1,5 @@
module.exports = Self => { module.exports = Self => {
Self.remoteMethodCtx('getTotals', { Self.remoteMethod('getTotals', {
description: 'Return totals for an invoiceIn', description: 'Return totals for an invoiceIn',
accessType: 'READ', accessType: 'READ',
accepts: { accepts: {
@ -19,7 +19,7 @@ module.exports = Self => {
} }
}); });
Self.getTotals = async(ctx, id, options) => { Self.getTotals = async(id, options) => {
let tx; let tx;
const myOptions = {}; const myOptions = {};

View File

@ -22,7 +22,6 @@ module.exports = Self => {
}); });
Self.toBook = async(ctx, id, options) => { Self.toBook = async(ctx, id, options) => {
const models = Self.app.models;
let tx; let tx;
const myOptions = {}; const myOptions = {};
@ -35,10 +34,6 @@ module.exports = Self => {
} }
try { try {
const totals = await models.InvoiceIn.getTotals(id);
if (totals.totalDueDay != totals.totalTaxableBase && totals.totalDueDay != totals.totalVal)
throw new UserError(`Amounts do not match`);
await Self.rawSql(`CALL vn.invoiceInBookingMain(?)`, [id], myOptions); await Self.rawSql(`CALL vn.invoiceInBookingMain(?)`, [id], myOptions);
if (tx) await tx.commit(); if (tx) await tx.commit();
} catch (e) { } catch (e) {

View File

@ -51,14 +51,17 @@ class Controller extends Descriptor {
return this.getData(`InvoiceIns/${this.id}`, {filter}) return this.getData(`InvoiceIns/${this.id}`, {filter})
.then(res => this.entity = res.data); .then(res => this.entity = res.data);
} }
checktoBook() { checktoBook() {
jgallego marked this conversation as resolved Outdated

function naming must be in lowerCamelCase

function naming must be in lowerCamelCase
let message = ''; let message = '';
const id = this.invoiceIn.id; const id = this.invoiceIn.id;
this.$q.all([ this.$q.all([
this.$http.get(`InvoiceIns/${this.id}/getTotals`) this.$http.get(`InvoiceIns/${this.id}/getTotals`)
.then(res => { .then(res => {
if (res.data.totalDueDay != res.data.totalTaxableBase && res.data.totalDueDay != res.data.totalVat) const taxableBaseNotEqualDueDay = res.data.totalDueDay != res.data.totalTaxableBase;
message += 'amountsNotMatch'; const vatNotEqualDueDay = res.data.totalDueDay != res.data.totalVat;
if (taxableBaseNotEqualDueDay && vatNotEqualDueDay)
message += 'amountsDoNotMatch';
}), }),
this.$http.get('InvoiceInDueDays/count', { this.$http.get('InvoiceInDueDays/count', {
filter: { filter: {
@ -73,7 +76,7 @@ class Controller extends Descriptor {
}) })
]).finally(() => { ]).finally(() => {
if (message > '') if (message.length)
this.$.confirmToBookAnyway.show(); this.$.confirmToBookAnyway.show();
else else
onAcceptToBook(); onAcceptToBook();
@ -81,8 +84,10 @@ class Controller extends Descriptor {
} }
onAcceptToBook() { onAcceptToBook() {
this.$http.post(`InvoiceIns/${this.id}/toBook`); this.$http.post(`InvoiceIns/${this.id}/toBook`)
this.vnApp.showSuccess(this.$t('InvoiceIn booked')); .then(() => {
this.vnApp.showSuccess(this.$t('InvoiceIn booked'));
});
} }
} }

View File

@ -9,31 +9,26 @@ describe('vnInvoiceInDescriptor', () => {
beforeEach(inject(($componentController, _$httpBackend_) => { beforeEach(inject(($componentController, _$httpBackend_) => {
$httpBackend = _$httpBackend_; $httpBackend = _$httpBackend_;
controller = $componentController('vnInvoiceInDescriptor', {$element: null}); controller = $componentController('vnInvoiceInDescriptor', {$element: null});
controller.invoiceIn = {id: 1};
$httpBackend.when('GET', `InvoiceIns/${controller.invoiceIn.id}`).respond({id: 1});
})); }));
describe('loadData()', () => { describe('loadData()', () => {
it(`should perform a get query to store the invoice in data into the controller`, () => { it(`should perform a get query to store the invoice in data into the controller`, () => {
const id = 1; expect(controller.invoiceIn).toEqual({id: 1});
const response = {id: 1};
$httpBackend.expectGET(`InvoiceIns/${id}`).respond(response);
controller.id = id;
$httpBackend.flush();
expect(controller.invoiceIn).toEqual(response);
}); });
}); });
describe('toBook()', () => { describe('onAcceptToBook()', () => {
it(`should perform a post query to book the invoiSce`, () => { it(`should perform a post query to book the invoice`, () => {
controller.vnApp = {showSuccess: jest.fn()};
const id = 1; const id = 1;
const response = {id: 1};
$httpBackend.expectPOST(`InvoiceIns/${id}/toBook`).respond(response); $httpBackend.expectPOST(`InvoiceIns/${id}/toBook`).respond();
controller.id = id; controller.onAcceptToBook();
$httpBackend.flush(); $httpBackend.flush();
expect(controller.invoiceIn).toEqual(response); expect(controller.vnApp.showSuccess).toHaveBeenCalledWith('InvoiceIn booked');
}); });
}); });
}); });