mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Merge pull request #2539 from SchrodingersGat/exchange-rate-bug-fix
Add try/except blocks for calls to conert_money
This commit is contained in:
commit
506f5696ca
@ -29,6 +29,8 @@ from markdownx.models import MarkdownxField
|
||||
|
||||
from django_cleanup import cleanup
|
||||
|
||||
from djmoney.contrib.exchange.exceptions import MissingRate
|
||||
|
||||
from mptt.models import TreeForeignKey, MPTTModel
|
||||
from mptt.exceptions import InvalidMove
|
||||
from mptt.managers import TreeManager
|
||||
@ -1832,9 +1834,14 @@ class Part(MPTTModel):
|
||||
|
||||
def get_purchase_price(self, quantity):
|
||||
currency = currency_code_default()
|
||||
try:
|
||||
prices = [convert_money(item.purchase_price, currency).amount for item in self.stock_items.all() if item.purchase_price]
|
||||
except MissingRate:
|
||||
prices = None
|
||||
|
||||
if prices:
|
||||
return min(prices) * quantity, max(prices) * quantity
|
||||
|
||||
return None
|
||||
|
||||
@transaction.atomic
|
||||
|
@ -20,6 +20,7 @@ from django.contrib import messages
|
||||
|
||||
from moneyed import CURRENCIES
|
||||
from djmoney.contrib.exchange.models import convert_money
|
||||
from djmoney.contrib.exchange.exceptions import MissingRate
|
||||
|
||||
from PIL import Image
|
||||
|
||||
@ -425,7 +426,11 @@ class PartDetail(InvenTreeRoleMixin, DetailView):
|
||||
continue
|
||||
|
||||
# convert purchase price to current currency - only one currency in the graph
|
||||
try:
|
||||
price = convert_money(stock_item.purchase_price, default_currency)
|
||||
except MissingRate:
|
||||
continue
|
||||
|
||||
line = {
|
||||
'price': price.amount,
|
||||
'qty': stock_item.quantity
|
||||
@ -487,7 +492,11 @@ class PartDetail(InvenTreeRoleMixin, DetailView):
|
||||
if None in [sale_item.purchase_price, sale_item.quantity]:
|
||||
continue
|
||||
|
||||
try:
|
||||
price = convert_money(sale_item.purchase_price, default_currency)
|
||||
except MissingRate:
|
||||
continue
|
||||
|
||||
line = {
|
||||
'price': price.amount if price else 0,
|
||||
'qty': sale_item.quantity,
|
||||
|
Loading…
Reference in New Issue
Block a user