mirror of
https://github.com/inventree/InvenTree.git
synced 2026-11-20 06:57:57 +00:00
feat: Add Delivery Address field to Purchase Orders (#9768)
* Add delivery address to purchase order; migrate address field to Supplier Address (#9303) * update model related_name and remove migrate file * regenerate migration * Fix migration ordering * Bump API version * add 'receiving_company' field * UI updates * Add regression tests --------- Co-authored-by: Oliver <oliver.henry.walters@gmail.com> Co-authored-by: Matthias Mair <code@mjmair.com>
This commit is contained in:
12 files changed
+589
-6
No files matched your search
@@ -14,6 +14,7 @@ import {
|
||||
import { useDisclosure, useId } from '@mantine/hooks';
|
||||
import {
|
||||
IconAddressBook,
|
||||
IconBuildingSkyscraper,
|
||||
IconCalendar,
|
||||
IconCoins,
|
||||
IconCurrencyDollar,
|
||||
@@ -254,6 +255,9 @@ export function usePurchaseOrderFields({
|
||||
}): ApiFormFieldSet {
|
||||
const globalSettings = useGlobalSettingsState();
|
||||
|
||||
const [supplier, setSupplier] = useState<number | null>(supplierId ?? null);
|
||||
const [receivingCompany, setReceivingCompany] = useState<number | null>(null);
|
||||
|
||||
return useMemo(() => {
|
||||
const fields: ApiFormFieldSet = {
|
||||
reference: {
|
||||
@@ -267,6 +271,9 @@ export function usePurchaseOrderFields({
|
||||
is_supplier: true,
|
||||
active: true
|
||||
},
|
||||
onValueChange: (value: any) => {
|
||||
setSupplier(value || null);
|
||||
},
|
||||
addCreateFields: {
|
||||
name: {},
|
||||
description: {},
|
||||
@@ -301,6 +308,7 @@ export function usePurchaseOrderFields({
|
||||
link: {},
|
||||
contact: {
|
||||
icon: <IconUser />,
|
||||
disabled: !supplier,
|
||||
adjustFilters: (value: ApiFormAdjustFilterType) => {
|
||||
return {
|
||||
...value.filters,
|
||||
@@ -310,6 +318,7 @@ export function usePurchaseOrderFields({
|
||||
},
|
||||
address: {
|
||||
icon: <IconAddressBook />,
|
||||
disabled: !supplier,
|
||||
adjustFilters: (value: ApiFormAdjustFilterType) => {
|
||||
return {
|
||||
...value.filters,
|
||||
@@ -317,6 +326,26 @@ export function usePurchaseOrderFields({
|
||||
};
|
||||
}
|
||||
},
|
||||
receiving_company: {
|
||||
icon: <IconBuildingSkyscraper />,
|
||||
filters: {
|
||||
is_internal: true,
|
||||
active: true
|
||||
},
|
||||
onValueChange: (value: any) => {
|
||||
setReceivingCompany(value || null);
|
||||
}
|
||||
},
|
||||
delivery_address: {
|
||||
icon: <IconAddressBook />,
|
||||
disabled: !receivingCompany,
|
||||
adjustFilters: (value: ApiFormAdjustFilterType) => {
|
||||
return {
|
||||
...value.filters,
|
||||
company: value.data.receiving_company
|
||||
};
|
||||
}
|
||||
},
|
||||
responsible: {
|
||||
filters: {
|
||||
is_active: true
|
||||
@@ -346,7 +375,14 @@ export function usePurchaseOrderFields({
|
||||
}
|
||||
|
||||
return fields;
|
||||
}, [duplicateOrderId, supplierId, create, globalSettings]);
|
||||
}, [
|
||||
duplicateOrderId,
|
||||
supplierId,
|
||||
create,
|
||||
globalSettings,
|
||||
supplier,
|
||||
receivingCompany
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { t } from '@lingui/core/macro';
|
||||
import { Grid, Skeleton, Stack } from '@mantine/core';
|
||||
import { Grid, Skeleton, Stack, Text } from '@mantine/core';
|
||||
import { useMemo } from 'react';
|
||||
|
||||
import TagsList from '@lib/components/TagsList';
|
||||
@@ -16,6 +16,7 @@ import { DetailsImage } from '../../components/details/DetailsImage';
|
||||
import { ItemDetailsGrid } from '../../components/details/ItemDetails';
|
||||
import { LineItemOverviewTable } from '../../components/details/LineItemOverviewTable';
|
||||
import { useParameterDetailsGrid } from '../../components/details/ParameterDetailsGrid';
|
||||
import { RenderAddress } from '../../components/render/Company';
|
||||
import { formatCurrency } from '../../defaults/formatters';
|
||||
import { useGlobalSettingsState } from '../../states/SettingsStates';
|
||||
|
||||
@@ -101,6 +102,27 @@ export function PurchaseOrderDetailsPanel({
|
||||
label: t`Destination`,
|
||||
hidden: !instance?.destination
|
||||
},
|
||||
{
|
||||
type: 'link',
|
||||
model: ModelType.company,
|
||||
name: 'receiving_company',
|
||||
label: t`Receiving Company`,
|
||||
icon: 'internal_company',
|
||||
hidden: !instance?.receiving_company
|
||||
},
|
||||
{
|
||||
type: 'text',
|
||||
name: 'delivery_address',
|
||||
label: t`Delivery Address`,
|
||||
icon: 'address',
|
||||
hidden: !instance?.receiving_company && !instance?.delivery_address,
|
||||
value_formatter: () =>
|
||||
instance?.delivery_address_detail ? (
|
||||
<RenderAddress instance={instance.delivery_address_detail} />
|
||||
) : (
|
||||
<Text size='sm' c='red'>{t`Not specified`}</Text>
|
||||
)
|
||||
},
|
||||
{
|
||||
type: 'text',
|
||||
name: 'currency',
|
||||
|
||||
Reference in new issue
Block a user