From 09cb82cdc0bb9a5229f10b8ce1db0c82bd35f6f7 Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Tue, 3 Sep 2019 09:46:32 +1000 Subject: [PATCH] Fix converted_cost - Incompatibility between float and decimal --- InvenTree/company/models.py | 9 ++++++--- InvenTree/company/templates/company/partdetail.html | 5 ++++- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/InvenTree/company/models.py b/InvenTree/company/models.py index eb8d7e5215..f62b2f27a2 100644 --- a/InvenTree/company/models.py +++ b/InvenTree/company/models.py @@ -8,6 +8,7 @@ from __future__ import unicode_literals import os import math +from decimal import Decimal from django.core.validators import MinValueValidator from django.db import models @@ -311,7 +312,8 @@ class SupplierPart(models.Model): # If this price-break quantity is the largest so far, use it! if pb.quantity > pb_quantity: pb_quantity = pb.quantity - pb_cost = pb.get_cost() + # Convert everything to base currency + pb_cost = pb.converted_cost if pb_found: cost = pb_cost * quantity @@ -381,10 +383,11 @@ class SupplierPriceBreak(models.Model): currency = models.ForeignKey(Currency, blank=True, null=True, on_delete=models.SET_NULL) - def get_cost(self): + @property + def converted_cost(self): """ Return the cost of this price break, converted to the base currency """ - scaler = 1.0 + scaler = Decimal(1.0) if self.currency: scaler = self.currency.value diff --git a/InvenTree/company/templates/company/partdetail.html b/InvenTree/company/templates/company/partdetail.html index d945ec31c4..00e1d03b63 100644 --- a/InvenTree/company/templates/company/partdetail.html +++ b/InvenTree/company/templates/company/partdetail.html @@ -88,7 +88,10 @@ InvenTree | {{ company.name }} - Parts {% for pb in part.price_breaks.all %} {{ pb.quantity }} - {{ pb.cost }} + + {% if pb.currency %}{{ pb.currency.symbol }}{% endif %} + {{ pb.cost }} + {% if pb.currency %}{{ pb.currency.suffix }}{% endif %}