Skip to content

Commit

Permalink
إضافة دالة جديدة لمسح سجلات الاسترجاع الفارغة، وتقليل مخرجات أسعار الصرف
Browse files Browse the repository at this point in the history
  • Loading branch information
vzool committed Jul 17, 2024
1 parent 1a5ac4d commit 1341bde
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 6 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "zakat"
version = "0.2.74"
version = "0.2.75"
authors = [
{ name="Abdelaziz Elrashed Elshaikh Mohamed", email="aeemh.sdn@gmail.com" },
]
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
setup(
name='zakat',
packages=find_packages(include=['zakat']),
version='0.2.74',
version='0.2.75',
description='A Python Library for Islamic Financial Management.',
author='Abdelaziz Elrashed Elshaikh Mohamed',
install_requires=[],
Expand Down
33 changes: 29 additions & 4 deletions zakat/zakat_tracker.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ def Version():
Returns:
str: The current version of the software.
"""
return '0.2.74'
return '0.2.75'

@staticmethod
def ZakatCut(x: float) -> float:
Expand Down Expand Up @@ -335,6 +335,30 @@ def time_to_datetime(ordinal_ns: int) -> datetime:
t = datetime.timedelta(seconds=ns_in_day // 10 ** 9)
return datetime.datetime.combine(d, datetime.time()) + t

def clean_history(self, lock: int | None = None) -> int:
"""
Cleans up the history of actions performed on the ZakatTracker instance.
Parameters:
lock (int, optional): The lock ID is used to clean up the empty history.
If not provided, it cleans up the empty history records for all locks.
Returns:
int: The number of locks cleaned up.
"""
count = 0
if lock in self._vault['history']:
if len(self._vault['history'][lock]) <= 0:
count += 1
del self._vault['history'][lock]
return count
self.free(self.lock())
for lock in self._vault['history']:
if len(self._vault['history'][lock]) <= 0:
count += 1
del self._vault['history'][lock]
return count

def _step(self, action: Action = None, account=None, ref: int = None, file: int = None, value: float = None,
key: str = None, math_operation: MathOperation = None) -> int:
"""
Expand Down Expand Up @@ -460,6 +484,7 @@ def free(self, lock: int, auto_save: bool = True) -> bool:
"""
if lock == self._vault['lock']:
self._vault['lock'] = None
self.clean_history(lock)
if auto_save:
return self.save(self.path())
return True
Expand Down Expand Up @@ -1214,6 +1239,8 @@ def check(self, silver_gram_price: float, nisab: float = None, debug: bool = Fal
below_nisab = 0
brief = [0, 0, 0]
valid = False
if debug:
print('exchanges', self.exchanges())
for x in self._vault['account']:
if not self.zakatable(x):
continue
Expand All @@ -1227,9 +1254,7 @@ def check(self, silver_gram_price: float, nisab: float = None, debug: bool = Fal
if rest <= 0:
continue
exchange = self.exchange(x, created=self.time())
if debug:
print('exchanges', self.exchanges())
rest = ZakatTracker.exchange_calc(rest, exchange['rate'], 1)
rest = ZakatTracker.exchange_calc(rest, float(exchange['rate']), 1)
brief[0] += rest
index = limit + i - 1
epoch = (now - j) / cycle
Expand Down

0 comments on commit 1341bde

Please sign in to comment.