From 7a17fe2cbae9d5e573c3c5d28b4cbfd498ef5957 Mon Sep 17 00:00:00 2001 From: alexm Date: Wed, 23 Mar 2022 10:36:00 +0100 Subject: [PATCH] fix(invoiceIn_descriptor): add necessary relations to filter --- modules/invoiceIn/front/descriptor/index.js | 14 +++++++++++--- .../invoiceIn/front/descriptor/index.spec.js | 17 +++++++++++++++-- 2 files changed, 26 insertions(+), 5 deletions(-) diff --git a/modules/invoiceIn/front/descriptor/index.js b/modules/invoiceIn/front/descriptor/index.js index 952692496..cde324296 100644 --- a/modules/invoiceIn/front/descriptor/index.js +++ b/modules/invoiceIn/front/descriptor/index.js @@ -39,17 +39,25 @@ class Controller extends Descriptor { loadData() { const filter = { include: [ - { - relation: 'company', + {relation: 'supplier'}, + {relation: 'invoiceInDueDay'}, + {relation: 'company', scope: { fields: ['id', 'code'] } } + ] }; return this.getData(`InvoiceIns/${this.id}`, {filter}) - .then(res => this.entity = res.data); + .then(res => { + this.entity = res.data; + this.invoiceIn.amount = res.data.invoiceInDueDay.reduce( + (accumulator, currentValue) => { + return accumulator + (currentValue['amount'] || 0); + }, 0); + }); } checkToBook() { diff --git a/modules/invoiceIn/front/descriptor/index.spec.js b/modules/invoiceIn/front/descriptor/index.spec.js index 46815c155..7e061007f 100644 --- a/modules/invoiceIn/front/descriptor/index.spec.js +++ b/modules/invoiceIn/front/descriptor/index.spec.js @@ -12,12 +12,25 @@ describe('vnInvoiceInDescriptor', () => { controller = $componentController('vnInvoiceInDescriptor', {$element}); controller.invoiceIn = {id: 1}; - $httpBackend.when('GET', `InvoiceIns/${controller.invoiceIn.id}`).respond({id: 1}); })); describe('loadData()', () => { it(`should perform a get query to store the invoice in data into the controller`, () => { - expect(controller.invoiceIn).toEqual({id: 1}); + const invoiceIn = { + id: 1, + invoiceInDueDay: [ + {amount: 1}, + {amount: 2} + ] + }; + const expectedAmount = invoiceIn.invoiceInDueDay[0].amount + invoiceIn.invoiceInDueDay[1].amount; + + $httpBackend.when('GET', `InvoiceIns/${controller.invoiceIn.id}`).respond(invoiceIn); + controller.loadData(); + $httpBackend.flush(); + + expect(controller.invoiceIn.id).toEqual(invoiceIn.id); + expect(controller.invoiceIn.amount).toEqual(expectedAmount); }); });