Add currency field to SupplierPriceBreak

This commit is contained in:
Oliver Walters 2019-09-03 09:34:32 +10:00
parent 9f91797f42
commit c6a435eba0
2 changed files with 35 additions and 1 deletions

View File

@ -0,0 +1,20 @@
# Generated by Django 2.2.4 on 2019-09-02 23:34
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('common', '0003_auto_20190902_2310'),
('company', '0005_auto_20190525_2356'),
]
operations = [
migrations.AddField(
model_name='supplierpricebreak',
name='currency',
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, to='common.Currency'),
),
]

View File

@ -19,6 +19,7 @@ from django.conf import settings
from django.contrib.staticfiles.templatetags.staticfiles import static
from InvenTree.status_codes import OrderStatus
from common.models import Currency
def rename_company_image(instance, filename):
@ -310,7 +311,7 @@ class SupplierPart(models.Model):
# If this price-break quantity is the largest so far, use it!
if pb.quantity > pb_quantity:
pb_quantity = pb.quantity
pb_cost = pb.cost
pb_cost = pb.get_cost()
if pb_found:
cost = pb_cost * quantity
@ -369,6 +370,7 @@ class SupplierPriceBreak(models.Model):
part: Link to a SupplierPart object that this price break applies to
quantity: Quantity required for price break
cost: Cost at specified quantity
currency: Reference to the currency of this pricebreak (leave empty for base currency)
"""
part = models.ForeignKey(SupplierPart, on_delete=models.CASCADE, related_name='pricebreaks')
@ -377,6 +379,18 @@ class SupplierPriceBreak(models.Model):
cost = models.DecimalField(max_digits=10, decimal_places=5, validators=[MinValueValidator(0)])
currency = models.ForeignKey(Currency, blank=True, null=True, on_delete=models.SET_NULL)
def get_cost(self):
""" Return the cost of this price break, converted to the base currency """
scaler = 1.0
if self.currency:
scaler = self.currency.value
return self.cost * scaler
class Meta:
unique_together = ("part", "quantity")