mirror of
https://github.com/inventree/InvenTree.git
synced 2025-06-16 12:05:53 +00:00
[UI] Pricing chart fixes (#9119)
* 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:
@ -45,6 +45,12 @@ class InvenTreeMoneySerializer(MoneyField):
|
||||
|
||||
super().__init__(*args, **kwargs)
|
||||
|
||||
def to_representation(self, obj):
|
||||
"""Convert the Money object to a decimal value for representation."""
|
||||
val = super().to_representation(obj)
|
||||
|
||||
return float(val)
|
||||
|
||||
def get_value(self, data):
|
||||
"""Test that the returned amount is a valid Decimal."""
|
||||
amount = super(DecimalField, self).get_value(data)
|
||||
@ -73,7 +79,11 @@ class InvenTreeMoneySerializer(MoneyField):
|
||||
):
|
||||
return Money(amount, currency)
|
||||
|
||||
return amount
|
||||
try:
|
||||
fp_amount = float(amount)
|
||||
return fp_amount
|
||||
except Exception:
|
||||
return amount
|
||||
|
||||
|
||||
class InvenTreeCurrencySerializer(serializers.ChoiceField):
|
||||
|
@ -62,7 +62,6 @@ from order import models as OrderModels
|
||||
from order.status_codes import (
|
||||
PurchaseOrderStatus,
|
||||
PurchaseOrderStatusGroups,
|
||||
SalesOrderStatus,
|
||||
SalesOrderStatusGroups,
|
||||
)
|
||||
from stock import models as StockModels
|
||||
@ -3088,9 +3087,12 @@ class PartPricing(common.models.MetaMixin):
|
||||
min_sell_history = None
|
||||
max_sell_history = None
|
||||
|
||||
# Calculate sale price history too
|
||||
parts = self.part.get_descendants(include_self=True)
|
||||
|
||||
# Find all line items for shipped sales orders which reference this part
|
||||
line_items = OrderModels.SalesOrderLineItem.objects.filter(
|
||||
order__status=SalesOrderStatus.SHIPPED, part=self.part
|
||||
order__status__in=SalesOrderStatusGroups.COMPLETE, part__in=parts
|
||||
)
|
||||
|
||||
# Exclude line items which do not have associated pricing data
|
||||
|
@ -1515,13 +1515,13 @@ class StockItemTest(StockAPITestCase):
|
||||
data = self.get(url, expected_code=200).data
|
||||
|
||||
# Check fixture values
|
||||
self.assertEqual(data['purchase_price'], '123.000000')
|
||||
self.assertAlmostEqual(data['purchase_price'], 123, 3)
|
||||
self.assertEqual(data['purchase_price_currency'], 'AUD')
|
||||
|
||||
# Update just the amount
|
||||
data = self.patch(url, {'purchase_price': 456}, expected_code=200).data
|
||||
|
||||
self.assertEqual(data['purchase_price'], '456.000000')
|
||||
self.assertAlmostEqual(data['purchase_price'], 456, 3)
|
||||
self.assertEqual(data['purchase_price_currency'], 'AUD')
|
||||
|
||||
# Update the currency
|
||||
|
Reference in New Issue
Block a user