From c58ed5a07e415177118671518734036845d147c4 Mon Sep 17 00:00:00 2001 From: Matthias Date: Mon, 9 Aug 2021 01:43:50 +0200 Subject: [PATCH 1/2] Fixes #1915 --- InvenTree/templates/js/translated/part.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/InvenTree/templates/js/translated/part.js b/InvenTree/templates/js/translated/part.js index 6f51f492c4..3218765c46 100644 --- a/InvenTree/templates/js/translated/part.js +++ b/InvenTree/templates/js/translated/part.js @@ -1106,6 +1106,7 @@ function loadPriceBreakTable(table, options) { formatNoMatches: function() { return `{% trans "No ${human_name} information found" %}`; }, + queryParams: {part: options.part}, url: options.url, onLoadSuccess: function(tableData) { if (linkedGraph) { @@ -1201,6 +1202,7 @@ function initPriceBreakSet(table, options) { human_name: pb_human_name, url: pb_url, linkedGraph: linkedGraph, + part: part_id, } ); From ad656b7ca7defcd04f8b24bd78bc3634bab6b690 Mon Sep 17 00:00:00 2001 From: Matthias Date: Mon, 9 Aug 2021 01:49:55 +0200 Subject: [PATCH 2/2] extending API to supply price wihtout formatting --- InvenTree/part/serializers.py | 19 ++++++++++++++++--- InvenTree/templates/js/translated/part.js | 2 +- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/InvenTree/part/serializers.py b/InvenTree/part/serializers.py index 9463ec9400..e2c8c3fa4d 100644 --- a/InvenTree/part/serializers.py +++ b/InvenTree/part/serializers.py @@ -15,7 +15,8 @@ from djmoney.contrib.django_rest_framework import MoneyField from InvenTree.serializers import (InvenTreeAttachmentSerializerField, InvenTreeImageSerializerField, - InvenTreeModelSerializer) + InvenTreeModelSerializer, + InvenTreeMoneySerializer) from InvenTree.status_codes import BuildStatus, PurchaseOrderStatus from stock.models import StockItem @@ -102,7 +103,12 @@ class PartSalePriceSerializer(InvenTreeModelSerializer): quantity = serializers.FloatField() - price = serializers.CharField() + price = InvenTreeMoneySerializer( + max_digits=19, decimal_places=4, + allow_null=True + ) + + price_string = serializers.CharField(source='price', read_only=True) class Meta: model = PartSellPriceBreak @@ -111,6 +117,7 @@ class PartSalePriceSerializer(InvenTreeModelSerializer): 'part', 'quantity', 'price', + 'price_string', ] @@ -121,7 +128,12 @@ class PartInternalPriceSerializer(InvenTreeModelSerializer): quantity = serializers.FloatField() - price = serializers.CharField() + price = InvenTreeMoneySerializer( + max_digits=19, decimal_places=4, + allow_null=True + ) + + price_string = serializers.CharField(source='price', read_only=True) class Meta: model = PartInternalPriceBreak @@ -130,6 +142,7 @@ class PartInternalPriceSerializer(InvenTreeModelSerializer): 'part', 'quantity', 'price', + 'price_string', ] diff --git a/InvenTree/templates/js/translated/part.js b/InvenTree/templates/js/translated/part.js index 3218765c46..3d8a21c66a 100644 --- a/InvenTree/templates/js/translated/part.js +++ b/InvenTree/templates/js/translated/part.js @@ -1115,7 +1115,7 @@ function loadPriceBreakTable(table, options) { // split up for graph definition var graphLabels = Array.from(tableData, x => x.quantity); - var graphData = Array.from(tableData, x => parseFloat(x.price)); + var graphData = Array.from(tableData, x => x.price); // destroy chart if exists if (chart){