Skip to content

Commit

Permalink
feat: add RequestCreationScreen
Browse files Browse the repository at this point in the history
  • Loading branch information
gca-axelor committed Dec 17, 2024
1 parent 5ad415c commit 1aca1c8
Show file tree
Hide file tree
Showing 24 changed files with 1,014 additions and 2 deletions.
2 changes: 2 additions & 0 deletions packages/apps/purchase/src/api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
55 changes: 55 additions & 0 deletions packages/apps/purchase/src/api/product-api.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
* 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 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,
});
}
32 changes: 32 additions & 0 deletions packages/apps/purchase/src/api/unit-api.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* 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';

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,
});
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/*
* 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 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 (
<View style={[styles.container, style]}>
<HorizontalRule style={styles.line} />
<Text
style={[
styles.text,
{color: Colors.secondaryColor.foreground},
textStyle,
]}>
{text}
</Text>
<HorizontalRule style={styles.line} />
</View>
);
};

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;
1 change: 1 addition & 0 deletions packages/apps/purchase/src/components/atoms/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,5 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

export {default as HorizontalRuleText} from './HorizontalRuleText/HorizontalRuleText';
export {default as RequestCard} from './RequestCard/RequestCard';
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/*
* 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 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 (
<Picker
placeholder={I18n.t('Purchase_Company')}
style={style}
defaultValue={company}
listItems={user?.companySet}
valueField="id"
labelField="name"
onValueChange={onChange}
isValueItem
emptyValue={emptyValue}
translator={I18n.t}
/>
);
};

export default CompanyPicker;
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
/*
* 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 {
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 (
<AutoCompleteSearch
style={style}
title={showTitle && I18n.t(title)}
objectList={productList}
value={defaultValue}
required={required}
readonly={readonly}
onChangeValue={onChange}
fetchData={searchProductAPI}
displayValue={displayItemName}
placeholder={I18n.t(title)}
showDetailsPopup={true}
loadingList={loadingProducts}
moreLoading={moreLoadingProduct}
isListEnd={isListEndProduct}
navigate={false}
oneFilter={false}
isScrollViewContainer={isScrollViewContainer}
/>
);
};

export default ProductSearchBar;
Loading

0 comments on commit 1aca1c8

Please sign in to comment.