コード例 #1
0
ファイル: money.py プロジェクト: vitorqb/pacs
 def __eq__(self, other) -> bool:
     if not isinstance(other, Money):
         return False
     return (
         self.currency == other.currency and
         decimals_equal(self.quantity, other.quantity)
     )
コード例 #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')
コード例 #3
0
ファイル: test_common.py プロジェクト: vitorqb/pacs
 def test_decimals_equal_not_equal(self):
     one = Decimal('1.128')
     two = one - Decimal('0.003')
     assert decimals_equal(one, two) is False
コード例 #4
0
ファイル: test_common.py プロジェクト: vitorqb/pacs
 def test_decimals_equal_equal(self):
     one = Decimal('123.4567')
     two = one + Decimal('0.0001')
     assert decimals_equal(one, two) is True
コード例 #5
0
ファイル: test_common.py プロジェクト: vitorqb/pacs
 def test_decimals_equal_not_equal_limit(self):
     one = Decimal('123.005')
     two = one + Decimal('0.001')
     assert decimals_equal(one, two) is False