Skip to content

Commit

Permalink
fix: Subtracting Money from moneyed.Money
Browse files Browse the repository at this point in the history
  • Loading branch information
Stranger6667 committed Jan 10, 2021
1 parent bb222ed commit 9ac8d8b
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
1 change: 0 additions & 1 deletion djmoney/money.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,6 @@ def __round__(self, n=None):
# we overwrite the 'targets' so the wrong synonyms are called
# Example: we overwrite __add__; __radd__ calls __add__ on DefaultMoney...
__radd__ = __add__
__rsub__ = __sub__
__rmul__ = __mul__


Expand Down
2 changes: 2 additions & 0 deletions docs/changes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ Changelog
**Fixed**

- Pin ``pymoneyed<1.0`` as it changed the ``repr`` output of the ``Money`` class.
- Subtracting ``Money`` from ``moneyed.Money``. Regression, introduced in ``1.2``. `#593`_

`1.2.2`_ - 2020-12-29
---------------------
Expand Down Expand Up @@ -694,6 +695,7 @@ wrapping with ``money_manager``.
.. _0.3: https://github.com/django-money/django-money/compare/0.2...0.3
.. _0.2: https://github.com/django-money/django-money/compare/0.2...a6d90348085332a393abb40b86b5dd9505489b04

.. _#593: https://github.com/django-money/django-money/issues/593
.. _#586: https://github.com/django-money/django-money/issues/586
.. _#585: https://github.com/django-money/django-money/pull/585
.. _#583: https://github.com/django-money/django-money/issues/583
Expand Down
11 changes: 10 additions & 1 deletion tests/test_money.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import pytest

from djmoney.money import Money, get_current_locale
from djmoney.money import DefaultMoney, Money, get_current_locale


def test_repr():
Expand Down Expand Up @@ -114,3 +114,12 @@ def test_decimal_places_display_overwrite():
assert str(number) == "$1.23457"
number.decimal_places_display = None
assert str(number) == "$1.23"


def test_sub_negative():
# See GH-593
total = DefaultMoney(0, "EUR")
bills = (Money(8, "EUR"), Money(25, "EUR"))
for bill in bills:
total -= bill
assert total == Money(-33, "EUR")

0 comments on commit 9ac8d8b

Please sign in to comment.