From 3a57093b4ede3eb0f46f5f9a11a88e486af4308d Mon Sep 17 00:00:00 2001 From: Matthias Date: Thu, 1 Jul 2021 00:13:38 +0200 Subject: [PATCH] replace MoneyFields with inherited classes --- InvenTree/InvenTree/fields.py | 10 ++++++++++ InvenTree/common/models.py | 3 +-- InvenTree/company/forms.py | 5 ++--- InvenTree/order/forms.py | 6 ++---- InvenTree/order/models.py | 8 +++----- InvenTree/stock/models.py | 6 ++---- 6 files changed, 20 insertions(+), 18 deletions(-) diff --git a/InvenTree/InvenTree/fields.py b/InvenTree/InvenTree/fields.py index c496c1bb22..25fbf77c90 100644 --- a/InvenTree/InvenTree/fields.py +++ b/InvenTree/InvenTree/fields.py @@ -13,6 +13,8 @@ from django.core import validators from django import forms from decimal import Decimal +from djmoney.models.fields import MoneyField as ModelMoneyField +from djmoney.forms.fields import MoneyField import InvenTree.helpers @@ -34,6 +36,14 @@ class InvenTreeURLField(models.URLField): }) +class InvenTreeModelMoneyField(ModelMoneyField): + pass + + +class InvenTreeMoneyField(MoneyField): + pass + + class DatePickerFormField(forms.DateField): """ Custom date-picker field diff --git a/InvenTree/common/models.py b/InvenTree/common/models.py index 55dc760d55..cb6329bb39 100644 --- a/InvenTree/common/models.py +++ b/InvenTree/common/models.py @@ -15,7 +15,6 @@ from django.db.utils import IntegrityError, OperationalError from django.conf import settings from djmoney.settings import CURRENCY_CHOICES -from djmoney.models.fields import MoneyField from djmoney.contrib.exchange.models import convert_money from djmoney.contrib.exchange.exceptions import MissingRate @@ -743,7 +742,7 @@ class PriceBreak(models.Model): help_text=_('Price break quantity'), ) - price = MoneyField( + price = InvenTree.fields.InvenTreeModelMoneyField( max_digits=19, decimal_places=4, default_currency=lambda: common.settings.currency_code_default(), diff --git a/InvenTree/company/forms.py b/InvenTree/company/forms.py index 80673b4fa4..c9497ab89f 100644 --- a/InvenTree/company/forms.py +++ b/InvenTree/company/forms.py @@ -6,13 +6,12 @@ Django Forms for interacting with Company app from __future__ import unicode_literals from InvenTree.forms import HelperForm -from InvenTree.fields import RoundingDecimalFormField +from InvenTree.fields import InvenTreeMoneyField, RoundingDecimalFormField from django.utils.translation import ugettext_lazy as _ import django.forms import djmoney.settings -from djmoney.forms.fields import MoneyField from common.settings import currency_code_default @@ -129,7 +128,7 @@ class EditSupplierPartForm(HelperForm): 'note': 'fa-pencil-alt', } - single_pricing = MoneyField( + single_pricing = InvenTreeMoneyField( label=_('Single Price'), default_currency=currency_code_default(), help_text=_('Single quantity price'), diff --git a/InvenTree/order/forms.py b/InvenTree/order/forms.py index 48b5245a5f..3dd687c685 100644 --- a/InvenTree/order/forms.py +++ b/InvenTree/order/forms.py @@ -10,10 +10,8 @@ from django.utils.translation import ugettext_lazy as _ from mptt.fields import TreeNodeChoiceField -from djmoney.forms.fields import MoneyField - from InvenTree.forms import HelperForm -from InvenTree.fields import RoundingDecimalFormField +from InvenTree.fields import InvenTreeMoneyField, RoundingDecimalFormField from InvenTree.fields import DatePickerFormField from InvenTree.helpers import clean_decimal @@ -321,7 +319,7 @@ class OrderMatchItemForm(MatchItemForm): ) # set price field elif 'price' in col_guess.lower(): - return MoneyField( + return InvenTreeMoneyField( label=_(col_guess), default_currency=InvenTreeSetting.get_setting('INVENTREE_DEFAULT_CURRENCY'), decimal_places=5, diff --git a/InvenTree/order/models.py b/InvenTree/order/models.py index c150331f94..8e5c881ebd 100644 --- a/InvenTree/order/models.py +++ b/InvenTree/order/models.py @@ -22,14 +22,12 @@ from common.settings import currency_code_default from markdownx.models import MarkdownxField from mptt.models import TreeForeignKey -from djmoney.models.fields import MoneyField - from users import models as UserModels from part import models as PartModels from stock import models as stock_models from company.models import Company, SupplierPart -from InvenTree.fields import RoundingDecimalField +from InvenTree.fields import InvenTreeModelMoneyField, RoundingDecimalField from InvenTree.helpers import decimal2string, increment, getSetting from InvenTree.status_codes import PurchaseOrderStatus, SalesOrderStatus, StockStatus, StockHistoryCode from InvenTree.models import InvenTreeAttachment @@ -664,7 +662,7 @@ class PurchaseOrderLineItem(OrderLineItem): received = models.DecimalField(decimal_places=5, max_digits=15, default=0, verbose_name=_('Received'), help_text=_('Number of items received')) - purchase_price = MoneyField( + purchase_price = InvenTreeModelMoneyField( max_digits=19, decimal_places=4, default_currency=currency_code_default(), @@ -716,7 +714,7 @@ class SalesOrderLineItem(OrderLineItem): part = models.ForeignKey('part.Part', on_delete=models.SET_NULL, related_name='sales_order_line_items', null=True, verbose_name=_('Part'), help_text=_('Part'), limit_choices_to={'salable': True}) - sale_price = MoneyField( + sale_price = InvenTreeModelMoneyField( max_digits=19, decimal_places=4, default_currency=currency_code_default(), diff --git a/InvenTree/stock/models.py b/InvenTree/stock/models.py index 9786b360d9..cab3ed0d1b 100644 --- a/InvenTree/stock/models.py +++ b/InvenTree/stock/models.py @@ -26,8 +26,6 @@ from markdownx.models import MarkdownxField from mptt.models import MPTTModel, TreeForeignKey -from djmoney.models.fields import MoneyField - from decimal import Decimal, InvalidOperation from datetime import datetime, timedelta from InvenTree import helpers @@ -38,7 +36,7 @@ import label.models from InvenTree.status_codes import StockStatus, StockHistoryCode from InvenTree.models import InvenTreeTree, InvenTreeAttachment -from InvenTree.fields import InvenTreeURLField +from InvenTree.fields import InvenTreeModelMoneyField, InvenTreeURLField from users.models import Owner @@ -533,7 +531,7 @@ class StockItem(MPTTModel): help_text=_('Stock Item Notes') ) - purchase_price = MoneyField( + purchase_price = InvenTreeModelMoneyField( max_digits=19, decimal_places=4, default_currency=currency_code_default(),