Skip to content

Commit

Permalink
feat: add RequestListView (#819)
Browse files Browse the repository at this point in the history
* RM#86192
  • Loading branch information
gca-axelor authored Dec 11, 2024
1 parent 6dac2fb commit 0383600
Show file tree
Hide file tree
Showing 22 changed files with 862 additions and 2 deletions.
20 changes: 20 additions & 0 deletions packages/apps/purchase/src/api/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
* Axelor Business Solutions
*
* Copyright (C) 2024 Axelor (<http://axelor.com>).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License, version 3,
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

export {searchPurchaseRequest as searchPurchaseRequestApi} from './purchase-request-api';
export {searchSupplier as searchSupplierApi} from './supplier-api';
68 changes: 68 additions & 0 deletions packages/apps/purchase/src/api/purchase-request-api.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/*
* Axelor Business Solutions
*
* Copyright (C) 2024 Axelor (<http://axelor.com>).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License, version 3,
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

import {
createStandardSearch,
getSearchCriterias,
} from '@axelor/aos-mobile-core';

const createPurchaseRequestCriteria = ({searchValue, statusList, supplier}) => {
const criterias = [
getSearchCriterias('purchase_purchaseRequest', searchValue),
];

if (supplier) {
criterias.push({
fieldName: 'supplierPartner.id',
operator: '=',
value: supplier.id,
});
}

if (Array.isArray(statusList) && statusList.length > 0) {
criterias.push({
operator: 'or',
criteria: statusList.map(status => ({
fieldName: 'statusSelect',
operator: '=',
value: status.key,
})),
});
}

return criterias;
};

export async function searchPurchaseRequest({
page = 0,
searchValue,
statusList,
supplier,
}) {
return createStandardSearch({
model: 'com.axelor.apps.purchase.db.PurchaseRequest',
criteria: createPurchaseRequestCriteria({
searchValue,
statusList,
supplier,
}),
fieldKey: 'purchase_purchaseRequest',
sortKey: 'purchase_purchaseRequest',
page,
});
}
50 changes: 50 additions & 0 deletions packages/apps/purchase/src/api/supplier-api.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
* Axelor Business Solutions
*
* Copyright (C) 2024 Axelor (<http://axelor.com>).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License, version 3,
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

import {
createStandardSearch,
getSearchCriterias,
} from '@axelor/aos-mobile-core';

const createSupplierCriteria = searchValue => {
const criterias = [
getSearchCriterias('purchase_supplier', searchValue),
{
fieldName: 'isContact',
operator: '=',
value: false,
},
{
fieldName: 'isSupplier',
operator: '=',
value: true,
},
];

return criterias;
};

export async function searchSupplier({page = 0, searchValue}) {
return createStandardSearch({
model: 'com.axelor.apps.base.db.Partner',
criteria: createSupplierCriteria(searchValue),
fieldKey: 'purchase_supplier',
sortKey: 'purchase_supplier',
page,
});
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
/*
* Axelor Business Solutions
*
* Copyright (C) 2024 Axelor (<http://axelor.com>).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License, version 3,
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

import React, {useMemo} from 'react';
import {StyleSheet} from 'react-native';
import {ObjectCard} from '@axelor/aos-mobile-ui';
import {useTypeHelpers, useTypes} from '@axelor/aos-mobile-core';

interface RequestCardProps {
style?: any;
companyName: string;
supplierPartnerName: string;
reference: string;
statusSelect: number;
onPress: () => void;
}

const RequestCard = ({
style,
companyName,
supplierPartnerName,
reference,
statusSelect,
onPress,
}: RequestCardProps) => {
const {PurchaseRequest} = useTypes();
const {getItemColor} = useTypeHelpers();

const borderStyle = useMemo(() => {
return getStyles(
getItemColor(PurchaseRequest?.statusSelect, statusSelect)?.background,
)?.border;
}, [PurchaseRequest?.statusSelect, getItemColor, statusSelect]);

return (
<ObjectCard
onPress={onPress}
style={[borderStyle, style]}
upperTexts={{
items: [
{
isTitle: true,
displayText: reference,
},
{
iconName: 'person-fill',
indicatorText: supplierPartnerName,
hideIfNull: true,
},
{
iconName: 'building',
indicatorText: companyName,
hideIfNull: true,
},
],
}}
/>
);
};

const getStyles = (color: string) =>
StyleSheet.create({
border: {borderLeftWidth: 7, borderLeftColor: color},
});

export default RequestCard;
19 changes: 19 additions & 0 deletions packages/apps/purchase/src/components/atoms/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*
* Axelor Business Solutions
*
* Copyright (C) 2024 Axelor (<http://axelor.com>).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License, version 3,
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

export {default as RequestCard} from './RequestCard/RequestCard';
20 changes: 20 additions & 0 deletions packages/apps/purchase/src/components/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
* Axelor Business Solutions
*
* Copyright (C) 2024 Axelor (<http://axelor.com>).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License, version 3,
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

export * from './atoms';
export * from './templates';
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
/*
* Axelor Business Solutions
*
* Copyright (C) 2024 Axelor (<http://axelor.com>).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License, version 3,
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

import React, {useCallback} from 'react';
import {useDispatch, useSelector, useTranslator} from '@axelor/aos-mobile-core';
import {AutoCompleteSearch} from '@axelor/aos-mobile-ui';
import {searchSupplier} from '../../../features/supplierSlice';

const displaySimpleFullName = item => item.simpleFullName;

interface SupplierSearchBarProps {
placeholderKey?: string;
defaultValue: any;
showDetailsPopup?: boolean;
navigate?: boolean;
oneFilter?: boolean;
onChange: (value: any) => void;
}

const SupplierSearchBar = ({
placeholderKey = 'Purchase_Supplier',
defaultValue = '',
onChange = () => {},
showDetailsPopup = true,
navigate = false,
oneFilter = false,
}: SupplierSearchBarProps) => {
const I18n = useTranslator();
const dispatch = useDispatch();

const {
supplierList,
loadingSuppliers,
moreLoadingSupplier,
isListEndSupplier,
} = useSelector(state => state.purchase_supplier);

const fetchSupplierAPI = useCallback(
({page = 0, searchValue}) => {
dispatch((searchSupplier as any)({page, searchValue}));
},
[dispatch],
);

return (
<AutoCompleteSearch
objectList={supplierList}
value={defaultValue}
onChangeValue={onChange}
fetchData={fetchSupplierAPI}
displayValue={displaySimpleFullName}
placeholder={I18n.t(placeholderKey)}
showDetailsPopup={showDetailsPopup}
loadingList={loadingSuppliers}
moreLoading={moreLoadingSupplier}
isListEnd={isListEndSupplier}
navigate={navigate}
oneFilter={oneFilter}
/>
);
};

export default SupplierSearchBar;
19 changes: 19 additions & 0 deletions packages/apps/purchase/src/components/templates/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*
* Axelor Business Solutions
*
* Copyright (C) 2024 Axelor (<http://axelor.com>).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License, version 3,
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

export {default as SupplierSearchBar} from './SupplierSearchBar/SupplierSearchBar';
20 changes: 20 additions & 0 deletions packages/apps/purchase/src/features/asyncFunctions-index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
* Axelor Business Solutions
*
* Copyright (C) 2024 Axelor (<http://axelor.com>).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License, version 3,
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

export {searchPurchaseRequest} from './purchaseRequestSlice';
export {searchSupplier} from './supplierSlice';
Loading

0 comments on commit 0383600

Please sign in to comment.