2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-06-18 21:15:41 +00:00

[UI] Pricing chart fixes ()

* Fix default values for pricing override

* Fix broken calculation for sale pricing

- Was previously excluding COMPLETED orders

* Fix for PricingOverviewPanel

* Fix for InvenTreeMoneySerializer

- Numbers should be represented as numbers!

* Front-end wrangling too

* Fix unit test
This commit is contained in:
Oliver
2025-02-21 19:09:57 +11:00
committed by GitHub
parent 15ad62494f
commit ab4eff19d3
10 changed files with 86 additions and 39 deletions

@ -68,7 +68,7 @@ function BomPieChart({
return {
// Note: Replace '.' in name to avoid issues with tooltip
name: entry?.name?.replace('.', '') ?? '',
value: entry?.total_price_max,
value: Number.parseFloat(entry?.total_price_max),
color: `${CHART_COLORS[index % CHART_COLORS.length]}.5`
};
}) ?? []

@ -26,6 +26,7 @@ import { type ReactNode, useCallback, useMemo } from 'react';
import { api } from '../../../App';
import { tooltipFormatter } from '../../../components/charts/tooltipFormatter';
import type { ApiFormFieldSet } from '../../../components/forms/fields/ApiFormField';
import {
EditItemAction,
OptionsActionDropdown
@ -35,12 +36,14 @@ import { ApiEndpoints } from '../../../enums/ApiEndpoints';
import { InvenTreeIcon } from '../../../functions/icons';
import { useEditApiFormModal } from '../../../hooks/UseForm';
import { apiUrl } from '../../../states/ApiState';
import { useGlobalSettingsState } from '../../../states/SettingsState';
import { panelOptions } from '../PartPricingPanel';
interface PricingOverviewEntry {
icon: ReactNode;
name: panelOptions;
title: string;
valid: boolean;
min_value: number | null | undefined;
max_value: number | null | undefined;
visible?: boolean;
@ -58,6 +61,8 @@ export default function PricingOverviewPanel({
pricingQuery: UseQueryResult;
doNavigation: (panel: panelOptions) => void;
}>): ReactNode {
const globalSettings = useGlobalSettingsState();
const refreshPricing = useCallback(() => {
const url = apiUrl(ApiEndpoints.part_pricing, part.pk);
@ -99,19 +104,29 @@ export default function PricingOverviewPanel({
});
}, [part]);
const editPricing = useEditApiFormModal({
title: t`Edit Pricing`,
url: apiUrl(ApiEndpoints.part_pricing, part.pk),
fields: {
const pricingFields: ApiFormFieldSet = useMemo(() => {
return {
override_min: {},
override_min_currency: {},
override_min_currency: {
default:
globalSettings.getSetting('INVENTREE_DEFAULT_CURRENCY') ?? 'USD'
},
override_max: {},
override_max_currency: {},
override_max_currency: {
default:
globalSettings.getSetting('INVENTREE_DEFAULT_CURRENCY') ?? 'USD'
},
update: {
hidden: true,
value: true
}
},
};
}, [globalSettings]);
const editPricing = useEditApiFormModal({
title: t`Edit Pricing`,
url: apiUrl(ApiEndpoints.part_pricing, part.pk),
fields: pricingFields,
onFormSuccess: () => {
pricingQuery.refetch();
}
@ -172,67 +187,85 @@ export default function PricingOverviewPanel({
name: panelOptions.override,
title: t`Override Pricing`,
icon: <IconExclamationCircle />,
min_value: pricing?.override_min,
max_value: pricing?.override_max
min_value: Number.parseFloat(pricing?.override_min),
max_value: Number.parseFloat(pricing?.override_max),
valid: pricing?.override_min != null && pricing?.override_max != null
},
{
name: panelOptions.overall,
title: t`Overall Pricing`,
icon: <IconReportAnalytics />,
min_value: pricing?.overall_min,
max_value: pricing?.overall_max
min_value: Number.parseFloat(pricing?.overall_min),
max_value: Number.parseFloat(pricing?.overall_max),
valid: pricing?.overall_min != null && pricing?.overall_max != null
},
{
name: panelOptions.internal,
title: t`Internal Pricing`,
icon: <IconList />,
min_value: pricing?.internal_cost_min,
max_value: pricing?.internal_cost_max
min_value: Number.parseFloat(pricing?.internal_cost_min),
max_value: Number.parseFloat(pricing?.internal_cost_max),
valid:
pricing?.internal_cost_min != null &&
pricing?.internal_cost_max != null
},
{
name: panelOptions.bom,
title: t`BOM Pricing`,
icon: <IconChartDonut />,
min_value: pricing?.bom_cost_min,
max_value: pricing?.bom_cost_max
min_value: Number.parseFloat(pricing?.bom_cost_min),
max_value: Number.parseFloat(pricing?.bom_cost_max),
valid: pricing?.bom_cost_min != null && pricing?.bom_cost_max != null
},
{
name: panelOptions.purchase,
title: t`Purchase Pricing`,
icon: <IconShoppingCart />,
min_value: pricing?.purchase_cost_min,
max_value: pricing?.purchase_cost_max
min_value: Number.parseFloat(pricing?.purchase_cost_min),
max_value: Number.parseFloat(pricing?.purchase_cost_max),
valid:
pricing?.purchase_cost_min != null &&
pricing?.purchase_cost_max != null
},
{
name: panelOptions.supplier,
title: t`Supplier Pricing`,
icon: <IconBuildingWarehouse />,
min_value: pricing?.supplier_price_min,
max_value: pricing?.supplier_price_max
min_value: Number.parseFloat(pricing?.supplier_price_min),
max_value: Number.parseFloat(pricing?.supplier_price_max),
valid:
pricing?.supplier_price_min != null &&
pricing?.supplier_price_max != null
},
{
name: panelOptions.variant,
title: t`Variant Pricing`,
icon: <IconTriangleSquareCircle />,
min_value: pricing?.variant_cost_min,
max_value: pricing?.variant_cost_max
min_value: Number.parseFloat(pricing?.variant_cost_min),
max_value: Number.parseFloat(pricing?.variant_cost_max),
valid:
pricing?.variant_cost_min != null && pricing?.variant_cost_max != null
},
{
name: panelOptions.sale_pricing,
title: t`Sale Pricing`,
icon: <IconTriangleSquareCircle />,
min_value: pricing?.sale_price_min,
max_value: pricing?.sale_price_max
min_value: Number.parseFloat(pricing?.sale_price_min),
max_value: Number.parseFloat(pricing?.sale_price_max),
valid:
pricing?.sale_price_min != null && pricing?.sale_price_max != null
},
{
name: panelOptions.sale_history,
title: t`Sale History`,
icon: <IconTriangleSquareCircle />,
min_value: pricing?.sale_history_min,
max_value: pricing?.sale_history_max
min_value: Number.parseFloat(pricing?.sale_history_min),
max_value: Number.parseFloat(pricing?.sale_history_max),
valid:
pricing?.sale_history_min != null && pricing?.sale_history_max != null
}
].filter((entry) => {
return !(entry.min_value == null || entry.max_value == null);
return entry.valid;
});
}, [part, pricing]);

@ -21,7 +21,7 @@ export default function PurchaseHistoryPanel({
const calculateUnitPrice = useCallback((record: any) => {
const pack_quantity =
record?.supplier_part_detail?.pack_quantity_native ?? 1;
const unit_price = record.purchase_price / pack_quantity;
const unit_price = Number.parseFloat(record.purchase_price) / pack_quantity;
return unit_price;
}, []);
@ -95,7 +95,7 @@ export default function PurchaseHistoryPanel({
return table.records.map((record: any) => {
return {
quantity: record.quantity,
purchase_price: record.purchase_price,
purchase_price: Number.parseFloat(record.purchase_price),
unit_price: calculateUnitPrice(record),
name: record.order_detail.reference
};

@ -57,7 +57,7 @@ export default function SaleHistoryPanel({
return table.records.map((record: any) => {
return {
name: record.order_detail.reference,
sale_price: record.sale_price
sale_price: Number.parseFloat(record.sale_price)
};
});
}, [table.records]);

@ -36,7 +36,7 @@ export default function SupplierPricingPanel({
table.records?.map((record: any) => {
return {
quantity: record.quantity,
supplier_price: record.price,
supplier_price: Number.parseFloat(record.price),
unit_price: calculateSupplierPartUnitPrice(record),
name: record.part_detail?.SKU
};

@ -63,8 +63,10 @@ export default function VariantPricingPanel({
return {
part: variant,
name: variant.full_name,
pmin: variant.pricing_min ?? variant.pricing_max ?? 0,
pmax: variant.pricing_max ?? variant.pricing_min ?? 0
pmin: Number.parseFloat(
variant.pricing_min ?? variant.pricing_max ?? 0
),
pmax: Number.parseFloat(variant.pricing_max ?? variant.pricing_min ?? 0)
};
});

@ -24,7 +24,7 @@ import { type RowAction, RowDeleteAction, RowEditAction } from '../RowActions';
export function calculateSupplierPartUnitPrice(record: any) {
const pack_quantity = record?.part_detail?.pack_quantity_native ?? 1;
const unit_price = record.price / pack_quantity;
const unit_price = Number.parseFloat(record.price) / pack_quantity;
return unit_price;
}