Specify default currency when creating a new stock item

This commit is contained in:
Oliver Walters 2020-11-12 11:50:59 +11:00
parent 51d2d85c26
commit 391eeb0e46

View File

@ -14,6 +14,8 @@ from django.urls import reverse
from django.utils.translation import ugettext as _ from django.utils.translation import ugettext as _
from moneyed import CURRENCIES
from InvenTree.views import AjaxView from InvenTree.views import AjaxView
from InvenTree.views import AjaxUpdateView, AjaxDeleteView, AjaxCreateView from InvenTree.views import AjaxUpdateView, AjaxDeleteView, AjaxCreateView
from InvenTree.views import QRCodeView from InvenTree.views import QRCodeView
@ -32,6 +34,8 @@ from report.models import TestReport
from label.models import StockItemLabel from label.models import StockItemLabel
from .models import StockItem, StockLocation, StockItemTracking, StockItemAttachment, StockItemTestResult from .models import StockItem, StockLocation, StockItemTracking, StockItemAttachment, StockItemTestResult
import common.settings
from .admin import StockItemResource from .admin import StockItemResource
from . import forms as StockForms from . import forms as StockForms
@ -1572,6 +1576,8 @@ class StockItemCreate(AjaxCreateView):
initials['location'] = part.get_default_location() initials['location'] = part.get_default_location()
initials['supplier_part'] = part.default_supplier initials['supplier_part'] = part.default_supplier
currency_code = common.settings.currency_code_default()
# SupplierPart field has been specified # SupplierPart field has been specified
# It must match the Part, if that has been supplied # It must match the Part, if that has been supplied
if sup_part_id: if sup_part_id:
@ -1581,6 +1587,8 @@ class StockItemCreate(AjaxCreateView):
if part is None or supplier_part.part == part: if part is None or supplier_part.part == part:
initials['supplier_part'] = supplier_part initials['supplier_part'] = supplier_part
currency_code = supplier_part.supplier.currency_code
except (ValueError, SupplierPart.DoesNotExist): except (ValueError, SupplierPart.DoesNotExist):
pass pass
@ -1592,6 +1600,11 @@ class StockItemCreate(AjaxCreateView):
except (ValueError, StockLocation.DoesNotExist): except (ValueError, StockLocation.DoesNotExist):
pass pass
currency = CURRENCIES.get(currency_code, None)
if currency:
initials['purchase_price'] = (None, currency)
return initials return initials
def post(self, request, *args, **kwargs): def post(self, request, *args, **kwargs):