mirror of
https://github.com/inventree/InvenTree.git
synced 2025-04-29 20:16:44 +00:00
Fix money field kwargs (#5722)
- Reduces number of calls to currency_code_defaults() - Thus reducing number of database hits (cherry picked from commit 15ff99a24d2a4dcbe38cf4f2c7b886c8820952e8)
This commit is contained in:
parent
a566ac67a7
commit
8f75758c45
@ -44,13 +44,23 @@ class InvenTreeURLField(models.URLField):
|
|||||||
super().__init__(**kwargs)
|
super().__init__(**kwargs)
|
||||||
|
|
||||||
|
|
||||||
def money_kwargs():
|
def money_kwargs(**kwargs):
|
||||||
"""Returns the database settings for MoneyFields."""
|
"""Returns the database settings for MoneyFields."""
|
||||||
from common.settings import currency_code_default, currency_code_mappings
|
from common.settings import currency_code_default, currency_code_mappings
|
||||||
|
|
||||||
kwargs = {}
|
# Default values (if not specified)
|
||||||
kwargs['currency_choices'] = currency_code_mappings()
|
if 'max_digits' not in kwargs:
|
||||||
kwargs['default_currency'] = currency_code_default()
|
kwargs['max_digits'] = 19
|
||||||
|
|
||||||
|
if 'decimal_places' not in kwargs:
|
||||||
|
kwargs['decimal_places'] = 6
|
||||||
|
|
||||||
|
if 'currency_choices' not in kwargs:
|
||||||
|
kwargs['currency_choices'] = currency_code_mappings()
|
||||||
|
|
||||||
|
if 'default_currency' not in kwargs:
|
||||||
|
kwargs['default_currency'] = currency_code_default()
|
||||||
|
|
||||||
return kwargs
|
return kwargs
|
||||||
|
|
||||||
|
|
||||||
@ -64,16 +74,8 @@ class InvenTreeModelMoneyField(ModelMoneyField):
|
|||||||
# remove currency information for a clean migration
|
# remove currency information for a clean migration
|
||||||
kwargs['default_currency'] = ''
|
kwargs['default_currency'] = ''
|
||||||
kwargs['currency_choices'] = []
|
kwargs['currency_choices'] = []
|
||||||
else:
|
|
||||||
# set defaults
|
|
||||||
kwargs.update(money_kwargs())
|
|
||||||
|
|
||||||
# Default values (if not specified)
|
kwargs = money_kwargs(**kwargs)
|
||||||
if 'max_digits' not in kwargs:
|
|
||||||
kwargs['max_digits'] = 19
|
|
||||||
|
|
||||||
if 'decimal_places' not in kwargs:
|
|
||||||
kwargs['decimal_places'] = 6
|
|
||||||
|
|
||||||
# Set a minimum value validator
|
# Set a minimum value validator
|
||||||
validators = kwargs.get('validators', [])
|
validators = kwargs.get('validators', [])
|
||||||
@ -115,11 +117,8 @@ class InvenTreeMoneyField(MoneyField):
|
|||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
"""Override initial values with the real info from database."""
|
"""Override initial values with the real info from database."""
|
||||||
kwargs.update(money_kwargs())
|
|
||||||
|
|
||||||
kwargs['max_digits'] = 19
|
|
||||||
kwargs['decimal_places'] = 6
|
|
||||||
|
|
||||||
|
kwargs = money_kwargs(**kwargs)
|
||||||
super().__init__(*args, **kwargs)
|
super().__init__(*args, **kwargs)
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user