mirror of
https://gitlab.com/mbugroup/lti-web-client.git
synced 2026-05-23 23:05:46 +00:00
refactor(FE-208,212): enhance PurchaseRequestForm with product and product warehouse fields
This commit is contained in:
@@ -97,21 +97,18 @@ const PurchaseRequestForm = ({
|
||||
validateOnBlur: true,
|
||||
onSubmit: async (values) => {
|
||||
const payload: CreatePurchaseRequestPayload = {
|
||||
supplier_id: values.supplier_id,
|
||||
supplier_id: values.supplier_id || 0,
|
||||
credit_term: values.credit_term || 0,
|
||||
notes: values.notes || '',
|
||||
purchase_items: (values.purchase_items || []).map((item) => ({
|
||||
warehouse_ids: item.warehouse_ids,
|
||||
product_id: item.product_id,
|
||||
product_warehouse_id: item.product_warehouse_id,
|
||||
total_qty:
|
||||
typeof item.total_qty === 'number'
|
||||
? item.total_qty
|
||||
: parseFloat(String(item.total_qty)) || 0,
|
||||
warehouse_ids: item.warehouse_ids || 0,
|
||||
product_id: item.product_id || 0,
|
||||
product_warehouse_id: item.product_warehouse_id || 0,
|
||||
total_qty: item.total_qty || 0,
|
||||
price:
|
||||
typeof item.price === 'number'
|
||||
? item.price
|
||||
: parseFloat(String(item.price)) || 0,
|
||||
: parseFloat(item.price) || 0,
|
||||
})),
|
||||
};
|
||||
|
||||
@@ -149,8 +146,11 @@ const PurchaseRequestForm = ({
|
||||
const newPurchaseItems = [
|
||||
...(formik.values.purchase_items || []),
|
||||
{
|
||||
warehouse: null,
|
||||
warehouse_ids: 0,
|
||||
product: null,
|
||||
product_id: 0,
|
||||
product_warehouse: null,
|
||||
product_warehouse_id: 0,
|
||||
total_qty: 0,
|
||||
price: 0,
|
||||
@@ -179,12 +179,23 @@ const PurchaseRequestForm = ({
|
||||
field: string,
|
||||
value: string | number
|
||||
) => {
|
||||
if (field === 'warehouse_ids') {
|
||||
formik.setFieldValue(`purchase_items.${idx}.${field}`, value);
|
||||
} else {
|
||||
const integerFields = [
|
||||
'warehouse_ids',
|
||||
'product_id',
|
||||
'product_warehouse_id',
|
||||
'total_qty',
|
||||
];
|
||||
const floatFields = ['price'];
|
||||
|
||||
if (integerFields.includes(field)) {
|
||||
const numValue = typeof value === 'string' ? parseInt(value) || 0 : value;
|
||||
formik.setFieldValue(`purchase_items.${idx}.${field}`, numValue);
|
||||
} else if (floatFields.includes(field)) {
|
||||
const numValue =
|
||||
typeof value === 'string' ? parseFloat(value) || 0 : value;
|
||||
formik.setFieldValue(`purchase_items.${idx}.${field}`, numValue);
|
||||
} else {
|
||||
formik.setFieldValue(`purchase_items.${idx}.${field}`, value);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -388,6 +399,7 @@ const PurchaseRequestForm = ({
|
||||
</td>
|
||||
<td>
|
||||
<TextInput
|
||||
required
|
||||
name={`purchase_items.${idx}.product_warehouse_id`}
|
||||
value={item.product_warehouse_id || ''}
|
||||
onChange={(e) =>
|
||||
|
||||
Reference in New Issue
Block a user