mirror of
https://github.com/inventree/InvenTree.git
synced 2025-06-16 12:05:53 +00:00
Added various PO fixes (#6483)
* Added various PO fixes * Add auto-pricing and merge items functionality to PurchaseOrderLineItem * Bump api version to v173 * Add po line item create/update tests
This commit is contained in:
@ -144,24 +144,24 @@ export function ApiFormField({
|
||||
);
|
||||
|
||||
// Coerce the value to a numerical value
|
||||
const numericalValue: number | undefined = useMemo(() => {
|
||||
let val = 0;
|
||||
const numericalValue: number | '' = useMemo(() => {
|
||||
let val: number | '' = 0;
|
||||
|
||||
switch (definition.field_type) {
|
||||
case 'integer':
|
||||
val = parseInt(value) ?? 0;
|
||||
val = parseInt(value) ?? '';
|
||||
break;
|
||||
case 'decimal':
|
||||
case 'float':
|
||||
case 'number':
|
||||
val = parseFloat(value) ?? 0;
|
||||
val = parseFloat(value) ?? '';
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
if (isNaN(val) || !isFinite(val)) {
|
||||
val = 0;
|
||||
val = '';
|
||||
}
|
||||
|
||||
return val;
|
||||
|
@ -11,6 +11,7 @@ import {
|
||||
IconUser,
|
||||
IconUsers
|
||||
} from '@tabler/icons-react';
|
||||
import { useEffect, useMemo, useState } from 'react';
|
||||
|
||||
import {
|
||||
ApiFormAdjustFilterType,
|
||||
@ -20,45 +21,76 @@ import {
|
||||
/*
|
||||
* Construct a set of fields for creating / editing a PurchaseOrderLineItem instance
|
||||
*/
|
||||
export function purchaseOrderLineItemFields() {
|
||||
let fields: ApiFormFieldSet = {
|
||||
order: {
|
||||
filters: {
|
||||
supplier_detail: true
|
||||
},
|
||||
hidden: true
|
||||
},
|
||||
part: {
|
||||
filters: {
|
||||
part_detail: true,
|
||||
supplier_detail: true
|
||||
},
|
||||
adjustFilters: (value: ApiFormAdjustFilterType) => {
|
||||
// TODO: Adjust part based on the supplier associated with the supplier
|
||||
return value.filters;
|
||||
}
|
||||
},
|
||||
quantity: {},
|
||||
reference: {},
|
||||
purchase_price: {
|
||||
icon: <IconCurrencyDollar />
|
||||
},
|
||||
purchase_price_currency: {
|
||||
icon: <IconCoins />
|
||||
},
|
||||
target_date: {
|
||||
icon: <IconCalendar />
|
||||
},
|
||||
destination: {
|
||||
icon: <IconSitemap />
|
||||
},
|
||||
notes: {
|
||||
icon: <IconNotes />
|
||||
},
|
||||
link: {
|
||||
icon: <IconLink />
|
||||
export function usePurchaseOrderLineItemFields({
|
||||
create
|
||||
}: {
|
||||
create?: boolean;
|
||||
}) {
|
||||
const [purchasePrice, setPurchasePrice] = useState<string>('');
|
||||
const [autoPricing, setAutoPricing] = useState(true);
|
||||
|
||||
useEffect(() => {
|
||||
if (autoPricing) {
|
||||
setPurchasePrice('');
|
||||
}
|
||||
};
|
||||
}, [autoPricing]);
|
||||
|
||||
useEffect(() => {
|
||||
setAutoPricing(purchasePrice === '');
|
||||
}, [purchasePrice]);
|
||||
|
||||
const fields = useMemo(() => {
|
||||
const fields: ApiFormFieldSet = {
|
||||
order: {
|
||||
filters: {
|
||||
supplier_detail: true
|
||||
},
|
||||
hidden: true
|
||||
},
|
||||
part: {
|
||||
filters: {
|
||||
part_detail: true,
|
||||
supplier_detail: true
|
||||
},
|
||||
adjustFilters: (value: ApiFormAdjustFilterType) => {
|
||||
// TODO: Adjust part based on the supplier associated with the supplier
|
||||
return value.filters;
|
||||
}
|
||||
},
|
||||
quantity: {},
|
||||
reference: {},
|
||||
purchase_price: {
|
||||
icon: <IconCurrencyDollar />,
|
||||
value: purchasePrice,
|
||||
onValueChange: setPurchasePrice
|
||||
},
|
||||
purchase_price_currency: {
|
||||
icon: <IconCoins />
|
||||
},
|
||||
auto_pricing: {
|
||||
value: autoPricing,
|
||||
onValueChange: setAutoPricing
|
||||
},
|
||||
target_date: {
|
||||
icon: <IconCalendar />
|
||||
},
|
||||
destination: {
|
||||
icon: <IconSitemap />
|
||||
},
|
||||
notes: {
|
||||
icon: <IconNotes />
|
||||
},
|
||||
link: {
|
||||
icon: <IconLink />
|
||||
}
|
||||
};
|
||||
|
||||
if (create) {
|
||||
fields['merge_items'] = {};
|
||||
}
|
||||
|
||||
return fields;
|
||||
}, [create, autoPricing, purchasePrice]);
|
||||
|
||||
return fields;
|
||||
}
|
||||
|
@ -12,7 +12,7 @@ import { RenderStockLocation } from '../../components/render/Stock';
|
||||
import { ApiEndpoints } from '../../enums/ApiEndpoints';
|
||||
import { ModelType } from '../../enums/ModelType';
|
||||
import { UserRoles } from '../../enums/Roles';
|
||||
import { purchaseOrderLineItemFields } from '../../forms/PurchaseOrderForms';
|
||||
import { usePurchaseOrderLineItemFields } from '../../forms/PurchaseOrderForms';
|
||||
import { getDetailUrl } from '../../functions/urls';
|
||||
import {
|
||||
useCreateApiFormModal,
|
||||
@ -178,7 +178,7 @@ export function PurchaseOrderLineItemTable({
|
||||
const newLine = useCreateApiFormModal({
|
||||
url: ApiEndpoints.purchase_order_line_list,
|
||||
title: t`Add Line Item`,
|
||||
fields: purchaseOrderLineItemFields(),
|
||||
fields: usePurchaseOrderLineItemFields({ create: true }),
|
||||
initialData: {
|
||||
order: orderId
|
||||
},
|
||||
@ -193,7 +193,7 @@ export function PurchaseOrderLineItemTable({
|
||||
url: ApiEndpoints.purchase_order_line_list,
|
||||
pk: selectedLine,
|
||||
title: t`Edit Line Item`,
|
||||
fields: purchaseOrderLineItemFields(),
|
||||
fields: usePurchaseOrderLineItemFields({}),
|
||||
onFormSuccess: table.refreshTable
|
||||
});
|
||||
|
||||
|
Reference in New Issue
Block a user