From a2dbdfe794ebc738581568fd10620d0eaec4aecf Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Sat, 18 May 2019 15:45:32 +1000 Subject: [PATCH] Remove 'single_price' field from supplier part - Instead we will rely entirely on the SupplierPriceBreak model --- .../migrations/0014_auto_20190518_1543.py | 19 ++++++++++++++++ InvenTree/part/forms.py | 1 - .../0026_remove_supplierpart_single_price.py | 17 ++++++++++++++ InvenTree/part/models.py | 22 +++++++------------ 4 files changed, 44 insertions(+), 15 deletions(-) create mode 100644 InvenTree/build/migrations/0014_auto_20190518_1543.py create mode 100644 InvenTree/part/migrations/0026_remove_supplierpart_single_price.py diff --git a/InvenTree/build/migrations/0014_auto_20190518_1543.py b/InvenTree/build/migrations/0014_auto_20190518_1543.py new file mode 100644 index 0000000000..9fbd095445 --- /dev/null +++ b/InvenTree/build/migrations/0014_auto_20190518_1543.py @@ -0,0 +1,19 @@ +# Generated by Django 2.2 on 2019-05-18 05:43 + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('build', '0013_build_take_from'), + ] + + operations = [ + migrations.AlterField( + model_name='build', + name='take_from', + field=models.ForeignKey(blank=True, help_text='Select location to take stock from for this build (leave blank to take from any stock location)', null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='sourcing_builds', to='stock.StockLocation'), + ), + ] diff --git a/InvenTree/part/forms.py b/InvenTree/part/forms.py index d4e70ee47a..988cb7aa38 100644 --- a/InvenTree/part/forms.py +++ b/InvenTree/part/forms.py @@ -155,7 +155,6 @@ class EditSupplierPartForm(HelperForm): 'MPN', 'URL', 'note', - 'single_price', 'base_cost', 'multiple', 'minimum', diff --git a/InvenTree/part/migrations/0026_remove_supplierpart_single_price.py b/InvenTree/part/migrations/0026_remove_supplierpart_single_price.py new file mode 100644 index 0000000000..f0bde887a4 --- /dev/null +++ b/InvenTree/part/migrations/0026_remove_supplierpart_single_price.py @@ -0,0 +1,17 @@ +# Generated by Django 2.2 on 2019-05-18 05:43 + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('part', '0025_auto_20190515_0012'), + ] + + operations = [ + migrations.RemoveField( + model_name='supplierpart', + name='single_price', + ), + ] diff --git a/InvenTree/part/models.py b/InvenTree/part/models.py index f4673dc309..1aa52342a9 100644 --- a/InvenTree/part/models.py +++ b/InvenTree/part/models.py @@ -816,7 +816,6 @@ class SupplierPart(models.Model): URL: Link to external website for this part description: Descriptive notes field note: Longer form note field - single_price: Default price for a single unit base_cost: Base charge added to order independent of quantity e.g. "Reeling Fee" multiple: Multiple that the part is provided in minimum: MOQ (minimum order quantity) required for purchase @@ -854,8 +853,6 @@ class SupplierPart(models.Model): note = models.CharField(max_length=100, blank=True, help_text='Notes') - single_price = models.DecimalField(max_digits=10, decimal_places=3, default=0, validators=[MinValueValidator(0)], help_text='Price for single quantity') - base_cost = models.DecimalField(max_digits=10, decimal_places=3, default=0, validators=[MinValueValidator(0)], help_text='Minimum charge (e.g. stocking fee)') packaging = models.CharField(max_length=50, blank=True, help_text='Part packaging') @@ -884,27 +881,26 @@ class SupplierPart(models.Model): def get_price(self, quantity, moq=True, multiples=True): """ Calculate the supplier price based on quantity price breaks. - - - If no price breaks available, use the single_price field + - Don't forget to add in flat-fee cost (base_cost field) - If MOQ (minimum order quantity) is required, bump quantity - If order multiples are to be observed, then we need to calculate based on that, too """ - # Order multiples - if multiples: - quantity = int(math.ceil(quantity / self.multipe) * self.multiple) - # Minimum ordering requirement if moq and self.minimum > quantity: quantity = self.minimum + # Order multiples + if multiples: + quantity = int(math.ceil(quantity / self.multipe) * self.multiple) + pb_found = False pb_quantity = -1 pb_cost = 0.0 for pb in self.price_breaks.all(): - # Ignore this pricebreak! + # Ignore this pricebreak (quantity is too high) if pb.quantity > quantity: continue @@ -915,13 +911,11 @@ class SupplierPart(models.Model): pb_quantity = pb.quantity pb_cost = pb.cost - # No appropriate price-break found - use the single cost! if pb_found: cost = pb_cost * quantity + return cost + self.base_cost else: - cost = self.single_price * quantity - - return cost + self.base_cost + return None def __str__(self): s = "{supplier} ({sku})".format(