Skip to content

Commit

Permalink
wip: filter receivable types by service unit
Browse files Browse the repository at this point in the history
  • Loading branch information
NC-jsAhonen committed Jan 8, 2024
1 parent 17cf456 commit a1bb88d
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/components/attributes/LeaseInvoiceTabAttributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ function LeaseInvoiceTabAttributes(WrappedComponent: any) {
fetchLeaseCreateChargeAttributes();
}

if(!isFetchingReceivableTypes && !receivableTypes) {
if(!isFetchingReceivableTypes) {
fetchReceivableTypes();
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/leaseCreateCharge/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 5 additions & 1 deletion src/leaseCreateCharge/requests.js
Original file line number Diff line number Diff line change
@@ -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<any, any, any> => {
return callApi(new Request(createUrl(`lease_create_charge/`), {method: 'OPTIONS'}));
};

export const fetchReceivableTypes = (): Generator<any, any, any> => {
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'}));
};

0 comments on commit a1bb88d

Please sign in to comment.