Merge pull request '3685-fix(invoiceIn_descriptor): add necessary relations to filter' (#909) from 3685-invoiceIn_descriptor into dev
gitea/salix/pipeline/head This commit looks good Details

Reviewed-on: #909
Reviewed-by: Joan Sanchez <joan@verdnatura.es>
This commit is contained in:
Joan Sanchez 2022-03-23 11:27:57 +00:00
commit d5c2fb9857
2 changed files with 26 additions and 5 deletions

View File

@ -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() {

View File

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