mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Add currency field to SupplierPriceBreak
This commit is contained in:
parent
9f91797f42
commit
c6a435eba0
@ -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'),
|
||||||
|
),
|
||||||
|
]
|
@ -19,6 +19,7 @@ from django.conf import settings
|
|||||||
from django.contrib.staticfiles.templatetags.staticfiles import static
|
from django.contrib.staticfiles.templatetags.staticfiles import static
|
||||||
|
|
||||||
from InvenTree.status_codes import OrderStatus
|
from InvenTree.status_codes import OrderStatus
|
||||||
|
from common.models import Currency
|
||||||
|
|
||||||
|
|
||||||
def rename_company_image(instance, filename):
|
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 this price-break quantity is the largest so far, use it!
|
||||||
if pb.quantity > pb_quantity:
|
if pb.quantity > pb_quantity:
|
||||||
pb_quantity = pb.quantity
|
pb_quantity = pb.quantity
|
||||||
pb_cost = pb.cost
|
pb_cost = pb.get_cost()
|
||||||
|
|
||||||
if pb_found:
|
if pb_found:
|
||||||
cost = pb_cost * quantity
|
cost = pb_cost * quantity
|
||||||
@ -369,6 +370,7 @@ class SupplierPriceBreak(models.Model):
|
|||||||
part: Link to a SupplierPart object that this price break applies to
|
part: Link to a SupplierPart object that this price break applies to
|
||||||
quantity: Quantity required for price break
|
quantity: Quantity required for price break
|
||||||
cost: Cost at specified quantity
|
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')
|
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)])
|
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:
|
class Meta:
|
||||||
unique_together = ("part", "quantity")
|
unique_together = ("part", "quantity")
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user