From 1aca1c8c6c72fe4b49e99ab7bd668d9297b82c51 Mon Sep 17 00:00:00 2001 From: Gregory <117281520+gca-axelor@users.noreply.github.com> Date: Fri, 6 Dec 2024 10:09:51 +0100 Subject: [PATCH] feat: add RequestCreationScreen --- packages/apps/purchase/src/api/index.ts | 2 + packages/apps/purchase/src/api/product-api.js | 55 +++++ packages/apps/purchase/src/api/unit-api.js | 32 +++ .../HorizontalRuleText/HorizontalRuleText.tsx | 69 ++++++ .../purchase/src/components/atoms/index.ts | 1 + .../templates/CompanyPicker/CompanyPicker.tsx | 60 ++++++ .../ProductSearchBar/ProductSearchBar.tsx | 91 ++++++++ .../RequestCreationButton.tsx | 126 +++++++++++ .../RequestCreationQuantityCard.tsx | 69 ++++++ .../templates/UnitSearchBar/UnitSearchBar.tsx | 92 ++++++++ .../src/components/templates/index.ts | 5 + .../src/features/asyncFunctions-index.ts | 2 + packages/apps/purchase/src/features/index.js | 2 + .../purchase/src/features/productSlice.js | 59 +++++ .../apps/purchase/src/features/unitSlice.js | 59 +++++ packages/apps/purchase/src/i18n/en.json | 8 +- packages/apps/purchase/src/i18n/fr.json | 8 +- packages/apps/purchase/src/index.ts | 5 + .../apps/purchase/src/models/objectFields.ts | 9 + .../src/screens/RequestCreationScreen.tsx | 204 ++++++++++++++++++ packages/apps/purchase/src/screens/index.ts | 10 + packages/apps/purchase/src/types/index.ts | 19 ++ .../purchase/src/types/request-creation.ts | 27 +++ .../ViewAllEditList/ViewAllEditList.tsx | 2 + 24 files changed, 1014 insertions(+), 2 deletions(-) create mode 100644 packages/apps/purchase/src/api/product-api.js create mode 100644 packages/apps/purchase/src/api/unit-api.js create mode 100644 packages/apps/purchase/src/components/atoms/HorizontalRuleText/HorizontalRuleText.tsx create mode 100644 packages/apps/purchase/src/components/templates/CompanyPicker/CompanyPicker.tsx create mode 100644 packages/apps/purchase/src/components/templates/ProductSearchBar/ProductSearchBar.tsx create mode 100644 packages/apps/purchase/src/components/templates/RequestCreationButton/RequestCreationButton.tsx create mode 100644 packages/apps/purchase/src/components/templates/RequestCreationQuantityCard/RequestCreationQuantityCard.tsx create mode 100644 packages/apps/purchase/src/components/templates/UnitSearchBar/UnitSearchBar.tsx create mode 100644 packages/apps/purchase/src/features/productSlice.js create mode 100644 packages/apps/purchase/src/features/unitSlice.js create mode 100644 packages/apps/purchase/src/screens/RequestCreationScreen.tsx create mode 100644 packages/apps/purchase/src/types/index.ts create mode 100644 packages/apps/purchase/src/types/request-creation.ts diff --git a/packages/apps/purchase/src/api/index.ts b/packages/apps/purchase/src/api/index.ts index e7d0362176..f72b6c213d 100644 --- a/packages/apps/purchase/src/api/index.ts +++ b/packages/apps/purchase/src/api/index.ts @@ -17,4 +17,6 @@ */ export {searchPurchaseRequest as searchPurchaseRequestApi} from './purchase-request-api'; +export {searchProduct as searchProductApi} from './product-api'; export {searchSupplier as searchSupplierApi} from './supplier-api'; +export {searchUnit as searchUnitApi} from './unit-api'; diff --git a/packages/apps/purchase/src/api/product-api.js b/packages/apps/purchase/src/api/product-api.js new file mode 100644 index 0000000000..2560c36938 --- /dev/null +++ b/packages/apps/purchase/src/api/product-api.js @@ -0,0 +1,55 @@ +/* + * Axelor Business Solutions + * + * Copyright (C) 2024 Axelor (). + * + * 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 . + */ + +import { + createStandardSearch, + getSearchCriterias, +} from '@axelor/aos-mobile-core'; + +const createProductCriteria = ({searchValue}) => { + const criterias = [ + getSearchCriterias('purchase_product', searchValue), + { + fieldName: 'isModel', + operator: '=', + value: false, + }, + { + fieldName: 'purchasable', + operator: '=', + value: true, + }, + { + fieldName: 'dtype', + operator: '=', + value: 'Product', + }, + ]; + + return criterias; +}; + +export async function searchProduct({page = 0, searchValue}) { + return createStandardSearch({ + model: 'com.axelor.apps.base.db.Product', + criteria: createProductCriteria(searchValue), + fieldKey: 'purchase_product', + sortKey: 'purchase_product', + page, + }); +} diff --git a/packages/apps/purchase/src/api/unit-api.js b/packages/apps/purchase/src/api/unit-api.js new file mode 100644 index 0000000000..4e71cb42b6 --- /dev/null +++ b/packages/apps/purchase/src/api/unit-api.js @@ -0,0 +1,32 @@ +/* + * Axelor Business Solutions + * + * Copyright (C) 2024 Axelor (). + * + * 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 . + */ + +import { + createStandardSearch, + getSearchCriterias, +} from '@axelor/aos-mobile-core'; + +export async function searchUnit({page = 0, searchValue}) { + return createStandardSearch({ + model: 'com.axelor.apps.base.db.Unit', + criteria: [getSearchCriterias('purchase_unit', searchValue)], + fieldKey: 'purchase_unit', + sortKey: 'purchase_unit', + page, + }); +} diff --git a/packages/apps/purchase/src/components/atoms/HorizontalRuleText/HorizontalRuleText.tsx b/packages/apps/purchase/src/components/atoms/HorizontalRuleText/HorizontalRuleText.tsx new file mode 100644 index 0000000000..539dbb2179 --- /dev/null +++ b/packages/apps/purchase/src/components/atoms/HorizontalRuleText/HorizontalRuleText.tsx @@ -0,0 +1,69 @@ +/* + * Axelor Business Solutions + * + * Copyright (C) 2024 Axelor (). + * + * 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 . + */ + +import React from 'react'; +import {View, StyleSheet, Text} from 'react-native'; +import {HorizontalRule, useThemeColor} from '@axelor/aos-mobile-ui'; + +interface HorizontalRuleTextProps { + text?: string; + style?: any; + textStyle?: any; +} + +const HorizontalRuleText = ({ + text = '', + style, + textStyle, +}: HorizontalRuleTextProps) => { + const Colors = useThemeColor(); + + return ( + + + + {text} + + + + ); +}; + +const styles = StyleSheet.create({ + container: { + flexDirection: 'row', + alignItems: 'center', + justifyContent: 'center', + width: '100%', + }, + line: { + flex: 1, + marginHorizontal: 10, + }, + text: { + fontSize: 14, + textAlign: 'center', + }, +}); + +export default HorizontalRuleText; diff --git a/packages/apps/purchase/src/components/atoms/index.ts b/packages/apps/purchase/src/components/atoms/index.ts index 33fdb3deba..92e2897bd1 100644 --- a/packages/apps/purchase/src/components/atoms/index.ts +++ b/packages/apps/purchase/src/components/atoms/index.ts @@ -16,4 +16,5 @@ * along with this program. If not, see . */ +export {default as HorizontalRuleText} from './HorizontalRuleText/HorizontalRuleText'; export {default as RequestCard} from './RequestCard/RequestCard'; diff --git a/packages/apps/purchase/src/components/templates/CompanyPicker/CompanyPicker.tsx b/packages/apps/purchase/src/components/templates/CompanyPicker/CompanyPicker.tsx new file mode 100644 index 0000000000..135cf4dfcd --- /dev/null +++ b/packages/apps/purchase/src/components/templates/CompanyPicker/CompanyPicker.tsx @@ -0,0 +1,60 @@ +/* + * Axelor Business Solutions + * + * Copyright (C) 2024 Axelor (). + * + * 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 . + */ + +import React from 'react'; +import {useSelector, useTranslator} from '@axelor/aos-mobile-core'; +import {Picker} from '@axelor/aos-mobile-ui'; + +interface CompanyPickerProps { + style?: any; + company?: any; + emptyValue?: boolean; + onChange: (state: any) => void; +} + +const CompanyPicker = ({ + style, + company, + onChange = () => {}, + emptyValue = true, +}: CompanyPickerProps) => { + const I18n = useTranslator(); + + const {user} = useSelector((state: any) => state.user); + + if (!Array.isArray(user?.companySet) || user.companySet.length === 0) { + return null; + } + + return ( + + ); +}; + +export default CompanyPicker; diff --git a/packages/apps/purchase/src/components/templates/ProductSearchBar/ProductSearchBar.tsx b/packages/apps/purchase/src/components/templates/ProductSearchBar/ProductSearchBar.tsx new file mode 100644 index 0000000000..f3b5f2f065 --- /dev/null +++ b/packages/apps/purchase/src/components/templates/ProductSearchBar/ProductSearchBar.tsx @@ -0,0 +1,91 @@ +/* + * Axelor Business Solutions + * + * Copyright (C) 2024 Axelor (). + * + * 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 . + */ + +import React, {useCallback} from 'react'; +import { + displayItemName, + useDispatch, + useSelector, + useTranslator, +} from '@axelor/aos-mobile-core'; +import {AutoCompleteSearch} from '@axelor/aos-mobile-ui'; +import {searchProduct} from '../../../features/productSlice'; + +interface ProductSearchBarProps { + style?: any; + title?: string; + showTitle?: boolean; + defaultValue?: string; + onChange?: (any: any) => void; + readonly?: boolean; + required?: boolean; + isScrollViewContainer?: boolean; +} + +const ProductSearchBar = ({ + style = null, + title = 'Sale_Product', + showTitle = false, + defaultValue = null, + onChange = () => {}, + readonly = false, + required = false, + isScrollViewContainer = false, +}: ProductSearchBarProps) => { + const I18n = useTranslator(); + const dispatch = useDispatch(); + + const {loadingProducts, moreLoadingProduct, isListEndProduct, productList} = + useSelector((state: any) => state.purchase_product); + + const searchProductAPI = useCallback( + ({page = 0, searchValue}) => { + dispatch( + (searchProduct as any)({ + page, + searchValue, + }), + ); + }, + [dispatch], + ); + + return ( + + ); +}; + +export default ProductSearchBar; diff --git a/packages/apps/purchase/src/components/templates/RequestCreationButton/RequestCreationButton.tsx b/packages/apps/purchase/src/components/templates/RequestCreationButton/RequestCreationButton.tsx new file mode 100644 index 0000000000..9c843054d4 --- /dev/null +++ b/packages/apps/purchase/src/components/templates/RequestCreationButton/RequestCreationButton.tsx @@ -0,0 +1,126 @@ +/* + * Axelor Business Solutions + * + * Copyright (C) 2024 Axelor (). + * + * 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 . + */ + +import React from 'react'; +import {StyleSheet, View} from 'react-native'; +import { + useDispatch, + useNavigation, + useSelector, + useTranslator, +} from '@axelor/aos-mobile-core'; +import {Button, useThemeColor} from '@axelor/aos-mobile-ui'; +//import {createInternalMove} from '../../../../features/internalMoveSlice'; +import {RequestCreation} from '../../../types'; + +interface RequestCreationButtonProps { + step: number; + setStep: (step: number) => void; + lines: any[]; + movedQty: number; + isEditionMode: boolean; + addLine: () => void; +} + +const RequestCreationButton = ({ + step, + setStep, + lines, + movedQty, + isEditionMode, + addLine, +}: RequestCreationButtonProps) => { + const Colors = useThemeColor(); + const I18n = useTranslator(); + const navigation = useNavigation(); + const dispatch = useDispatch(); + + const {user} = useSelector((state: any) => state.user); + + const handleFinishPress = () => { + if (step === RequestCreation.step.validateLine) { + addLine(); + } + setStep(RequestCreation.step.finish); + }; + + const handleRealizePress = () => { + navigation.popToTop(); + }; + + if ( + (step === RequestCreation.step.addLine && lines.length >= 1) || + step === RequestCreation.step.validateLine + ) { + return ( + + {step === RequestCreation.step.validateLine && ( +