From 1163f60b235c18c6b215dd9d485dcbe8d87b6f93 Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Sat, 18 May 2019 16:42:15 +1000 Subject: [PATCH] Return price breaks in the correct order --- .../migrations/0030_auto_20190518_1641.py | 19 +++++++++++++++++++ InvenTree/part/models.py | 10 +++++++--- 2 files changed, 26 insertions(+), 3 deletions(-) create mode 100644 InvenTree/part/migrations/0030_auto_20190518_1641.py diff --git a/InvenTree/part/migrations/0030_auto_20190518_1641.py b/InvenTree/part/migrations/0030_auto_20190518_1641.py new file mode 100644 index 0000000000..7661dd6412 --- /dev/null +++ b/InvenTree/part/migrations/0030_auto_20190518_1641.py @@ -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'), + ), + ] diff --git a/InvenTree/part/models.py b/InvenTree/part/models.py index 42080ba408..9c5476674a 100644 --- a/InvenTree/part/models.py +++ b/InvenTree/part/models.py @@ -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)