feat: rename item sku to code.

feat: fix sidebar current tab issue.
This commit is contained in:
Ahmed Bouhuolia
2020-11-24 11:30:27 +02:00
parent a7e5401b7d
commit 0321f29442
20 changed files with 75 additions and 50 deletions

View File

@@ -9,6 +9,9 @@ export default function EditableItemsEntriesTable({
defaultEntry,
minLinesNumber = 2,
linesNumber = 5,
filterSellableItems = false,
filterPurchasableItems = false,
}) {
const { setFieldValue, values } = useFormikContext();
const [clearLinesAlert, setClearLinesAlert] = useState(false);
@@ -58,6 +61,8 @@ export default function EditableItemsEntriesTable({
}}
entries={value}
errors={error}
filterPurchasableItems={filterPurchasableItems}
filterSellableItems={filterSellableItems}
onClickAddNewRow={handleClickAddNewRow}
onClickClearAllLines={handleClearAllLines}
onClickRemoveRow={handleClickRemoveLine}

View File

@@ -91,6 +91,8 @@ function ItemsEntriesTable({
onClickRemoveRow,
onClickAddNewRow,
onClickClearAllLines,
filterPurchasableItems = false,
filterSellableItems = false,
}) {
const [rows, setRows] = useState([]);
const { formatMessage } = useIntl();
@@ -117,6 +119,8 @@ function ItemsEntriesTable({
Cell: ItemsListCell,
disableSortBy: true,
width: 180,
filterPurchasable: filterPurchasableItems,
filterSellable: filterSellableItems,
},
{
Header: formatMessage({ id: 'description' }),

View File

@@ -33,7 +33,7 @@ const defaultInitialValues = {
active: true,
name: '',
type: 'service',
sku: '',
code: '',
cost_price: '',
sell_price: '',
cost_account_id: '',

View File

@@ -1,4 +1,5 @@
import * as Yup from 'yup';
import { defaultTo } from 'lodash';
import { formatMessage } from 'services/intl';
import { DATATYPES_LENGTH } from 'common/dataTypes';
@@ -15,7 +16,7 @@ const Schema = Yup.object().shape({
.min(0)
.max(DATATYPES_LENGTH.STRING)
.label(formatMessage({ id: 'item_type_' })),
sku: Yup.string().trim().min(0).max(DATATYPES_LENGTH.STRING),
code: Yup.string().trim().min(0).max(DATATYPES_LENGTH.STRING),
cost_price: Yup.number().when(['purchasable'], {
is: true,
then: Yup.number()
@@ -61,8 +62,8 @@ const Schema = Yup.object().shape({
export const transformItemFormData = (item, defaultValue) => {
return {
...item,
sellable: item?.sellable ? Boolean(item.sellable) : defaultValue.sellable,
purchasable: item?.purchasable ? Boolean(item.purchasable) : defaultValue.purchasable,
sellable: !!defaultTo(item?.sellable, defaultValue.sellable),
purchasable: !!defaultTo(item?.purchasable, defaultValue.purchasable),
};
}

View File

@@ -27,7 +27,7 @@ function ItemFormBody({ accountsList, baseCurrency }) {
<Col xs={6}>
{/*------------- Purchasable checbox ------------- */}
<FastField name={'sellable'} type="checkbox">
{({ field }) => (
{({ form, field }) => (
<FormGroup inline={true} className={'form-group--sellable'}>
<Checkbox
inline={true}
@@ -44,7 +44,7 @@ function ItemFormBody({ accountsList, baseCurrency }) {
</FastField>
{/*------------- Selling price ------------- */}
<Field name={'sell_price'}>
<FastField name={'sell_price'}>
{({ form, field: { value }, meta: { error, touched } }) => (
<FormGroup
label={<T id={'selling_price'} />}
@@ -67,7 +67,7 @@ function ItemFormBody({ accountsList, baseCurrency }) {
</ControlGroup>
</FormGroup>
)}
</Field>
</FastField>
{/*------------- Selling account ------------- */}
<FastField name={'sell_account_id'}>
@@ -93,6 +93,7 @@ function ItemFormBody({ accountsList, baseCurrency }) {
selectedAccountId={value}
disabled={!form.values.sellable}
filterByTypes={['income']}
popoverFill={true}
/>
</FormGroup>
)}
@@ -118,7 +119,7 @@ function ItemFormBody({ accountsList, baseCurrency }) {
</FastField>
{/*------------- Cost price ------------- */}
<Field name={'cost_price'}>
<FastField name={'cost_price'}>
{({ field, form, field: { value }, meta: { error, touched } }) => (
<FormGroup
label={<T id={'cost_price'} />}
@@ -141,7 +142,7 @@ function ItemFormBody({ accountsList, baseCurrency }) {
</ControlGroup>
</FormGroup>
)}
</Field>
</FastField>
{/*------------- Cost account ------------- */}
<FastField name={'cost_account_id'}>
@@ -167,6 +168,7 @@ function ItemFormBody({ accountsList, baseCurrency }) {
selectedAccountId={value}
disabled={!form.values.purchasable}
filterByTypes={['cost_of_goods_sold']}
popoverFill={true}
/>
</FormGroup>
)}

View File

@@ -135,7 +135,7 @@ function ItemFormPrimarySection({
</FastField>
{/*----------- Item category ----------*/}
<FastField name={'type'}>
<FastField name={'category_id'}>
{({ form, field: { value }, meta: { error, touched } }) => (
<FormGroup
label={<T id={'category'} />}
@@ -143,7 +143,6 @@ function ItemFormPrimarySection({
intent={inputIntent({ error, touched })}
helperText={<ErrorMessage name="category_id" />}
className={classNames(
'form-group--select-list',
'form-group--category',
Classes.FILL,
)}
@@ -154,7 +153,6 @@ function ItemFormPrimarySection({
onCategorySelected={(category) => {
form.setFieldValue('category_id', category.id);
}}
popoverProps={{ minimal: true }}
/>
</FormGroup>
)}

View File

@@ -111,8 +111,8 @@ function ItemsDataTable({
},
{
Header: formatMessage({ id: 'item_code' }),
accessor: 'sku',
className: 'sku',
accessor: 'code',
className: 'code',
width: 120,
},
{

View File

@@ -22,7 +22,7 @@ import withBillDetail from './withBillDetail';
import { AppToaster } from 'components';
import { ERROR } from 'common/errors';
import { compose, repeatValue, orderingLinesIndexes } from 'utils';
import { compose, repeatValue, defaultToTransform, orderingLinesIndexes } from 'utils';
const MIN_LINES_NUMBER = 5;
@@ -207,7 +207,10 @@ function BillForm({
{({ isSubmitting, values }) => (
<Form>
<BillFormHeader onBillNumberChanged={handleBillNumberChanged} />
<EditableItemsEntriesTable defaultEntry={defaultBill} />
<EditableItemsEntriesTable
defaultEntry={defaultBill}
filterPurchasableItems={true}
/>
<BillFormFooter
oninitialFiles={[]}
// onDropFiles={handleDeleteFile}

View File

@@ -54,6 +54,7 @@ function BillFormHeader({
onContactSelected={(contact) => {
form.setFieldValue('vendor_id', contact.id);
}}
popoverFill={true}
/>
</FormGroup>
)}