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); }); });