mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Return price breaks in the correct order
This commit is contained in:
parent
a3cd54875c
commit
1163f60b23
19
InvenTree/part/migrations/0030_auto_20190518_1641.py
Normal file
19
InvenTree/part/migrations/0030_auto_20190518_1641.py
Normal file
@ -0,0 +1,19 @@
|
||||
# Generated by Django 2.2 on 2019-05-18 06:41
|
||||
|
||||
from django.db import migrations, models
|
||||
import django.db.models.deletion
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('part', '0029_auto_20190518_1632'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='supplierpricebreak',
|
||||
name='part',
|
||||
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='pricebreaks', to='part.SupplierPart'),
|
||||
),
|
||||
]
|
@ -879,6 +879,11 @@ class SupplierPart(models.Model):
|
||||
def has_price_breaks(self):
|
||||
return self.price_breaks.count() > 0
|
||||
|
||||
@property
|
||||
def price_breaks(self):
|
||||
""" Return the associated price breaks in the correct order """
|
||||
return self.pricebreaks.order_by('quantity').all()
|
||||
|
||||
def get_price(self, quantity, moq=True, multiples=True):
|
||||
""" Calculate the supplier price based on quantity price breaks.
|
||||
|
||||
@ -939,7 +944,7 @@ class SupplierPriceBreak(models.Model):
|
||||
cost: Cost at specified quantity
|
||||
"""
|
||||
|
||||
part = models.ForeignKey(SupplierPart, on_delete=models.CASCADE, related_name='price_breaks')
|
||||
part = models.ForeignKey(SupplierPart, on_delete=models.CASCADE, related_name='pricebreaks')
|
||||
|
||||
quantity = models.PositiveIntegerField(validators=[MinValueValidator(1)])
|
||||
|
||||
@ -949,8 +954,7 @@ class SupplierPriceBreak(models.Model):
|
||||
unique_together = ("part", "quantity")
|
||||
|
||||
def __str__(self):
|
||||
return "{mpn} - {cost}{currency} @ {quan}".format(
|
||||
return "{mpn} - {cost} @ {quan}".format(
|
||||
mpn=self.part.MPN,
|
||||
cost=self.cost,
|
||||
currency=self.currency if self.currency else '',
|
||||
quan=self.quantity)
|
||||
|
Loading…
Reference in New Issue
Block a user