diff --git a/src/components/attributes/LeaseInvoiceTabAttributes.js b/src/components/attributes/LeaseInvoiceTabAttributes.js index 6d7044fa0..0384b0389 100644 --- a/src/components/attributes/LeaseInvoiceTabAttributes.js +++ b/src/components/attributes/LeaseInvoiceTabAttributes.js @@ -136,7 +136,7 @@ function LeaseInvoiceTabAttributes(WrappedComponent: any) { fetchLeaseCreateChargeAttributes(); } - if(!isFetchingReceivableTypes && !receivableTypes) { + if(!isFetchingReceivableTypes) { fetchReceivableTypes(); } } diff --git a/src/leaseCreateCharge/helpers.js b/src/leaseCreateCharge/helpers.js index db167205a..7923284e8 100644 --- a/src/leaseCreateCharge/helpers.js +++ b/src/leaseCreateCharge/helpers.js @@ -40,6 +40,8 @@ export const getPayloadLeaseCreateCharge = (invoice: Object): Object => { */ export const receivableTypesFromAttributes = (fieldAttributes: Object, receivableTypes: Object): Object => { // Filter choices where choices receivable_type.is_active === true + // TODO: Fix the logic to define the choices and the current choice + // receivableTypes.find(type => type.id === choice.value) is undefined const newChoices = fieldAttributes.choices.filter(choice => receivableTypes.find(type => type.id === choice.value).is_active); const newFieldAttributes = {...fieldAttributes, choices: newChoices}; return newFieldAttributes; diff --git a/src/leaseCreateCharge/requests.js b/src/leaseCreateCharge/requests.js index 3d668fb91..9b1dc0af6 100644 --- a/src/leaseCreateCharge/requests.js +++ b/src/leaseCreateCharge/requests.js @@ -1,11 +1,15 @@ // @flow import callApi from '../api/callApi'; import createUrl from '../api/createUrl'; +import { store } from "../root/startApp"; +import { getUserActiveServiceUnit } from "../usersPermissions/selectors"; export const fetchAttributes = (): Generator => { return callApi(new Request(createUrl(`lease_create_charge/`), {method: 'OPTIONS'})); }; export const fetchReceivableTypes = (): Generator => { - return callApi(new Request(createUrl(`receivable_type/`), {method: 'GET'})); + const state = store.getState() + const serviceUnit = getUserActiveServiceUnit(state) + return callApi(new Request(createUrl(`receivable_type/`, { service_unit: serviceUnit.id }), {method: 'GET'})); };