mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Remove 'single_price' field from supplier part
- Instead we will rely entirely on the SupplierPriceBreak model
This commit is contained in:
parent
3a0f60930e
commit
a2dbdfe794
19
InvenTree/build/migrations/0014_auto_20190518_1543.py
Normal file
19
InvenTree/build/migrations/0014_auto_20190518_1543.py
Normal file
@ -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'),
|
||||||
|
),
|
||||||
|
]
|
@ -155,7 +155,6 @@ class EditSupplierPartForm(HelperForm):
|
|||||||
'MPN',
|
'MPN',
|
||||||
'URL',
|
'URL',
|
||||||
'note',
|
'note',
|
||||||
'single_price',
|
|
||||||
'base_cost',
|
'base_cost',
|
||||||
'multiple',
|
'multiple',
|
||||||
'minimum',
|
'minimum',
|
||||||
|
@ -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',
|
||||||
|
),
|
||||||
|
]
|
@ -816,7 +816,6 @@ class SupplierPart(models.Model):
|
|||||||
URL: Link to external website for this part
|
URL: Link to external website for this part
|
||||||
description: Descriptive notes field
|
description: Descriptive notes field
|
||||||
note: Longer form note 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"
|
base_cost: Base charge added to order independent of quantity e.g. "Reeling Fee"
|
||||||
multiple: Multiple that the part is provided in
|
multiple: Multiple that the part is provided in
|
||||||
minimum: MOQ (minimum order quantity) required for purchase
|
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')
|
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)')
|
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')
|
packaging = models.CharField(max_length=50, blank=True, help_text='Part packaging')
|
||||||
@ -885,26 +882,25 @@ class SupplierPart(models.Model):
|
|||||||
def get_price(self, quantity, moq=True, multiples=True):
|
def get_price(self, quantity, moq=True, multiples=True):
|
||||||
""" Calculate the supplier price based on quantity price breaks.
|
""" 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)
|
- Don't forget to add in flat-fee cost (base_cost field)
|
||||||
- If MOQ (minimum order quantity) is required, bump quantity
|
- 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
|
- 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
|
# Minimum ordering requirement
|
||||||
if moq and self.minimum > quantity:
|
if moq and self.minimum > quantity:
|
||||||
quantity = self.minimum
|
quantity = self.minimum
|
||||||
|
|
||||||
|
# Order multiples
|
||||||
|
if multiples:
|
||||||
|
quantity = int(math.ceil(quantity / self.multipe) * self.multiple)
|
||||||
|
|
||||||
pb_found = False
|
pb_found = False
|
||||||
pb_quantity = -1
|
pb_quantity = -1
|
||||||
pb_cost = 0.0
|
pb_cost = 0.0
|
||||||
|
|
||||||
for pb in self.price_breaks.all():
|
for pb in self.price_breaks.all():
|
||||||
# Ignore this pricebreak!
|
# Ignore this pricebreak (quantity is too high)
|
||||||
if pb.quantity > quantity:
|
if pb.quantity > quantity:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
@ -915,13 +911,11 @@ class SupplierPart(models.Model):
|
|||||||
pb_quantity = pb.quantity
|
pb_quantity = pb.quantity
|
||||||
pb_cost = pb.cost
|
pb_cost = pb.cost
|
||||||
|
|
||||||
# No appropriate price-break found - use the single cost!
|
|
||||||
if pb_found:
|
if pb_found:
|
||||||
cost = pb_cost * quantity
|
cost = pb_cost * quantity
|
||||||
|
return cost + self.base_cost
|
||||||
else:
|
else:
|
||||||
cost = self.single_price * quantity
|
return None
|
||||||
|
|
||||||
return cost + self.base_cost
|
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
s = "{supplier} ({sku})".format(
|
s = "{supplier} ({sku})".format(
|
||||||
|
Loading…
Reference in New Issue
Block a user