mirror of
https://github.com/inventree/InvenTree.git
synced 2025-06-18 21:15:41 +00:00
Remove common_currency model entirely
- A lot of views / pages / etc needed to be updated too - Now uses django-money fields entirely - Create a manual rate exchange backend (needs more work!)
This commit is contained in:
@ -13,7 +13,6 @@ from .models import SupplierPart
|
||||
from .models import SupplierPriceBreak
|
||||
|
||||
from part.models import Part
|
||||
from common.models import Currency
|
||||
|
||||
|
||||
class CompanyResource(ModelResource):
|
||||
@ -75,8 +74,6 @@ class SupplierPriceBreakResource(ModelResource):
|
||||
|
||||
part = Field(attribute='part', widget=widgets.ForeignKeyWidget(SupplierPart))
|
||||
|
||||
currency = Field(attribute='currency', widget=widgets.ForeignKeyWidget(Currency))
|
||||
|
||||
supplier_id = Field(attribute='part__supplier__pk', readonly=True)
|
||||
|
||||
supplier_name = Field(attribute='part__supplier__name', readonly=True)
|
||||
@ -98,7 +95,7 @@ class SupplierPriceBreakAdmin(ImportExportModelAdmin):
|
||||
|
||||
resource_class = SupplierPriceBreakResource
|
||||
|
||||
list_display = ('part', 'quantity', 'cost')
|
||||
list_display = ('part', 'quantity', 'price')
|
||||
|
||||
|
||||
admin.site.register(Company, CompanyAdmin)
|
||||
|
@ -7,21 +7,21 @@
|
||||
fields:
|
||||
part: 1
|
||||
quantity: 1
|
||||
cost: 10
|
||||
price: 10
|
||||
|
||||
- model: company.supplierpricebreak
|
||||
pk: 2
|
||||
fields:
|
||||
part: 1
|
||||
quantity: 5
|
||||
cost: 7.50
|
||||
price: 7.50
|
||||
|
||||
- model: company.supplierpricebreak
|
||||
pk: 3
|
||||
fields:
|
||||
part: 1
|
||||
quantity: 25
|
||||
cost: 3.50
|
||||
price: 3.50
|
||||
|
||||
# Price breaks for ACME0002
|
||||
- model: company.supplierpricebreak
|
||||
@ -29,14 +29,14 @@
|
||||
fields:
|
||||
part: 2
|
||||
quantity: 5
|
||||
cost: 7.00
|
||||
price: 7.00
|
||||
|
||||
- model: company.supplierpricebreak
|
||||
pk: 5
|
||||
fields:
|
||||
part: 2
|
||||
quantity: 50
|
||||
cost: 1.25
|
||||
price: 1.25
|
||||
|
||||
# Price breaks for ZERGLPHS
|
||||
- model: company.supplierpricebreak
|
||||
@ -44,11 +44,11 @@
|
||||
fields:
|
||||
part: 4
|
||||
quantity: 25
|
||||
cost: 8
|
||||
price: 8
|
||||
|
||||
- model: company.supplierpricebreak
|
||||
pk: 7
|
||||
fields:
|
||||
part: 4
|
||||
quantity: 100
|
||||
cost: 1.25
|
||||
price: 1.25
|
@ -82,13 +82,10 @@ class EditPriceBreakForm(HelperForm):
|
||||
|
||||
quantity = RoundingDecimalFormField(max_digits=10, decimal_places=5)
|
||||
|
||||
cost = RoundingDecimalFormField(max_digits=10, decimal_places=5)
|
||||
|
||||
class Meta:
|
||||
model = SupplierPriceBreak
|
||||
fields = [
|
||||
'part',
|
||||
'quantity',
|
||||
'cost',
|
||||
'currency',
|
||||
'price',
|
||||
]
|
||||
|
@ -0,0 +1,17 @@
|
||||
# Generated by Django 3.0.7 on 2020-11-10 11:40
|
||||
|
||||
from django.db import migrations
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('company', '0026_auto_20201110_1011'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.RemoveField(
|
||||
model_name='supplierpricebreak',
|
||||
name='currency',
|
||||
),
|
||||
]
|
@ -0,0 +1,17 @@
|
||||
# Generated by Django 3.0.7 on 2020-11-10 11:42
|
||||
|
||||
from django.db import migrations
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('company', '0027_remove_supplierpricebreak_currency'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.RemoveField(
|
||||
model_name='supplierpricebreak',
|
||||
name='cost',
|
||||
),
|
||||
]
|
@ -350,7 +350,7 @@ class SupplierPart(models.Model):
|
||||
def unit_pricing(self):
|
||||
return self.get_price(1)
|
||||
|
||||
def get_price(self, quantity, moq=True, multiples=True):
|
||||
def get_price(self, quantity, moq=True, multiples=True, currency=None):
|
||||
""" Calculate the supplier price based on quantity price breaks.
|
||||
|
||||
- Don't forget to add in flat-fee cost (base_cost field)
|
||||
@ -372,6 +372,10 @@ class SupplierPart(models.Model):
|
||||
pb_quantity = -1
|
||||
pb_cost = 0.0
|
||||
|
||||
if currency is None:
|
||||
# Default currency selection
|
||||
currency = common.models.InvenTreeSetting.get_setting('INVENTREE_DEFAULT_CURRENCY')
|
||||
|
||||
for pb in self.price_breaks.all():
|
||||
# Ignore this pricebreak (quantity is too high)
|
||||
if pb.quantity > quantity:
|
||||
@ -382,8 +386,9 @@ 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
|
||||
# Convert everything to base currency
|
||||
pb_cost = pb.converted_cost
|
||||
|
||||
# Convert everything to the selected currency
|
||||
pb_cost = pb.convert_to(currency)
|
||||
|
||||
if pb_found:
|
||||
cost = pb_cost * quantity
|
||||
@ -462,7 +467,4 @@ class SupplierPriceBreak(common.models.PriceBreak):
|
||||
db_table = 'part_supplierpricebreak'
|
||||
|
||||
def __str__(self):
|
||||
return "{mpn} - {cost} @ {quan}".format(
|
||||
mpn=self.part.MPN,
|
||||
cost=self.cost,
|
||||
quan=self.quantity)
|
||||
return f'{self.part.MPN} - {self.price} @ {self.quantity}'
|
||||
|
@ -137,13 +137,9 @@ class SupplierPartSerializer(InvenTreeModelSerializer):
|
||||
class SupplierPriceBreakSerializer(InvenTreeModelSerializer):
|
||||
""" Serializer for SupplierPriceBreak object """
|
||||
|
||||
symbol = serializers.CharField(read_only=True)
|
||||
|
||||
suffix = serializers.CharField(read_only=True)
|
||||
|
||||
quantity = serializers.FloatField()
|
||||
|
||||
cost = serializers.FloatField()
|
||||
price = serializers.CharField()
|
||||
|
||||
class Meta:
|
||||
model = SupplierPriceBreak
|
||||
@ -151,8 +147,5 @@ class SupplierPriceBreakSerializer(InvenTreeModelSerializer):
|
||||
'pk',
|
||||
'part',
|
||||
'quantity',
|
||||
'cost',
|
||||
'currency',
|
||||
'symbol',
|
||||
'suffix',
|
||||
'price',
|
||||
]
|
||||
|
@ -76,18 +76,11 @@ $('#price-break-table').inventreeTable({
|
||||
sortable: true,
|
||||
},
|
||||
{
|
||||
field: 'cost',
|
||||
field: 'price',
|
||||
title: '{% trans "Price" %}',
|
||||
sortable: true,
|
||||
formatter: function(value, row, index) {
|
||||
var html = '';
|
||||
|
||||
html += row.symbol || '';
|
||||
html += value;
|
||||
|
||||
if (row.suffix) {
|
||||
html += ' ' + row.suffix || '';
|
||||
}
|
||||
var html = value;
|
||||
|
||||
html += `<div class='btn-group float-right' role='group'>`
|
||||
|
||||
|
@ -6,6 +6,8 @@ from .models import Company, Contact, SupplierPart
|
||||
from .models import rename_company_image
|
||||
from part.models import Part
|
||||
|
||||
from InvenTree.exchange import InvenTreeManualExchangeBackend
|
||||
from djmoney.contrib.exchange.models import Rate
|
||||
|
||||
class CompanySimpleTest(TestCase):
|
||||
|
||||
@ -32,6 +34,14 @@ class CompanySimpleTest(TestCase):
|
||||
self.zerglphs = SupplierPart.objects.get(SKU='ZERGLPHS')
|
||||
self.zergm312 = SupplierPart.objects.get(SKU='ZERGM312')
|
||||
|
||||
InvenTreeManualExchangeBackend().update_rates()
|
||||
|
||||
Rate.objects.create(
|
||||
currency='AUD',
|
||||
value='1.35',
|
||||
backend_id='inventree',
|
||||
)
|
||||
|
||||
def test_company_model(self):
|
||||
c = Company.objects.get(name='ABC Co.')
|
||||
self.assertEqual(c.name, 'ABC Co.')
|
||||
|
@ -12,12 +12,12 @@ from django.views.generic import DetailView, ListView, UpdateView
|
||||
from django.urls import reverse
|
||||
from django.forms import HiddenInput
|
||||
|
||||
from moneyed import CURRENCIES
|
||||
|
||||
from InvenTree.views import AjaxCreateView, AjaxUpdateView, AjaxDeleteView
|
||||
from InvenTree.helpers import str2bool
|
||||
from InvenTree.views import InvenTreeRoleMixin
|
||||
|
||||
from common.models import Currency
|
||||
|
||||
from .models import Company
|
||||
from .models import SupplierPart
|
||||
from .models import SupplierPriceBreak
|
||||
@ -29,6 +29,8 @@ from .forms import CompanyImageForm
|
||||
from .forms import EditSupplierPartForm
|
||||
from .forms import EditPriceBreakForm
|
||||
|
||||
import common.models
|
||||
|
||||
|
||||
class CompanyIndex(InvenTreeRoleMixin, ListView):
|
||||
""" View for displaying list of companies
|
||||
@ -435,12 +437,11 @@ class PriceBreakCreate(AjaxCreateView):
|
||||
|
||||
initials['part'] = self.get_part()
|
||||
|
||||
# Pre-select the default currency
|
||||
try:
|
||||
base = Currency.objects.get(base=True)
|
||||
initials['currency'] = base
|
||||
except Currency.DoesNotExist:
|
||||
pass
|
||||
default_currency = common.models.InvenTreeSetting.get_setting('INVENTREE_DEFAULT_CURRENCY')
|
||||
currency = CURRENCIES.get(default_currency, None)
|
||||
|
||||
if currency is not None:
|
||||
initials['price'] = [1.0, currency]
|
||||
|
||||
return initials
|
||||
|
||||
|
Reference in New Issue
Block a user