mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Display part pricing in Part view
- Calculate min_price and max_price based on provided supplier information
This commit is contained in:
parent
0cfb243eb3
commit
a3d1591929
@ -7,6 +7,8 @@ from __future__ import unicode_literals
|
|||||||
|
|
||||||
import os
|
import os
|
||||||
|
|
||||||
|
import math
|
||||||
|
|
||||||
from django.core.validators import MinValueValidator
|
from django.core.validators import MinValueValidator
|
||||||
|
|
||||||
from django.apps import apps
|
from django.apps import apps
|
||||||
@ -260,7 +262,7 @@ class SupplierPart(models.Model):
|
|||||||
|
|
||||||
# Order multiples
|
# Order multiples
|
||||||
if 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_found = False
|
||||||
pb_quantity = -1
|
pb_quantity = -1
|
||||||
|
@ -563,6 +563,61 @@ class Part(models.Model):
|
|||||||
""" Return the number of supplier parts available for this part """
|
""" Return the number of supplier parts available for this part """
|
||||||
return self.supplier_parts.count()
|
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):
|
def deepCopy(self, other, **kwargs):
|
||||||
""" Duplicates non-field data from another part.
|
""" Duplicates non-field data from another part.
|
||||||
Does not alter the normal fields of this part,
|
Does not alter the normal fields of this part,
|
||||||
|
@ -82,6 +82,25 @@
|
|||||||
<td>{{ part.allocation_count }}</td>
|
<td>{{ part.allocation_count }}</td>
|
||||||
</tr>
|
</tr>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
{% if part.supplier_count > 0 %}
|
||||||
|
<tr>
|
||||||
|
<td>
|
||||||
|
Price
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
{% if part.min_single_price %}
|
||||||
|
{% if part.min_single_price == part.max_single_price %}
|
||||||
|
{{ part.min_single_price }}
|
||||||
|
{% else %}
|
||||||
|
{{ part.min_single_price }} to {{ part.max_single_price }}
|
||||||
|
{% endif %}
|
||||||
|
from {{ part.supplier_count }} suppliers.
|
||||||
|
{% else %}
|
||||||
|
<span class='warning-msg'><i>No pricing data avilable</i></span>
|
||||||
|
{% endif %}
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
{% endif %}
|
||||||
</table>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
Loading…
Reference in New Issue
Block a user