From 24cac529254196db30ca6c8f1ab65b202b77cf83 Mon Sep 17 00:00:00 2001 From: Abdelaziz Elrashed Date: Sat, 3 Aug 2024 17:30:26 +0300 Subject: [PATCH] =?UTF-8?q?=D8=AA=D8=AD=D8=AF=D9=8A=D8=AB=20=D8=A7=D9=84?= =?UTF-8?q?=D9=82=D9=8A=D9=88=D8=AF=20=D8=A7=D9=84=D9=8A=D9=88=D9=85=D9=8A?= =?UTF-8?q?=D8=A9=20=D8=A8=D8=AD=D9=8A=D8=AB=20=D8=AA=D8=AD=D8=AA=D9=88?= =?UTF-8?q?=D9=8A=20=D8=AD=D8=A7=D9=84=D8=A9=20=D8=A7=D9=84=D8=AA=D8=AD?= =?UTF-8?q?=D9=88=D9=8A=D9=84=20=D9=81=D9=8A=D9=85=D8=A7=20=D8=A8=D9=8A?= =?UTF-8?q?=D9=86=20=D8=A7=D9=84=D8=AD=D8=B3=D8=A7=D8=A8=D8=A7=D8=AA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pyproject.toml | 2 +- setup.py | 2 +- zakat/zakat_tracker.py | 34 ++++++++++++++++++++++++---------- 3 files changed, 26 insertions(+), 12 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 40e1f81..0ccf2ac 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = 'zakat' -version = '0.2.89' +version = '0.2.9' authors = [ { name='Abdelaziz Elrashed Elshaikh Mohamed', email='aeemh.sdn@gmail.com' }, ] diff --git a/setup.py b/setup.py index 21a255b..1c68712 100644 --- a/setup.py +++ b/setup.py @@ -2,7 +2,7 @@ setup( name='zakat', - version='0.2.89', + version='0.2.9', description='A Python Library for Islamic Financial Management.', author='Abdelaziz Elrashed Elshaikh Mohamed', author_email='aeemh.sdn@gmail.com', diff --git a/zakat/zakat_tracker.py b/zakat/zakat_tracker.py index a24ed78..d289440 100644 --- a/zakat/zakat_tracker.py +++ b/zakat/zakat_tracker.py @@ -201,7 +201,7 @@ def Version() -> str: Returns: str: The current version of the software. """ - return '0.2.89' + return '0.2.9' @staticmethod def ZakatCut(x: float) -> float: @@ -1056,6 +1056,8 @@ def _log(self, value: float, desc: str = '', account: str = 1, created: int = No desc (str): The description of the transaction. account (str): The account to log the transaction into. Default is '1'. created (int): The timestamp of the transaction. If not provided, it will be generated. + ref (int): The reference of the object. + debug (bool): Whether to print debug information. Default is False. Returns: int: The timestamp of the logged transaction. @@ -1100,6 +1102,7 @@ def exchange(self, account, created: int = None, rate: float = None, description - created (int): The timestamp of the exchange rate. If not provided, the current timestamp will be used. - rate (float): The exchange rate to be recorded. If not provided, the method will retrieve the latest exchange rate. - description (str): A description of the exchange rate. + - debug (bool): Whether to print debug information. Default is False. Returns: - dict: A dictionary containing the latest exchange rate and its description. If no exchange rate is found, @@ -1215,7 +1218,7 @@ def logs(self, account) -> dict: return self._vault['account'][account]['log'] return {} - def daily_logs(self): + def daily_logs(self, debug: bool = False): """ Retrieve the daily logs (transactions) from all accounts. @@ -1224,7 +1227,7 @@ def daily_logs(self): and the values are dictionaries containing the total value and the logs for that group. Parameters: - None + debug (bool): Whether to print debug information. Default is False. Returns: dict: A dictionary containing the daily logs. @@ -1237,6 +1240,7 @@ def daily_logs(self): { 1632057600: { 'total': 151, + 'transfer': False, 'rows': [ {'value': 51, 'account': 'account1', 'file': {}, 'ref': 1690977015000000000, 'desc': 'desc'}, {'value': 100, 'account': 'account2', 'file': {}, 'ref': 1690977015000000000, 'desc': 'desc'} @@ -1244,15 +1248,18 @@ def daily_logs(self): } } """ - x = {} + logs = {} for account in self.accounts(): - logs = {} for k, v in self.logs(account).items(): + v['time'] = k v['account'] = account - logs[k] = v - x.update(logs) + if k not in logs: + logs[k] = [] + logs[k].append(v) + if debug: + print('logs', logs) y = {} - for i in sorted(x, reverse=True): + for i in sorted(logs, reverse=True): dt = self.time_to_datetime(i) group = self.day_to_time(dt.day, dt.month, dt.year) if group not in y: @@ -1260,8 +1267,15 @@ def daily_logs(self): 'total': 0, 'rows': [], } - y[group]['total'] += x[i]['value'] - y[group]['rows'].append(x[i]) + y[group]['transfer'] = len(logs[i]) > 1 + if debug: + print('logs[i]', logs[i]) + for z in logs[i]: + print('z', z) + y[group]['total'] += z['value'] + y[group]['rows'].append(z) + if debug: + print('y', y) return y def add_file(self, account: str, ref: int, path: str) -> int: