diff --git a/client/src/containers/Items/ItemForm.js b/client/src/containers/Items/ItemForm.js index 97fd4a492..d9ab4f86a 100644 --- a/client/src/containers/Items/ItemForm.js +++ b/client/src/containers/Items/ItemForm.js @@ -19,6 +19,7 @@ import withMediaActions from 'containers/Media/withMediaActions'; import useMedia from 'hooks/useMedia'; import withItemDetail from 'containers/Items/withItemDetail'; import withDashboardActions from 'containers/Dashboard/withDashboardActions'; +import withSettings from 'containers/Settings/withSettings'; import { compose, transformToForm } from 'utils'; @@ -54,6 +55,11 @@ function ItemForm({ changePageTitle, changePageSubtitle, + // #withSettings + preferredCostAccount, + preferredSellAccount, + preferredInventoryAccount, + // #withMediaActions requestSubmitMedia, requestDeleteMedia, @@ -89,14 +95,16 @@ function ItemForm({ sku: Yup.string().trim(), cost_price: Yup.number().when(['purchasable'], { is: true, - then: Yup.number().required() - .label(formatMessage({ id: 'cost_price_' })), + then: Yup.number() + .required() + .label(formatMessage({ id: 'cost_price_' })), otherwise: Yup.number().nullable(true), }), sell_price: Yup.number().when(['sellable'], { is: true, - then: Yup.number().required() - .label(formatMessage({ id: 'sell_price_' })), + then: Yup.number() + .required() + .label(formatMessage({ id: 'sell_price_' })), otherwise: Yup.number().nullable(true), }), cost_account_id: Yup.number() @@ -132,7 +140,9 @@ function ItemForm({ const initialValues = useMemo( () => ({ ...defaultInitialValues, - + cost_account_id: parseInt(preferredCostAccount), + sell_account_id: parseInt(preferredSellAccount), + inventory_account_id: parseInt(preferredInventoryAccount), /** * We only care about the fields in the form. Previously unfilled optional * values such as `notes` come back from the API as null, so remove those @@ -283,4 +293,9 @@ export default compose( withItemDetail, withDashboardActions, withMediaActions, + withSettings(({ itemsSettings }) => ({ + preferredCostAccount: itemsSettings.preferredCostAccount, + preferredSellAccount: itemsSettings.preferredSellAccount, + preferredInventoryAccount: itemsSettings.preferredInventoryAccount, + })), )(ItemForm); diff --git a/client/src/containers/Settings/withSettings.js b/client/src/containers/Settings/withSettings.js index 1713f375d..68588c579 100644 --- a/client/src/containers/Settings/withSettings.js +++ b/client/src/containers/Settings/withSettings.js @@ -10,6 +10,7 @@ export default (mapState) => { estimatesSettings: state.settings.data.salesEstimates, receiptSettings: state.settings.data.salesReceipts, invoiceSettings: state.settings.data.salesInvoices, + itemsSettings: state.settings.data.items, }; return mapState ? mapState(mapped, state, props) : mapped; }; diff --git a/server/src/data/options.js b/server/src/data/options.js index 38d52c7d2..1f369748d 100644 --- a/server/src/data/options.js +++ b/server/src/data/options.js @@ -105,12 +105,26 @@ export default { ], payment_receives: [ { - key: 'next_number', - type: 'number', + key: "next_number", + type: "number", }, { - key: 'number_prefix', - type: 'string', + key: "number_prefix", + type: "string", }, - ] + ], + items: [ + { + key: "preferred_sell_account", + type: "number", + }, + { + key: "preferred_cost_account", + type: "number", + }, + { + key: "preferred_inventory_account", + type: "number", + }, + ], };