Skip to content

Commit

Permalink
التحويل للحساب نفسه عملية محظورة
Browse files Browse the repository at this point in the history
  • Loading branch information
vzool committed Jul 7, 2024
1 parent e6c630c commit e05ea87
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ tmp
*.json
*.pyc
__pycache__
.pytest_cache
.pytest_cache
*.DS_Store
22 changes: 21 additions & 1 deletion zakat/zakat_tracker.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
from math import floor
from enum import Enum, auto
from sys import version_info
from decimal import Decimal


class Action(Enum):
Expand All @@ -83,6 +84,8 @@ class JSONEncoder(json.JSONEncoder):
def default(self, obj):
if isinstance(obj, Action) or isinstance(obj, MathOperation):
return obj.name # Serialize as the enum member's name
elif isinstance(obj, Decimal):
return float(obj)
return super().default(obj)


Expand Down Expand Up @@ -141,6 +144,11 @@ class ZakatTracker:
- desc (str): The description of the transaction.
- file (dict): A dictionary storing file references associated with the transaction.
- zakatable (bool): Indicates whether the account is subject to Zakat.
- exchange (dict):
- account (dict):
- {timestamps} (dict):
- rate (float): Exchange rate when compared to local currency.
- description (str): The description of the exchange rate.
- history (dict):
- {timestamp} (list): A list of dictionaries storing the history of actions performed.
- {action_dict} (dict):
Expand All @@ -161,7 +169,7 @@ class ZakatTracker:
ZakatCut = lambda x: 0.025 * x # Zakat Cut in one Lunar Year
TimeCycle = lambda days=355: int(60 * 60 * 24 * days * 1e9) # Lunar Year in nanoseconds
Nisab = lambda x: 595 * x # Silver Price in Local currency value
Version = lambda: '0.2.5'
Version = lambda: '0.2.6'

def __init__(self, db_path: str = "zakat.pickle", history_mode: bool = True):
"""
Expand Down Expand Up @@ -970,9 +978,12 @@ def transfer(self, amount: int, from_account: str, to_account: str, desc: str =
list[int]: A list of timestamps corresponding to the transactions made during the transfer.
Raises:
ValueError: Transfer to the same account is forbidden.
ValueError: The box transaction happened again in the same nanosecond time.
ValueError: The log transaction happened again in the same nanosecond time.
"""
if from_account == to_account:
raise ValueError(f'Transfer to the same account is forbidden. {to_account}')
if amount <= 0:
return []
if created is None:
Expand Down Expand Up @@ -1710,6 +1721,15 @@ def test(self, debug: bool = False) -> bool:

self.reset()

# Same account transfer
for x in [1, 'a', True, 1.8, None]:
failed = False
try:
self.transfer(1, x, x, 'same-account', debug= debug)
except:
failed = True
assert failed is True

# Always preserve box age during transfer

series: list[tuple] = [
Expand Down

0 comments on commit e05ea87

Please sign in to comment.