Skip to content

Commit

Permalink
Merge pull request #12 from inventree/sales-order-fix
Browse files Browse the repository at this point in the history
Bug Fix - Missing parts
  • Loading branch information
SchrodingersGat authored Nov 8, 2024
2 parents e9a0da7 + 0b70d07 commit 31e4ca5
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 2 deletions.
11 changes: 10 additions & 1 deletion frontend/src/OrderHistoryPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ function OrderHistoryPanel({context}: {context: any}) {

const [ loading, setLoading ] = useState<boolean>(true);

const [ error, setError ] = useState<boolean>(false);

// Plugin settings object
const pluginSettings = useMemo(() => context?.context?.settings ?? {}, [context]);

Expand Down Expand Up @@ -197,7 +199,7 @@ function OrderHistoryPanel({context}: {context: any}) {

// Ensure that the selected order type is valid for the current context
useEffect(() => {
if (!validOrderTypes.find((type) => type.value == orderType)) {
if (!validOrderTypes.find((type: any) => type.value == orderType)) {
setOrderType(validOrderTypes[0]?.value ?? null);
}
}, [orderType, validOrderTypes]);
Expand Down Expand Up @@ -240,10 +242,12 @@ function OrderHistoryPanel({context}: {context: any}) {
}).then((response: any) => {
setHistoryData(response.data);
setLoading(false);
setError(false);
}).catch(() => {
console.error("ERR: Failed to fetch history data");
setHistoryData([]);
setLoading(false);
setError(true);
});
}

Expand Down Expand Up @@ -391,6 +395,11 @@ function OrderHistoryPanel({context}: {context: any}) {
<Paper withBorder p="sm" m="sm">
<Box pos="relative">
<LoadingOverlay visible={loading} />
{error && (
<Alert color="red" title="Error Loading Data">
<Text>Failed to load order history data from the server</Text>
</Alert>
)}
{(hasData || loading) ? (
<Card>
<BarChart
Expand Down
2 changes: 1 addition & 1 deletion order_history/version.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
"""Version information for the Order History plugin."""

PLUGIN_VERSION = "0.3.2"
PLUGIN_VERSION = "0.3.3"
17 changes: 17 additions & 0 deletions order_history/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,10 @@ def generate_build_order_history(self):
for build in builds:
part = build.part

if not part:
# Skip builds which do not map to a part (may have been deleted, for example)
continue

if part.pk not in parts:
parts[part.pk] = part

Expand Down Expand Up @@ -156,6 +160,11 @@ def generate_purchase_order_history(self):
parts = {}

for line in lines:

if not line.part or not line.part.part:
# Skip lines which do not map to a part (may have been deleted, for example)
continue

part = line.part.part

part_history = history_items.get(part.pk, None) or {}
Expand Down Expand Up @@ -215,6 +224,10 @@ def generate_sales_order_history(self):
for line in lines:
part = line.part

if not part:
# Skip lines which do not map to a part (may have been deleted, for example)
continue

# Extract the date key for the line item
part_history = history_items.get(part.pk, None) or {}

Expand Down Expand Up @@ -268,6 +281,10 @@ def generate_return_order_history(self):
for line in lines:
part = line.item.part

if not part:
# Skip lines which do not map to a part (may have been deleted, for example)
continue

# Extract the date key for the line item
part_history = history_items.get(part.pk, None) or {}

Expand Down

0 comments on commit 31e4ca5

Please sign in to comment.