Esempio n. 1
0
 def __eq__(self, other) -> bool:
     if not isinstance(other, Money):
         return False
     return (
         self.currency == other.currency and
         decimals_equal(self.quantity, other.quantity)
     )
Esempio n. 2
0
    def validate(self, movement_specs: List[MovementSpec]) -> None:
        currency_set = set(x.money.currency for x in movement_specs)
        account_set = set(x.account for x in movement_specs)
        account_currency_pair_set = set(
            (x.money.currency, x.account) for x in movement_specs)

        if len(movement_specs) < 2:
            self.fail("TWO_OR_MORE_MOVEMENTS")

        if len(account_set) == 1:
            self.fail("SINGLE_ACCOUNT")

        if len(currency_set) == 1:
            value = sum(x.money.quantity for x in movement_specs)
            if not decimals_equal(value, Decimal(0)):
                self.fail("UNBALANCED_SINGLE_CURRENCY")

        # Each pair (account, currency) should only appear once
        if len(account_currency_pair_set) < len(movement_specs):
            self.fail('REPEATED_CURRENCY_ACCOUNT_PAIR')
Esempio n. 3
0
 def test_decimals_equal_not_equal(self):
     one = Decimal('1.128')
     two = one - Decimal('0.003')
     assert decimals_equal(one, two) is False
Esempio n. 4
0
 def test_decimals_equal_equal(self):
     one = Decimal('123.4567')
     two = one + Decimal('0.0001')
     assert decimals_equal(one, two) is True
Esempio n. 5
0
 def test_decimals_equal_not_equal_limit(self):
     one = Decimal('123.005')
     two = one + Decimal('0.001')
     assert decimals_equal(one, two) is False