Blame pr_638.patch

3feee8
From d29ff6f488c9d0478d29dd32a77e2fe0e76e4fb6 Mon Sep 17 00:00:00 2001
3feee8
From: Anton Agestam <git@antonagestam.se>
3feee8
Date: Mon, 19 Apr 2021 17:21:12 +0200
0e12f2
Subject: [PATCH 01/16] Drop support for legacy versions
3feee8
3feee8
- Drop support for Django 1.11, 2.1 and 3.0.
3feee8
- Drop support for Python 3.5.
3feee8
---
3feee8
 .github/workflows/main.yml                  |    2 
0e12f2
 djmoney/models/fields.py                    |    4 -
3feee8
 djmoney/money.py                            |   52 +---------------------
3feee8
 djmoney/settings.py                         |   15 +-----
0e12f2
 docs/changes.rst                            |   15 ++++++
3feee8
 pytest.ini                                  |    3 -
0e12f2
 setup.py                                    |    2 
3feee8
 tests/conftest.py                           |    8 ---
3feee8
 tests/contrib/test_django_rest_framework.py |    3 -
3feee8
 tests/settings.py                           |   16 -------
3feee8
 tests/test_admin.py                         |   19 --------
0e12f2
 tests/test_models.py                        |   62 +++++++++++++++++----------
3feee8
 tests/test_money.py                         |   64 ++++------------------------
3feee8
 tests/test_tags.py                          |   35 ---------------
3feee8
 tests/testapp/models.py                     |    2 
0e12f2
 15 files changed, 80 insertions(+), 222 deletions(-)
3feee8
3feee8
--- a/.github/workflows/main.yml
3feee8
+++ b/.github/workflows/main.yml
3feee8
@@ -13,7 +13,7 @@ jobs:
3feee8
 
3feee8
       - uses: actions/setup-python@v2
3feee8
         with:
3feee8
-          python-version: 3.7
3feee8
+          python-version: 3.9
3feee8
 
3feee8
       - run: pip install pre-commit
3feee8
       - run: pre-commit run --all-files
e24198
--- a/djmoney/models/fields.py
e24198
+++ b/djmoney/models/fields.py
e24198
@@ -213,7 +213,7 @@ class MoneyField(models.DecimalField):
e24198
         elif isinstance(default, OldMoney):
e24198
             default = Money(default.amount, default.currency)
e24198
         if default is not None and default is not NOT_PROVIDED and not isinstance(default, Money):
e24198
-            raise ValueError("default value must be an instance of Money, is: %s" % default)
e24198
+            raise ValueError(f"default value must be an instance of Money, is: {default}")
e24198
         return default
e24198
 
e24198
     def to_python(self, value):
0e12f2
@@ -261,7 +261,7 @@ class MoneyField(models.DecimalField):
0e12f2
             default=self.default_currency,
0e12f2
             editable=False,
0e12f2
             choices=self.currency_choices,
0e12f2
-            null=self.default_currency is None,
0e12f2
+            null=self.null,
0e12f2
         )
0e12f2
         currency_field.creation_counter = self.creation_counter - 1
0e12f2
         currency_field_name = get_currency_field_name(name, self)
e24198
--- a/djmoney/money.py
e24198
+++ b/djmoney/money.py
e24198
@@ -1,5 +1,3 @@
e24198
-import warnings
e24198
-from functools import partial
e24198
 from types import MappingProxyType
e24198
 
e24198
 from django.conf import settings
3feee8
@@ -10,20 +8,13 @@ from django.utils.html import avoid_wrap
e24198
 from django.utils.safestring import mark_safe
e24198
 
e24198
 import moneyed.l10n
e24198
-import moneyed.localization
e24198
 from moneyed import Currency, Money as DefaultMoney
e24198
 
e24198
-from .settings import DECIMAL_PLACES, DECIMAL_PLACES_DISPLAY, IS_DECIMAL_PLACES_DISPLAY_SET, MONEY_FORMAT
e24198
+from .settings import DECIMAL_PLACES, MONEY_FORMAT
e24198
 
e24198
 
e24198
 __all__ = ["Money", "Currency"]
e24198
 
e24198
-_warn_decimal_places_display_deprecated = partial(
e24198
-    warnings.warn,
e24198
-    "`Money.decimal_places_display` is deprecated and will be removed in django-money 3.0.",
e24198
-    DeprecationWarning,
e24198
-)
e24198
-
e24198
 
e24198
 @deconstructible
e24198
 class Money(DefaultMoney):
e24198
@@ -33,27 +24,11 @@ class Money(DefaultMoney):
e24198
 
e24198
     use_l10n = None
e24198
 
e24198
-    def __init__(self, *args, decimal_places_display=None, format_options=None, **kwargs):
e24198
+    def __init__(self, *args, format_options=None, **kwargs):
e24198
         self.decimal_places = kwargs.pop("decimal_places", DECIMAL_PLACES)
e24198
-        self._decimal_places_display = decimal_places_display
e24198
-        if decimal_places_display is not None:
e24198
-            _warn_decimal_places_display_deprecated()
e24198
         self.format_options = MappingProxyType(format_options) if format_options is not None else None
e24198
         super().__init__(*args, **kwargs)
e24198
 
e24198
-    @property
e24198
-    def decimal_places_display(self):
e24198
-        _warn_decimal_places_display_deprecated()
e24198
-        if self._decimal_places_display is None:
e24198
-            return DECIMAL_PLACES_DISPLAY.get(self.currency.code, self.decimal_places)
e24198
-        return self._decimal_places_display
e24198
-
e24198
-    @decimal_places_display.setter
e24198
-    def decimal_places_display(self, value):
e24198
-        """ Set number of digits being displayed - `None` resets to `DECIMAL_PLACES_DISPLAY` setting """
e24198
-        _warn_decimal_places_display_deprecated()
e24198
-        self._decimal_places_display = value
e24198
-
e24198
     def _copy_attributes(self, source, target):
e24198
         """Copy attributes to the new `Money` instance.
e24198
 
3feee8
@@ -118,13 +93,6 @@ class Money(DefaultMoney):
3feee8
         return self.use_l10n
e24198
 
e24198
     def __str__(self):
e24198
-        if self._decimal_places_display is not None or IS_DECIMAL_PLACES_DISPLAY_SET:
e24198
-            kwargs = {"money": self, "decimal_places": self.decimal_places_display}
e24198
-            if self.is_localized:
e24198
-                locale = get_current_locale(for_babel=False)
e24198
-                if locale:
e24198
-                    kwargs["locale"] = locale
e24198
-            return moneyed.localization.format_money(**kwargs)
e24198
         format_options = {
e24198
             **MONEY_FORMAT,
e24198
             **(self.format_options or {}),
3feee8
@@ -175,22 +143,10 @@ class Money(DefaultMoney):
e24198
     __rmul__ = __mul__
e24198
 
e24198
 
e24198
-def get_current_locale(for_babel=True):
e24198
+def get_current_locale():
e24198
     # get_language can return None starting from Django 1.8
e24198
     language = translation.get_language() or settings.LANGUAGE_CODE
e24198
-    locale = translation.to_locale(language)
e24198
-
e24198
-    if for_babel:
e24198
-        return locale
e24198
-
e24198
-    if locale.upper() in moneyed.localization._FORMATTER.formatting_definitions:
e24198
-        return locale
e24198
-
e24198
-    locale = f"{locale}_{locale}".upper()
e24198
-    if locale in moneyed.localization._FORMATTER.formatting_definitions:
e24198
-        return locale
e24198
-
e24198
-    return ""
e24198
+    return translation.to_locale(language)
e24198
 
e24198
 
e24198
 def maybe_convert(value, currency):
e24198
--- a/djmoney/settings.py
e24198
+++ b/djmoney/settings.py
e24198
@@ -1,15 +1,14 @@
e24198
 import operator
e24198
-import warnings
e24198
 from types import MappingProxyType
e24198
 
e24198
 from django.conf import settings
e24198
 
e24198
-from moneyed import CURRENCIES, DEFAULT_CURRENCY, DEFAULT_CURRENCY_CODE
e24198
+from moneyed import CURRENCIES, Currency
e24198
 
e24198
 
e24198
 # The default currency, you can define this in your project's settings module
e24198
 # This has to be a currency object imported from moneyed
e24198
-DEFAULT_CURRENCY = getattr(settings, "DEFAULT_CURRENCY", DEFAULT_CURRENCY)
e24198
+DEFAULT_CURRENCY: Currency = getattr(settings, "DEFAULT_CURRENCY", None)
e24198
 
e24198
 
e24198
 # The default currency choices, you can define this in your project's
e24198
@@ -21,18 +20,10 @@ if CURRENCY_CHOICES is None:
e24198
     if PROJECT_CURRENCIES:
e24198
         CURRENCY_CHOICES = [(code, CURRENCIES[code].name) for code in PROJECT_CURRENCIES]
e24198
     else:
e24198
-        CURRENCY_CHOICES = [(c.code, c.name) for i, c in CURRENCIES.items() if c.code != DEFAULT_CURRENCY_CODE]
e24198
+        CURRENCY_CHOICES = [(c.code, c.name) for i, c in CURRENCIES.items() if c != DEFAULT_CURRENCY]
e24198
 
e24198
 CURRENCY_CHOICES.sort(key=operator.itemgetter(1, 0))
e24198
 DECIMAL_PLACES = getattr(settings, "CURRENCY_DECIMAL_PLACES", 2)
e24198
-_decimal_display_value = getattr(settings, "CURRENCY_DECIMAL_PLACES_DISPLAY", None)
e24198
-if _decimal_display_value is not None:
e24198
-    warnings.warn(
e24198
-        "`CURRENCY_DECIMAL_PLACES_DISPLAY` is deprecated and will be removed in django-money 3.0.",
e24198
-        DeprecationWarning,
e24198
-    )
e24198
-DECIMAL_PLACES_DISPLAY = _decimal_display_value or {currency[0]: DECIMAL_PLACES for currency in CURRENCY_CHOICES}
e24198
-IS_DECIMAL_PLACES_DISPLAY_SET = _decimal_display_value is not None
e24198
 
e24198
 OPEN_EXCHANGE_RATES_URL = getattr(settings, "OPEN_EXCHANGE_RATES_URL", "https://openexchangerates.org/api/latest.json")
e24198
 OPEN_EXCHANGE_RATES_APP_ID = getattr(settings, "OPEN_EXCHANGE_RATES_APP_ID", None)
e24198
--- a/docs/changes.rst
e24198
+++ b/docs/changes.rst
0e12f2
@@ -4,6 +4,12 @@ Changelog
0e12f2
 `Unreleased`_ - TBA
0e12f2
 -------------------
0e12f2
 
0e12f2
+**Changed**
0e12f2
+- Update py-moneyed to 2.0. `#638`_ (`antonagestam`_, `flaeppe`_, `paoloxnet`_)
0e12f2
+- Remove the deprecated ``Money.decimal_places_display`` property and argument. `#638`_ (`antonagestam`_, `flaeppe`_, `paoloxnet`_)
0e12f2
+- Remove the deprecated ``CURRENCY_DECIMAL_PLACES_DISPLAY`` setting. `#638`_ (`antonagestam`_, `flaeppe`_, `paoloxnet`_)
0e12f2
+- Null constraint on an implicit ``CurrencyField`` is now declared from ``null=...`` argument to ``MoneyField``. `#638`_ (`antonagestam`_, `flaeppe`_, `paoloxnet`_)
0e12f2
+
0e12f2
 **Fixed**
0e12f2
 
0e12f2
 - Improve the internal check for whether a currency is provided `#657`_ (`davidszotten`_)
0e12f2
@@ -70,6 +76,13 @@ Changelog
3feee8
 - ``Money.decimal_places_display`` will be removed in django-money 3.0.
3feee8
 - ``CURRENCY_DECIMAL_PLACES_DISPLAY`` will be removed in django-money 3.0.
e24198
 
3feee8
+- Drop support for Django 1.11, 2.1 and 3.0.
3feee8
+- Drop support for Python 3.5.
3feee8
+- Add support for Django 3.2.
e24198
+- Update py-moneyed to 2.0.
e24198
+- Remove the deprecated ``Money.decimal_places_display`` property and argument.
e24198
+- Remove the deprecated ``CURRENCY_DECIMAL_PLACES_DISPLAY`` setting.
e24198
+
3feee8
 `1.3.1`_ - 2021-02-04
e24198
 ---------------------
e24198
 
0e12f2
@@ -783,6 +796,7 @@ wrapping with ``money_manager``.
0e12f2
 .. _#657: https://github.com/django-money/django-money/issues/657
0e12f2
 .. _#648: https://github.com/django-money/django-money/issues/648
0e12f2
 .. _#646: https://github.com/django-money/django-money/issues/646
0e12f2
+.. _#638: https://github.com/django-money/django-money/issues/638
0e12f2
 .. _#637: https://github.com/django-money/django-money/issues/637
0e12f2
 .. _#630: https://github.com/django-money/django-money/pull/630
0e12f2
 .. _#629: https://github.com/django-money/django-money/pull/629
0e12f2
@@ -951,6 +965,7 @@ wrapping with ``money_manager``.
0e12f2
 .. _mstarostik: https://github.com/mstarostik
0e12f2
 .. _niklasb: https://github.com/niklasb
0e12f2
 .. _nerdoc: https://github.com/nerdoc
0e12f2
+.. _paoloxnet: https://github.com/paoloxnet
0e12f2
 .. _pjdelport: https://github.com/pjdelport
0e12f2
 .. _plumdog: https://github.com/plumdog
0e12f2
 .. _rach: https://github.com/rach
e24198
--- a/pytest.ini
e24198
+++ b/pytest.ini
e24198
@@ -2,6 +2,3 @@
e24198
 DJANGO_SETTINGS_MODULE=tests.settings
e24198
 filterwarnings =
e24198
     error::DeprecationWarning
e24198
-    ignore:This module and all its contents is deprecated in favour of new moneyed.l10n.format_money\.:DeprecationWarning
e24198
-    ignore:`Money\.decimal_places_display` is deprecated and will be removed in django-money 3\.0\.:DeprecationWarning
e24198
-    ignore:`CURRENCY_DECIMAL_PLACES_DISPLAY` is deprecated and will be removed in django-money 3\.0\.:DeprecationWarning
e24198
--- a/setup.py
e24198
+++ b/setup.py
0e12f2
@@ -66,7 +66,7 @@ setup(
e24198
     maintainer_email="greg@reinbach.com",
e24198
     license="BSD",
e24198
     packages=find_packages(include=["djmoney", "djmoney.*"]),
e24198
-    install_requires=["setuptools", "Django>=2.2", "py-moneyed>=1.2,<2.0"],
3feee8
+    install_requires=["setuptools", "Django>=2.2", "py-moneyed>=2.0,<3.0"],
e24198
     python_requires=">=3.6",
e24198
     platforms=["Any"],
e24198
     keywords=["django", "py-money", "money"],
e24198
--- a/tests/conftest.py
e24198
+++ b/tests/conftest.py
e24198
@@ -1,5 +1,3 @@
e24198
-from unittest import mock
e24198
-
e24198
 import pytest
e24198
 
e24198
 from djmoney.contrib.exchange.models import ExchangeBackend, Rate, get_default_backend_name
e24198
@@ -31,9 +29,3 @@ def concrete_instance(m2m_object):
e24198
 
e24198
 
e24198
 pytest_plugins = "pytester"
e24198
-
e24198
-
e24198
-@pytest.yield_fixture
e24198
-def legacy_formatting():
e24198
-    with mock.patch("djmoney.money.IS_DECIMAL_PLACES_DISPLAY_SET", True):
e24198
-        yield
e24198
--- a/tests/contrib/test_django_rest_framework.py
e24198
+++ b/tests/contrib/test_django_rest_framework.py
3feee8
@@ -64,10 +64,9 @@ class TestMoneyField:
3feee8
             (NullMoneyFieldModel, "field", {"default_currency": "EUR", "allow_null": True}, None, None),
3feee8
             (NullMoneyFieldModel, "field", None, Money(10, "USD"), Money(10, "USD")),
3feee8
             (NullMoneyFieldModel, "field", {"default_currency": "EUR"}, Money(10, "USD"), Money(10, "USD")),
3feee8
-            (NullMoneyFieldModel, "field", {"default_currency": "EUR"}, 10, Money(10, "EUR")),
3feee8
+            (ModelWithVanillaMoneyField, "money", {"default_currency": "EUR"}, 10, Money(10, "EUR")),
e24198
             (ModelWithVanillaMoneyField, "money", None, Money(10, "USD"), Money(10, "USD")),
e24198
             (ModelWithVanillaMoneyField, "money", {"default_currency": "EUR"}, Money(10, "USD"), Money(10, "USD")),
e24198
-            (ModelWithVanillaMoneyField, "money", None, 10, Money(10, "XYZ")),
e24198
             (ModelWithVanillaMoneyField, "money", {"default_currency": "EUR"}, 10, Money(10, "EUR")),
e24198
         ),
e24198
     )
e24198
--- a/tests/settings.py
e24198
+++ b/tests/settings.py
e24198
@@ -1,8 +1,6 @@
e24198
 import warnings
e24198
-from decimal import ROUND_HALF_EVEN
e24198
 
e24198
 import moneyed
e24198
-from moneyed.localization import _FORMATTER, DEFAULT
e24198
 
e24198
 
e24198
 DATABASES = {"default": {"ENGINE": "django.db.backends.sqlite3", "NAME": ":memory:"}}
e24198
@@ -36,20 +34,6 @@ SECRET_KEY = "foobar"
e24198
 USE_L10N = True
e24198
 
e24198
 
e24198
-_FORMATTER.add_sign_definition("pl_PL", moneyed.PLN, suffix=" zł")
e24198
-_FORMATTER.add_sign_definition(DEFAULT, moneyed.PLN, suffix=" zł")
e24198
-_FORMATTER.add_formatting_definition(
e24198
-    "pl_PL",
e24198
-    group_size=3,
e24198
-    group_separator=" ",
e24198
-    decimal_point=",",
e24198
-    positive_sign="",
e24198
-    trailing_positive_sign="",
e24198
-    negative_sign="-",
e24198
-    trailing_negative_sign="",
e24198
-    rounding_method=ROUND_HALF_EVEN,
e24198
-)
e24198
-
e24198
 moneyed.add_currency("USDT", "000", "Tether", None)
e24198
 
e24198
 OPEN_EXCHANGE_RATES_APP_ID = "test"
e24198
--- a/tests/test_admin.py
e24198
+++ b/tests/test_admin.py
3feee8
@@ -14,26 +14,7 @@ INTEGER_FIELD = ModelWithVanillaMoneyFie
3feee8
 @pytest.mark.parametrize(
3feee8
     "value, expected",
3feee8
     (
e24198
-        (Money(10, "RUB"), "10.00 руб."),  # Issue 232
e24198
-        (Money(1234), "1,234.00 XYZ"),  # Issue 220
e24198
-        (Money(1000, "SAR"), "ر.س1,000.00"),  # Issue 196
e24198
-        (Money(1000, "PLN"), "1,000.00 zł"),  # Issue 102
e24198
-        (Money("3.33", "EUR"), "3.33 €"),  # Issue 90
e24198
-    ),
e24198
-)
e24198
-def test_display_for_field_with_legacy_formatting(legacy_formatting, settings, value, expected):
e24198
-    settings.USE_L10N = True
e24198
-    # This locale has no definitions in py-moneyed, so it will work for localized money representation.
e24198
-    settings.LANGUAGE_CODE = "cs"
e24198
-    settings.DECIMAL_PLACES_DISPLAY = {}
e24198
-    assert admin_utils.display_for_field(value, MONEY_FIELD, "") == expected
e24198
-
e24198
-
3feee8
-@pytest.mark.parametrize(
3feee8
-    "value, expected",
3feee8
-    (
e24198
         (Money(10, "RUB"), "10,00\xa0RUB"),  # Issue 232
e24198
-        (Money(1234), "1\xa0234,00\xa0XYZ"),  # Issue 220
e24198
         (Money(1000, "SAR"), "1\xa0000,00\xa0SAR"),  # Issue 196
e24198
         (Money(1000, "PLN"), "1\xa0000,00\xa0PLN"),  # Issue 102
e24198
         (Money("3.33", "EUR"), "3,33\xa0€"),  # Issue 90
e24198
--- a/tests/test_models.py
e24198
+++ b/tests/test_models.py
3feee8
@@ -60,8 +60,8 @@ class TestVanillaMoneyField:
e24198
     @pytest.mark.parametrize(
e24198
         "model_class, kwargs, expected",
e24198
         (
e24198
-            (ModelWithVanillaMoneyField, {"money": Money("100.0")}, Money("100.0")),
e24198
-            (ModelWithVanillaMoneyField, {"money": OldMoney("100.0")}, Money("100.0")),
e24198
+            (ModelWithVanillaMoneyField, {"money": Money("100.0", "USD")}, Money("100.0", "USD")),
e24198
+            (ModelWithVanillaMoneyField, {"money": OldMoney("100.0", "USD")}, Money("100.0", "USD")),
e24198
             (BaseModel, {}, Money(0, "USD")),
e24198
             (BaseModel, {"money": "111.2"}, Money("111.2", "USD")),
e24198
             (BaseModel, {"money": Money("123", "PLN")}, Money("123", "PLN")),
3feee8
@@ -116,7 +116,6 @@ class TestVanillaMoneyField:
e24198
     @pytest.mark.parametrize(
e24198
         "model_class, other_value",
e24198
         (
e24198
-            (ModelWithVanillaMoneyField, Money("100.0")),
e24198
             (BaseModel, Money(0, "USD")),
e24198
             (ModelWithDefaultAsMoney, Money("0.01", "RUB")),
e24198
             (ModelWithDefaultAsFloat, OldMoney("12.05", "PLN")),
3feee8
@@ -149,27 +148,35 @@ class TestVanillaMoneyField:
3feee8
             BaseModel.objects.create(money=value)
3feee8
 
e24198
     @pytest.mark.parametrize("money_class", (Money, OldMoney))
3feee8
-    @pytest.mark.parametrize("field_name", ("money", "second_money"))
3feee8
-    def test_save_new_value(self, field_name, money_class):
e24198
-        ModelWithVanillaMoneyField.objects.create(**{field_name: money_class("100.0")})
3feee8
+    def test_save_new_value_on_field_without_default(self, money_class):
3feee8
+        ModelWithVanillaMoneyField.objects.create(money=money_class("100.0", "DKK"))
e24198
 
e24198
         # Try setting the value directly
e24198
         retrieved = ModelWithVanillaMoneyField.objects.get()
3feee8
-        setattr(retrieved, field_name, Money(1, "DKK"))
3feee8
+        retrieved.money = Money(1, "DKK")
3feee8
         retrieved.save()
3feee8
         retrieved = ModelWithVanillaMoneyField.objects.get()
3feee8
+        assert retrieved.money == Money(1, "DKK")
3feee8
 
3feee8
-        assert getattr(retrieved, field_name) == Money(1, "DKK")
3feee8
+    def test_save_new_value_on_field_with_default(self):
3feee8
+        ModelWithDefaultAsMoney.objects.create()
3feee8
+
3feee8
+        # Try setting the value directly
3feee8
+        retrieved = ModelWithDefaultAsMoney.objects.get()
3feee8
+        retrieved.money = Money(1, "DKK")
3feee8
+        retrieved.save()
3feee8
+        retrieved = ModelWithDefaultAsMoney.objects.get()
3feee8
+        assert retrieved.money == Money(1, "DKK")
e24198
 
e24198
     def test_rounding(self):
e24198
-        money = Money("100.0623456781123219")
3feee8
+        money = Money("100.0623456781123219", "USD")
e24198
 
e24198
         instance = ModelWithVanillaMoneyField.objects.create(money=money)
e24198
         # TODO. Should instance.money be rounded too?
e24198
 
e24198
         retrieved = ModelWithVanillaMoneyField.objects.get(pk=instance.pk)
e24198
 
e24198
-        assert retrieved.money == Money("100.06")
3feee8
+        assert retrieved.money == Money("100.06", "USD")
e24198
 
e24198
     @pytest.fixture(params=[Money, OldMoney])
e24198
     def objects_setup(self, request):
3feee8
@@ -238,7 +245,7 @@ class TestVanillaMoneyField:
e24198
         assert ModelWithTwoMoneyFields.objects.filter(**kwargs).count() == expected
e24198
 
e24198
     def test_exact_match(self):
e24198
-        money = Money("100.0")
3feee8
+        money = Money("100.0", "USD")
e24198
 
e24198
         instance = ModelWithVanillaMoneyField.objects.create(money=money)
e24198
         retrieved = ModelWithVanillaMoneyField.objects.get(money=money)
3feee8
@@ -251,9 +258,9 @@ class TestVanillaMoneyField:
e24198
         ModelIssue300.objects.filter(money__created__gt=date)
e24198
 
e24198
     def test_range_search(self):
e24198
-        money = Money("3")
e24198
+        money = Money("3", "EUR")
e24198
 
e24198
-        instance = ModelWithVanillaMoneyField.objects.create(money=Money("100.0"))
e24198
+        instance = ModelWithVanillaMoneyField.objects.create(money=Money("100.0", "EUR"))
e24198
         retrieved = ModelWithVanillaMoneyField.objects.get(money__gt=money)
e24198
 
e24198
         assert instance.pk == retrieved.pk
0e12f2
@@ -302,12 +309,23 @@ class TestVanillaMoneyField:
3feee8
         instance = NullMoneyFieldModel.objects.create()
3feee8
         assert instance.field is None
3feee8
 
0e12f2
+    def test_raises_type_error_setting_currency_to_none_on_nullable_currency_field_while_having_amount(self):
0e12f2
+        with pytest.raises(ValueError, match=r"Missing currency value"):
0e12f2
+            NullMoneyFieldModel(field=10, field_currency=None)
0e12f2
+
3feee8
+    def test_currency_field_null_switch_not_triggered_from_default_currency(self):
3feee8
+        # We want a sane default behaviour and simply declaring a `MoneyField(...)`
3feee8
+        # without any default value args should create non nullable amount and currency
3feee8
+        # fields
3feee8
+        assert not ModelWithVanillaMoneyField._meta.get_field("money").null
3feee8
+        assert not ModelWithVanillaMoneyField._meta.get_field("money_currency").null
3feee8
+
3feee8
 
3feee8
 class TestGetOrCreate:
e24198
     @pytest.mark.parametrize(
e24198
         "model, field_name, kwargs, currency",
e24198
         (
e24198
-            (ModelWithVanillaMoneyField, "money", {"money_currency": "PLN"}, "PLN"),
3feee8
+            (ModelWithDefaultAsInt, "money", {"money_currency": "PLN"}, "PLN"),
3feee8
             (ModelWithVanillaMoneyField, "money", {"money": Money(0, "EUR")}, "EUR"),
3feee8
             (ModelWithVanillaMoneyField, "money", {"money": OldMoney(0, "EUR")}, "EUR"),
e24198
             (ModelWithSharedCurrency, "first", {"first": 10, "second": 15, "currency": "CZK"}, "CZK"),
0e12f2
@@ -381,9 +399,9 @@ class TestNullableCurrency:
0e12f2
         assert not ModelWithNullableCurrency.objects.exists()
0e12f2
 
0e12f2
     def test_fails_with_nullable_but_no_default(self):
0e12f2
-        with pytest.raises(IntegrityError) as exc:
0e12f2
+        match = r"NOT NULL constraint failed: testapp_modelwithtwomoneyfields.amount1"
0e12f2
+        with pytest.raises(IntegrityError, match=match):
0e12f2
             ModelWithTwoMoneyFields.objects.create()
0e12f2
-        assert str(exc.value) == "NOT NULL constraint failed: testapp_modelwithtwomoneyfields.amount1"
0e12f2
 
0e12f2
     def test_query_not_null(self):
0e12f2
         money = Money(100, "EUR")
0e12f2
@@ -527,9 +545,11 @@ class TestExpressions:
e24198
         assert ModelWithVanillaMoneyField.objects.get(integer=1).money == Money(0, "USD")
e24198
 
e24198
     def test_create_func(self):
e24198
-        instance = ModelWithVanillaMoneyField.objects.create(money=Func(Value(-10), function="ABS"))
3feee8
+        instance = ModelWithVanillaMoneyField.objects.create(
3feee8
+            money=Func(Value(-10), function="ABS"), money_currency="USD"
3feee8
+        )
e24198
         instance.refresh_from_db()
3feee8
-        assert instance.money.amount == 10
3feee8
+        assert instance.money == Money(10, "USD")
3feee8
 
3feee8
     @pytest.mark.parametrize(
3feee8
         "value, expected", ((None, None), (10, Money(10, "USD")), (Money(10, "EUR"), Money(10, "EUR")))
0e12f2
@@ -541,7 +561,7 @@ class TestExpressions:
e24198
 
3feee8
     def test_value_create_invalid(self):
3feee8
         with pytest.raises(ValidationError):
3feee8
-            ModelWithVanillaMoneyField.objects.create(money=Value("string"))
3feee8
+            ModelWithVanillaMoneyField.objects.create(money=Value("string"), money_currency="DKK")
3feee8
 
3feee8
     def test_expressions_for_non_money_fields(self):
3feee8
         instance = ModelWithVanillaMoneyField.objects.create(money=Money(1, "USD"), integer=0)
0e12f2
@@ -560,7 +580,7 @@ def test_find_models_related_to_money_mo
e24198
 def test_allow_expression_nodes_without_money():
e24198
     """Allow querying on expression nodes that are not Money"""
e24198
     desc = "hundred"
e24198
-    ModelWithNonMoneyField.objects.create(money=Money(100.0), desc=desc)
e24198
+    ModelWithNonMoneyField.objects.create(money=Money(100.0, "USD"), desc=desc)
e24198
     instance = ModelWithNonMoneyField.objects.filter(desc=F("desc")).get()
e24198
     assert instance.desc == desc
e24198
 
0e12f2
@@ -793,7 +813,7 @@ def test_mixer_blend():
3feee8
     except AttributeError:
3feee8
         pass  # mixer doesn't work with pypy
3feee8
     else:
e24198
-        instance = mixer.blend(ModelWithTwoMoneyFields)
3feee8
+        instance = mixer.blend(ModelWithTwoMoneyFields, amount1_currency="EUR", amount2_currency="USD")
3feee8
         assert isinstance(instance.amount1, Money)
3feee8
         assert isinstance(instance.amount2, Money)
3feee8
 
e24198
--- a/tests/test_money.py
e24198
+++ b/tests/test_money.py
3feee8
@@ -10,23 +10,19 @@ def test_repr():
e24198
 
e24198
 
3feee8
 def test_legacy_repr():
e24198
-    assert repr(Money("10.5", "USD", decimal_places_display=2)) == "Money('10.5', 'USD')"
3feee8
+    assert repr(Money("10.5", "USD")) == "Money('10.5', 'USD')"
3feee8
 
3feee8
 
e24198
 def test_html_safe():
e24198
     assert Money("10.5", "EUR").__html__() == "€10.50"
e24198
 
e24198
 
e24198
-def test_legacy_html_safe():
e24198
-    assert Money("10.5", "EUR", decimal_places_display=2).__html__() == "10.50\xa0€"
e24198
-
e24198
-
e24198
 def test_html_unsafe():
e24198
     class UnsafeMoney(Money):
e24198
         def __str__(self):
e24198
             return "<script>"
e24198
 
e24198
-    assert UnsafeMoney().__html__() == "<script>"
3feee8
+    assert UnsafeMoney(100, "USD").__html__() == "<script>"
e24198
 
e24198
 
e24198
 def test_default_mul():
3feee8
@@ -46,18 +42,6 @@ def test_reverse_truediv_fails():
3feee8
 @pytest.mark.parametrize(
3feee8
     "locale, expected",
3feee8
     (
e24198
-        ("pl", "PL_PL"),
e24198
-        ("pl_PL", "pl_PL"),
e24198
-    ),
e24198
-)
e24198
-def test_legacy_get_current_locale(locale, expected):
e24198
-    with override(locale):
e24198
-        assert get_current_locale(for_babel=False) == expected
e24198
-
e24198
-
3feee8
-@pytest.mark.parametrize(
3feee8
-    "locale, expected",
3feee8
-    (
3feee8
         ("pl", "pl"),
3feee8
         ("pl-pl", "pl_PL"),
3feee8
         ("sv", "sv"),
3feee8
@@ -82,17 +66,8 @@ def test_configurable_decimal_number():
e24198
     assert mny.decimal_places == 3
e24198
 
e24198
 
e24198
-def test_localize_decimal_places_default():
3feee8
-    # use default decimal display places from settings
3feee8
-    assert str(Money("10.543125", "USD")) == "$10.54"
3feee8
-
3feee8
-
e24198
-def test_localize_decimal_places_overwrite():
e24198
-    assert str(Money("10.543125", "USD", decimal_places_display=4)) == "$10.5431"
e24198
-
e24198
-
e24198
-def test_localize_decimal_places_both():
e24198
-    assert str(Money("10.543125", "USD", decimal_places=5, decimal_places_display=1)) == "$10.5"
3feee8
+def test_localize_defaults_to_currency_decimal_places():
e24198
+    assert str(Money("10.543125", "USD", decimal_places=5)) == "$10.54"
e24198
 
e24198
 
e24198
 def test_add_decimal_places():
3feee8
@@ -117,10 +92,10 @@ def test_add_decimal_places_zero():
e24198
         lambda a, d: a * 2,
e24198
         lambda a, d: 2 * a,
e24198
         lambda a, d: a / 5,
e24198
-        lambda a, d: a - Money("2", "USD", decimal_places=d, decimal_places_display=d),
e24198
-        lambda a, d: Money("2", "USD", decimal_places=d, decimal_places_display=d) - a,
e24198
-        lambda a, d: a + Money("2", "USD", decimal_places=d, decimal_places_display=d),
e24198
-        lambda a, d: Money("2", "USD", decimal_places=d, decimal_places_display=d) + a,
e24198
+        lambda a, d: a - Money("2", "USD", decimal_places=d),
e24198
+        lambda a, d: Money("2", "USD", decimal_places=d) - a,
e24198
+        lambda a, d: a + Money("2", "USD", decimal_places=d),
e24198
+        lambda a, d: Money("2", "USD", decimal_places=d) + a,
e24198
         lambda a, d: -a,
e24198
         lambda a, d: +a,
e24198
         lambda a, d: abs(a),
3feee8
@@ -131,19 +106,9 @@ def test_add_decimal_places_zero():
e24198
 )
e24198
 def test_keep_decimal_places(operation, decimal_places):
e24198
     # Arithmetic operations should keep the `decimal_places` value
e24198
-    amount = Money("1.0000", "USD", decimal_places=decimal_places, decimal_places_display=decimal_places)
e24198
+    amount = Money("1.0000", "USD", decimal_places=decimal_places)
e24198
     new = operation(amount, decimal_places)
e24198
     assert new.decimal_places == decimal_places
e24198
-    assert new.decimal_places_display == decimal_places
e24198
-
e24198
-
e24198
-def test_decimal_places_display_overwrite():
e24198
-    number = Money("1.23456789", "USD")
e24198
-    assert str(number) == "$1.23"
e24198
-    number.decimal_places_display = 5
e24198
-    assert str(number) == "$1.23457"
e24198
-    number.decimal_places_display = None
e24198
-    assert str(number) == "$1.23"
e24198
 
e24198
 
e24198
 def test_sub_negative():
3feee8
@@ -177,35 +142,28 @@ def test_sub_negative():
e24198
     ],
e24198
 )
3feee8
 def test_proper_copy_of_attributes(decimal_places_display, decimal_places):
e24198
-    one = Money(1, "EUR", decimal_places_display=decimal_places_display)
3feee8
+    one = Money(1, "EUR")
3feee8
 
e24198
-    assert one._decimal_places_display is decimal_places_display
3feee8
     assert one.decimal_places == 2, "default value"
3feee8
 
e24198
     two = Money(2, "EUR", decimal_places=decimal_places)
e24198
 
e24198
-    assert two._decimal_places_display is None, "default value"
e24198
     assert two.decimal_places == decimal_places
e24198
 
3feee8
     result = Money(3, "EUR")
3feee8
     one._copy_attributes(two, result)
3feee8
 
e24198
-    assert result._decimal_places_display == decimal_places_display
3feee8
     assert result.decimal_places == max(2, decimal_places) if decimal_places is not None else 2
3feee8
 
3feee8
     result = Money(0, "EUR")
e24198
-    one._copy_attributes(Money(1, "EUR", decimal_places_display=3), result)
e24198
-
e24198
-    assert result._decimal_places_display == max(3, decimal_places_display) if decimal_places_display is not None else 3
3feee8
+    one._copy_attributes(Money(1, "EUR"), result)
3feee8
 
3feee8
     result = Money(0, "EUR")
3feee8
     one._copy_attributes(1, result)
3feee8
 
e24198
-    assert result._decimal_places_display == decimal_places_display
3feee8
     assert result.decimal_places == 2
3feee8
 
e24198
     result = Money(0, "EUR")
e24198
     two._copy_attributes(1, result)
e24198
 
e24198
-    assert result._decimal_places_display is None
e24198
     assert result.decimal_places == decimal_places if decimal_places else 2
e24198
--- a/tests/test_tags.py
e24198
+++ b/tests/test_tags.py
3feee8
@@ -56,41 +56,6 @@ def assert_template(string, result, cont
3feee8
 @pytest.mark.parametrize(
3feee8
     "string, result, context",
3feee8
     (
e24198
-        ('{% load djmoney %}{% money_localize "2.5" "PLN" as NEW_M %}{{NEW_M}}', "2,50 zł", {}),
e24198
-        ('{% load djmoney %}{% money_localize "2.5" "PLN" %}', "2,50 zł", {}),
e24198
-        ("{% load djmoney %}{% money_localize amount currency %}", "2,60 zł", {"amount": 2.6, "currency": "PLN"}),
e24198
-        ("{% load djmoney %}{% money_localize money as NEW_M %}{{NEW_M}}", "2,30 zł", {"money": Money(2.3, "PLN")}),
e24198
-        ("{% load djmoney %}{% money_localize money off as NEW_M %}{{NEW_M}}", "2.30 zł", {"money": Money(2.3, "PLN")}),
e24198
-        ("{% load djmoney %}{% money_localize money off as NEW_M %}{{NEW_M}}", "0.00 zł", {"money": Money(0, "PLN")}),
e24198
-        (
e24198
-            # with a tag template "money_localize"
e24198
-            "{% load djmoney %}{% money_localize money %}",
e24198
-            "2,30 zł",
e24198
-            {"money": Money(2.3, "PLN")},
e24198
-        ),
e24198
-        (
e24198
-            # without a tag template "money_localize"
e24198
-            "{{ money }}",
e24198
-            "2,30 zł",
e24198
-            {"money": Money(2.3, "PLN")},
e24198
-        ),
e24198
-        ("{% load djmoney %}{% money_localize money off %}", "2.30 zł", {"money": Money(2.3, "PLN")}),
e24198
-        ("{% load djmoney %}{% money_localize money on %}", "2,30 zł", {"money": Money(2.3, "PLN")}),
e24198
-        (
e24198
-            # in django 2.0 we fail inside the for loop
e24198
-            '{% load djmoney %}{% for i in "xxx" %}{% money_localize money %} {% endfor %}',
e24198
-            "2,30 zł 2,30 zł 2,30 zł ",
e24198
-            {"money": Money(2.3, "PLN"), "test": "test"},
e24198
-        ),
e24198
-    ),
e24198
-)
e24198
-def test_tag_with_legacy_formatting(legacy_formatting, string, result, context):
e24198
-    assert_template(string, result, context)
e24198
-
e24198
-
3feee8
-@pytest.mark.parametrize(
3feee8
-    "string, result, context",
3feee8
-    (
3feee8
         ('{% load djmoney %}{% money_localize "2.5" "PLN" as NEW_M %}{{NEW_M}}', "2,50\xa0zł", {}),
3feee8
         ('{% load djmoney %}{% money_localize "2.5" "PLN" %}', "2,50\xa0zł", {}),
3feee8
         ("{% load djmoney %}{% money_localize amount currency %}", "2,60\xa0zł", {"amount": 2.6, "currency": "PLN"}),
e24198
--- a/tests/testapp/models.py
e24198
+++ b/tests/testapp/models.py
3feee8
@@ -24,7 +24,7 @@ else:
e24198
 
e24198
 
e24198
 class ModelWithVanillaMoneyField(models.Model):
e24198
-    money = MoneyField(max_digits=10, decimal_places=2, default=0.0)
e24198
+    money = MoneyField(max_digits=10, decimal_places=2)
e24198
     second_money = MoneyField(max_digits=10, decimal_places=2, default=0.0, default_currency="EUR")
e24198
     integer = models.IntegerField(default=0)
e24198