mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
When creating a new price break for a supplier part, default to using the currency code specified for the supplier company
This commit is contained in:
parent
1532be9c1e
commit
51d2d85c26
@ -464,7 +464,14 @@ class PriceBreak(models.Model):
|
||||
class Meta:
|
||||
abstract = True
|
||||
|
||||
quantity = InvenTree.fields.RoundingDecimalField(max_digits=15, decimal_places=5, default=1, validators=[MinValueValidator(1)])
|
||||
quantity = InvenTree.fields.RoundingDecimalField(
|
||||
max_digits=15,
|
||||
decimal_places=5,
|
||||
default=1,
|
||||
validators=[MinValueValidator(1)],
|
||||
verbose_name=_('Quantity'),
|
||||
help_text=_('Price break quantity'),
|
||||
)
|
||||
|
||||
price = MoneyField(
|
||||
max_digits=19,
|
||||
|
@ -107,7 +107,12 @@ class EditSupplierPartForm(HelperForm):
|
||||
class EditPriceBreakForm(HelperForm):
|
||||
""" Form for creating / editing a supplier price break """
|
||||
|
||||
quantity = RoundingDecimalFormField(max_digits=10, decimal_places=5)
|
||||
quantity = RoundingDecimalFormField(
|
||||
max_digits=10,
|
||||
decimal_places=5,
|
||||
label=_('Quantity'),
|
||||
help_text=_('Price break quantity'),
|
||||
)
|
||||
|
||||
class Meta:
|
||||
model = SupplierPriceBreak
|
||||
|
20
InvenTree/company/migrations/0030_auto_20201112_1112.py
Normal file
20
InvenTree/company/migrations/0030_auto_20201112_1112.py
Normal file
@ -0,0 +1,20 @@
|
||||
# Generated by Django 3.0.7 on 2020-11-12 00:12
|
||||
|
||||
import InvenTree.fields
|
||||
import django.core.validators
|
||||
from django.db import migrations
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('company', '0029_company_currency'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='supplierpricebreak',
|
||||
name='quantity',
|
||||
field=InvenTree.fields.RoundingDecimalField(decimal_places=5, default=1, help_text='Price break quantity', max_digits=15, validators=[django.core.validators.MinValueValidator(1)], verbose_name='Quantity'),
|
||||
),
|
||||
]
|
@ -17,6 +17,8 @@ from django.db.models import Sum, Q, UniqueConstraint
|
||||
from django.apps import apps
|
||||
from django.urls import reverse
|
||||
|
||||
from moneyed import CURRENCIES
|
||||
|
||||
from markdownx.models import MarkdownxField
|
||||
|
||||
from stdimage.models import StdImageField
|
||||
@ -29,6 +31,7 @@ from InvenTree.status_codes import PurchaseOrderStatus
|
||||
import InvenTree.validators
|
||||
|
||||
import common.models
|
||||
import common.settings
|
||||
|
||||
|
||||
def rename_company_image(instance, filename):
|
||||
@ -137,6 +140,22 @@ class Company(models.Model):
|
||||
validators=[InvenTree.validators.validate_currency_code],
|
||||
)
|
||||
|
||||
@property
|
||||
def currency_code(self):
|
||||
"""
|
||||
Return the currency code associated with this company.
|
||||
|
||||
- If the currency code is invalid, use the default currency
|
||||
- If the currency code is not specified, use the default currency
|
||||
"""
|
||||
|
||||
code = self.currency
|
||||
|
||||
if code not in CURRENCIES:
|
||||
code = common.settings.currency_code_default()
|
||||
|
||||
return code
|
||||
|
||||
def __str__(self):
|
||||
""" Get string representation of a Company """
|
||||
return "{n} - {d}".format(n=self.name, d=self.description)
|
||||
|
@ -30,6 +30,7 @@ from .forms import EditSupplierPartForm
|
||||
from .forms import EditPriceBreakForm
|
||||
|
||||
import common.models
|
||||
import common.settings
|
||||
|
||||
|
||||
class CompanyIndex(InvenTreeRoleMixin, ListView):
|
||||
@ -419,10 +420,23 @@ class PriceBreakCreate(AjaxCreateView):
|
||||
}
|
||||
|
||||
def get_part(self):
|
||||
"""
|
||||
Attempt to extract SupplierPart object from the supplied data.
|
||||
"""
|
||||
|
||||
try:
|
||||
return SupplierPart.objects.get(id=self.request.GET.get('part'))
|
||||
except SupplierPart.DoesNotExist:
|
||||
return SupplierPart.objects.get(id=self.request.POST.get('part'))
|
||||
supplier_part = SupplierPart.objects.get(pk=self.request.GET.get('part'))
|
||||
return supplier_part
|
||||
except (ValueError, SupplierPart.DoesNotExist):
|
||||
pass
|
||||
|
||||
try:
|
||||
supplier_part = SupplierPart.objects.get(pk=self.request.POST.get('part'))
|
||||
return supplier_part
|
||||
except (ValueError, SupplierPart.DoesNotExist):
|
||||
pass
|
||||
|
||||
return None
|
||||
|
||||
def get_form(self):
|
||||
|
||||
@ -435,12 +449,19 @@ class PriceBreakCreate(AjaxCreateView):
|
||||
|
||||
initials = super(AjaxCreateView, self).get_initial()
|
||||
|
||||
supplier_part = self.get_part()
|
||||
|
||||
initials['part'] = self.get_part()
|
||||
|
||||
default_currency = common.models.InvenTreeSetting.get_setting('INVENTREE_DEFAULT_CURRENCY')
|
||||
currency = CURRENCIES.get(default_currency, None)
|
||||
if supplier_part is not None:
|
||||
currency_code = supplier_part.supplier.currency_code
|
||||
else:
|
||||
currency_code = common.settings.currency_code_default()
|
||||
|
||||
if currency is not None:
|
||||
# Extract the currency object associated with the code
|
||||
currency = CURRENCIES.get(currency_code, None)
|
||||
|
||||
if currency:
|
||||
initials['price'] = [1.0, currency]
|
||||
|
||||
return initials
|
||||
|
20
InvenTree/part/migrations/0059_auto_20201112_1112.py
Normal file
20
InvenTree/part/migrations/0059_auto_20201112_1112.py
Normal file
@ -0,0 +1,20 @@
|
||||
# Generated by Django 3.0.7 on 2020-11-12 00:12
|
||||
|
||||
import InvenTree.fields
|
||||
import django.core.validators
|
||||
from django.db import migrations
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('part', '0058_remove_partsellpricebreak_cost'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='partsellpricebreak',
|
||||
name='quantity',
|
||||
field=InvenTree.fields.RoundingDecimalField(decimal_places=5, default=1, help_text='Price break quantity', max_digits=15, validators=[django.core.validators.MinValueValidator(1)], verbose_name='Quantity'),
|
||||
),
|
||||
]
|
Loading…
Reference in New Issue
Block a user