diff --git a/pyproject.toml b/pyproject.toml index 7797fc0..dd68aa2 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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" }, ] diff --git a/setup.py b/setup.py index c32753f..a577241 100644 --- a/setup.py +++ b/setup.py @@ -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=[], diff --git a/zakat/zakat_tracker.py b/zakat/zakat_tracker.py index b49d046..36f672b 100644 --- a/zakat/zakat_tracker.py +++ b/zakat/zakat_tracker.py @@ -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: @@ -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: """ @@ -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 @@ -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 @@ -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