diff --git a/InvenTree/company/models.py b/InvenTree/company/models.py index 06aa100f26..b45bd04c3d 100644 --- a/InvenTree/company/models.py +++ b/InvenTree/company/models.py @@ -7,6 +7,8 @@ from __future__ import unicode_literals import os +import math + from django.core.validators import MinValueValidator from django.apps import apps @@ -260,7 +262,7 @@ class SupplierPart(models.Model): # Order multiples if multiples: - quantity = int(math.ceil(quantity / self.multipe) * self.multiple) + quantity = int(math.ceil(quantity / self.multiple) * self.multiple) pb_found = False pb_quantity = -1 diff --git a/InvenTree/part/models.py b/InvenTree/part/models.py index 62fb6e7553..00fb07290e 100644 --- a/InvenTree/part/models.py +++ b/InvenTree/part/models.py @@ -563,6 +563,61 @@ class Part(models.Model): """ Return the number of supplier parts available for this part """ return self.supplier_parts.count() + @property + def min_single_price(self): + return self.get_min_supplier_price(1) + + @property + def max_single_price(self): + return self.get_max_supplier_price(1) + + def get_min_supplier_price(self, quantity=1): + """ Return the minimum price of this part from all available suppliers. + + Args: + quantity: Number of units we wish to purchase (default = 1) + + Returns: + Numerical price if pricing is available, else None + """ + + min_price = None + + for supplier_part in self.supplier_parts.all(): + supplier_price = supplier_part.get_price(quantity) + + if supplier_price is None: + continue + + if min_price is None or supplier_price < min_price: + min_price = supplier_price + + return min_price + + def get_max_supplier_price(self, quantity=1): + """ Return the maximum price of this part from all available suppliers. + + Args: + quantity: Number of units we wish to purchase (default = 1) + + Returns: + Numerical price if pricing is available, else None + """ + + max_price = None + + for supplier_part in self.supplier_parts.all(): + supplier_price = supplier_part.get_price(quantity) + + if supplier_price is None: + continue + + if max_price is None or supplier_price > max_price: + max_price = supplier_price + + return max_price + + def deepCopy(self, other, **kwargs): """ Duplicates non-field data from another part. Does not alter the normal fields of this part, diff --git a/InvenTree/part/templates/part/part_base.html b/InvenTree/part/templates/part/part_base.html index ea3bbc7617..405556bdfa 100644 --- a/InvenTree/part/templates/part/part_base.html +++ b/InvenTree/part/templates/part/part_base.html @@ -82,6 +82,25 @@