Skip to content

Commit

Permalink
refactor: manage company data in hr (#865)
Browse files Browse the repository at this point in the history
* RM#88455
  • Loading branch information
gca-axelor authored Jan 20, 2025
1 parent fd139f7 commit 5cbebad
Show file tree
Hide file tree
Showing 15 changed files with 122 additions and 49 deletions.
5 changes: 5 additions & 0 deletions changelogs/unreleased/88455.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"title": "Data fetching: add active company management",
"type": "refactor",
"packages": "hr"
}
13 changes: 11 additions & 2 deletions packages/apps/hr/src/api/expense-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,32 +82,40 @@ const createExpenseToValidateCriteria = (searchValue, user) => {
return criteria;
};

export async function searchExpenseDraft({userId}) {
export async function searchExpenseDraft({userId, companyId}) {
return createStandardSearch({
model: 'com.axelor.apps.hr.db.Expense',
criteria: createExpenseDraftCriteria(userId),
fieldKey: 'hr_expenseDraft',
numberElementsByPage: null,
page: 0,
provider: 'model',
companyId,
});
}

export async function searchMyExpense({searchValue = null, page = 0, userId}) {
export async function searchMyExpense({
searchValue = null,
page = 0,
userId,
companyId,
}) {
return createStandardSearch({
model: 'com.axelor.apps.hr.db.Expense',
criteria: createMyExpenseCriteria(searchValue, userId),
fieldKey: 'hr_expense',
sortKey: 'hr_expense',
page,
provider: 'model',
companyId,
});
}

export async function searchExpenseToValidate({
searchValue = null,
page = 0,
user,
companyId,
}) {
return createStandardSearch({
model: 'com.axelor.apps.hr.db.Expense',
Expand All @@ -116,6 +124,7 @@ export async function searchExpenseToValidate({
sortKey: 'hr_expense',
page,
provider: 'model',
companyId,
});
}

Expand Down
20 changes: 7 additions & 13 deletions packages/apps/hr/src/api/manuf-order-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,8 @@ import {
getSearchCriterias,
} from '@axelor/aos-mobile-core';

const createManufOrderCriteria = (searchValue, activeCompanyId) => {
const criteria = [getSearchCriterias('hr_manufOrder', searchValue)];

if (activeCompanyId != null) {
criteria.push({
fieldName: 'company.id',
operator: '=',
value: activeCompanyId,
});
}

return criteria;
const createManufOrderCriteria = searchValue => {
return [getSearchCriterias('hr_manufOrder', searchValue)];
};

const createOperationOrderCriteria = (searchValue, manufOrderId) => {
Expand All @@ -56,18 +46,20 @@ export async function searchManufOrder({
}) {
return createStandardSearch({
model: 'com.axelor.apps.production.db.ManufOrder',
criteria: createManufOrderCriteria(searchValue, activeCompanyId),
criteria: createManufOrderCriteria(searchValue),
fieldKey: 'hr_manufOrder',
sortKey: 'hr_manufOrder',
page,
provider: 'model',
companyId: activeCompanyId,
});
}

export async function searchOperationOrder({
searchValue,
page = 0,
manufOrderId,
companyId,
}) {
return createStandardSearch({
model: 'com.axelor.apps.production.db.OperationOrder',
Expand All @@ -76,5 +68,7 @@ export async function searchOperationOrder({
sortKey: 'hr_operationOrder',
page,
provider: 'model',
companyId,
companyFieldName: 'manufOrder.company',
});
}
14 changes: 4 additions & 10 deletions packages/apps/hr/src/api/project-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import {

const createProjectCriteria = ({
searchValue,
activeCompanyId,
isBusinessProject,
manageTimeSpent,
}) => {
Expand All @@ -38,14 +37,6 @@ const createProjectCriteria = ({
},
];

if (activeCompanyId != null) {
_businessCriteria.push({
fieldName: 'company.id',
operator: '=',
value: activeCompanyId,
});
}

criteria.push({
operator: 'and',
criteria: _businessCriteria,
Expand Down Expand Up @@ -115,9 +106,9 @@ export async function searchProject({
}) {
return createStandardSearch({
model: 'com.axelor.apps.project.db.Project',
companyId: activeCompanyId,
criteria: createProjectCriteria({
searchValue,
activeCompanyId,
isBusinessProject,
manageTimeSpent,
}),
Expand All @@ -135,9 +126,12 @@ export async function searchProjectTask({
projectId,
isAssignedToRequired,
isMemberRequired,
companyId,
}) {
return createStandardSearch({
model: 'com.axelor.apps.project.db.ProjectTask',
companyId,
companyFieldName: 'project.company',
criteria: createProjectTaskCriteria(
searchValue,
userId,
Expand Down
12 changes: 11 additions & 1 deletion packages/apps/hr/src/api/timesheet-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,21 +142,28 @@ const createDraftTimesheetCriteria = (
return criteria;
};

export async function fetchTimesheet({searchValue = null, userId, page = 0}) {
export async function fetchTimesheet({
searchValue = null,
userId,
page = 0,
companyId,
}) {
return createStandardSearch({
model: 'com.axelor.apps.hr.db.Timesheet',
criteria: createTimesheetCriteria(searchValue, userId),
fieldKey: 'hr_timesheet',
sortKey: 'hr_timesheet',
page,
provider: 'model',
companyId,
});
}

export async function fetchTimesheetToValidate({
searchValue = null,
page = 0,
user,
companyId,
}) {
return createStandardSearch({
model: 'com.axelor.apps.hr.db.Timesheet',
Expand All @@ -165,6 +172,7 @@ export async function fetchTimesheetToValidate({
sortKey: 'hr_timesheet',
page,
provider: 'model',
companyId,
});
}

Expand All @@ -182,6 +190,7 @@ export async function fetchDraftTimesheet({
fromDate,
toDate,
isOverlapAllowed,
companyId,
}) {
return createStandardSearch({
model: 'com.axelor.apps.hr.db.Timesheet',
Expand All @@ -195,6 +204,7 @@ export async function fetchDraftTimesheet({
numberElementsByPage: null,
page: 0,
provider: 'model',
companyId,
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,10 @@ const DraftExpensePickerAux = ({
const {expenseDraftList} = useSelector(state => state.expense);

useEffect(() => {
dispatch(searchExpenseDraft({userId: user?.id}));
}, [dispatch, user?.id]);
dispatch(
searchExpenseDraft({userId: user?.id, companyId: user.activeCompany?.id}),
);
}, [dispatch, user.activeCompany?.id, user?.id]);

return (
<Picker
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,13 @@ const DraftTimesheetPicker = ({
const {draftTimesheetList} = useSelector((state: any) => state.timesheet);

useEffect(() => {
dispatch((fetchDraftTimesheet as any)({userId: user?.id}));
}, [dispatch, user?.id]);
dispatch(
(fetchDraftTimesheet as any)({
userId: user.id,
companyId: user.activeCompany?.id,
}),
);
}, [dispatch, user.activeCompany?.id, user.id]);

const displayValue = item => {
return `${formatDate(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,14 @@ const ExpenseWaitingValidationSearchBar = ({

const fetchExpenseToValidateAPI = useCallback(
({page = 0, searchValue}) => {
dispatch(searchExpenseToValidate({page: page, user: user, searchValue}));
dispatch(
searchExpenseToValidate({
page: page,
user: user,
searchValue,
companyId: user.activeCompany?.id,
}),
);
},
[dispatch, user],
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ const OperationOrderSearchBarAux = ({
moreLoadingOperationOrder,
isListEndOperationOrder,
} = useSelector((state: any) => state.hr_manufOrder);
const {user} = useSelector((state: any) => state.user);

const searchOperationOrderAPI = useCallback(
({page = 0, searchValue}) => {
Expand All @@ -61,10 +62,11 @@ const OperationOrderSearchBarAux = ({
page,
searchValue,
manufOrderId: manufOrder?.id,
companyId: user.activeCompany?.id,
}),
);
},
[dispatch, manufOrder?.id],
[dispatch, manufOrder?.id, user.activeCompany?.id],
);

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,15 @@ const ProjectTaskSearchBarAux = ({
(searchProjectTask as any)({
page,
searchValue,
userId: user?.id,
userId: user.id,
projectId: project?.id,
isAssignedToRequired,
isMemberRequired,
companyId: user.activeCompany?.id,
}),
);
},
[dispatch, isAssignedToRequired, isMemberRequired, project?.id, user?.id],
[dispatch, isAssignedToRequired, isMemberRequired, project?.id, user],
);

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ const TimerListAlert = ({
moreLoadingTimerDateInterval,
isListEndTimerDateInterval,
} = useSelector((state: any) => state.hr_timer);
const {userId} = useSelector((state: any) => state.auth);
const {user} = useSelector(state => state.user);

const [timesheet, setTimesheet] = useState(null);
const [fromDate, setFromDate] = useState(null);
Expand All @@ -84,14 +84,14 @@ const TimerListAlert = ({
(page = 0) => {
dispatch(
(fetchTimerDateInterval as any)({
userId: userId,
userId: user.id,
fromDate: fromDate,
toDate: toDate,
page: page,
}),
);
},
[dispatch, fromDate, toDate, userId],
[dispatch, fromDate, toDate, user.id],
);

useEffect(() => {
Expand All @@ -104,10 +104,11 @@ const TimerListAlert = ({
if (timesheet == null && fromDate && toDate) {
if (getStartOfDay(fromDate) <= getEndOfDay(toDate)) {
fetchDraftTimesheet({
userId: userId,
userId: user.id,
fromDate: fromDate,
toDate: toDate,
isOverlapAllowed: false,
companyId: user.activeCompany?.id,
}).then(res => {
setErrorKey(null);
res.data?.data?.length > 0 &&
Expand All @@ -119,7 +120,7 @@ const TimerListAlert = ({
} else {
setErrorKey(null);
}
}, [fromDate, timesheet, toDate, userId]);
}, [fromDate, timesheet, toDate, user]);

const renderChexboxItem = ({item}) => {
return (
Expand Down Expand Up @@ -153,7 +154,7 @@ const TimerListAlert = ({
timesheetId: timesheet?.id,
version: timesheet?.version,
timerIdList,
userId,
userId: user.id,
}),
);
} else {
Expand All @@ -162,7 +163,7 @@ const TimerListAlert = ({
fromDate,
toDate,
timerIdList,
userId,
userId: user.id,
}),
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,13 @@ const TimesheetFilters = ({
]);

useEffect(() => {
dispatch(fetchTimesheetToValidate({page: 0, user: user}));
dispatch(
fetchTimesheetToValidate({
page: 0,
user: user,
companyId: user.activeCompany?.id,
}),
);
}, [dispatch, user]);

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,14 @@ const TimesheetWaitingValidationSearchBar = ({

const fetchTimesheetToValidateAPI = useCallback(
({page = 0, searchValue}) => {
dispatch(fetchTimesheetToValidate({page: page, user: user, searchValue}));
dispatch(
fetchTimesheetToValidate({
page: page,
user: user,
searchValue,
companyId: user.activeCompany?.id,
}),
);
},
[dispatch, user],
);
Expand Down
Loading

0 comments on commit 5cbebad

Please sign in to comment.