Repository: inventree/InvenTree

Issue:
reintroduce BOM price?
https://github.com/inventree/InvenTree/blob/be85de4a7b5dc6d328fe1d519dd592fdba76b76e/InvenTree/templates/js/bom.js#L264-L281

Hey @SchrodingersGat do you thin pricing has been fixed / what was meant by that?


Discussion:
I think this has been addressed by now. I should have left more detail. I think that I disabled the pricing column as the pricing needed a huge overhaul and was very expensive (slow) to calculate. That comment can safely be removed now.

Resolving patch:
diff --git a/InvenTree/InvenTree/helpers.py b/InvenTree/InvenTree/helpers.py
--- a/InvenTree/InvenTree/helpers.py
+++ b/InvenTree/InvenTree/helpers.py
@@ -21,6 +21,9 @@
 
 from common.models import InvenTreeSetting
 from .settings import MEDIA_URL, STATIC_URL
+from common.settings import currency_code_default
+
+from djmoney.money import Money
 
 
 def getSetting(key, backup_value=None):
@@ -247,6 +250,22 @@ def decimal2string(d):
     return s.rstrip("0").rstrip(".")
 
 
+def decimal2money(d, currency=None):
+    """
+    Format a Decimal number as Money
+
+    Args:
+        d: A python Decimal object
+        currency: Currency of the input amount, defaults to default currency in settings
+
+    Returns:
+        A Money object from the input(s)
+    """
+    if not currency:
+        currency = currency_code_default()
+    return Money(d, currency)
+
+
 def WrapWithQuotes(text, quote='"'):
     """ Wrap the supplied text with quotes
 
diff --git a/InvenTree/part/models.py b/InvenTree/part/models.py
--- a/InvenTree/part/models.py
+++ b/InvenTree/part/models.py
@@ -39,7 +39,7 @@
 from InvenTree import validators
 from InvenTree.models import InvenTreeTree, InvenTreeAttachment
 from InvenTree.fields import InvenTreeURLField
-from InvenTree.helpers import decimal2string, normalize
+from InvenTree.helpers import decimal2string, normalize, decimal2money
 
 from InvenTree.status_codes import BuildStatus, PurchaseOrderStatus, SalesOrderStatus
 
@@ -2414,7 +2414,7 @@ def __str__(self):
         return "{n} x {child} to make {parent}".format(
             parent=self.part.full_name,
             child=self.sub_part.full_name,
-            n=helpers.decimal2string(self.quantity))
+            n=decimal2string(self.quantity))
 
     def available_stock(self):
         """
@@ -2498,12 +2498,12 @@ def get_required_quantity(self, build_quantity):
         return required
 
     @property
-    def price_range(self):
+    def price_range(self, internal=False):
         """ Return the price-range for this BOM item. """
 
         # get internal price setting
         use_internal = common.models.InvenTreeSetting.get_setting('PART_BOM_USE_INTERNAL_PRICE', False)
-        prange = self.sub_part.get_price_range(self.quantity, intenal=use_internal)
+        prange = self.sub_part.get_price_range(self.quantity, internal=use_internal and internal)
 
         if prange is None:
             return prange
@@ -2511,11 +2511,11 @@ def price_range(self):
         pmin, pmax = prange
 
         if pmin == pmax:
-            return decimal2string(pmin)
+            return decimal2money(pmin)
 
         # Convert to better string representation
-        pmin = decimal2string(pmin)
-        pmax = decimal2string(pmax)
+        pmin = decimal2money(pmin)
+        pmax = decimal2money(pmax)
 
         return "{pmin} to {pmax}".format(pmin=pmin, pmax=pmax)
 
diff --git a/InvenTree/part/serializers.py b/InvenTree/part/serializers.py
--- a/InvenTree/part/serializers.py
+++ b/InvenTree/part/serializers.py
@@ -377,7 +377,7 @@ class Meta:
 class BomItemSerializer(InvenTreeModelSerializer):
     """ Serializer for BomItem object """
 
-    # price_range = serializers.CharField(read_only=True)
+    price_range = serializers.CharField(read_only=True)
 
     quantity = serializers.FloatField()
 
@@ -492,7 +492,7 @@ class Meta:
             'reference',
             'sub_part',
             'sub_part_detail',
-            # 'price_range',
+            'price_range',
             'validated',
         ]
 


Test patch: