From: Christian Heller Date: Tue, 5 Dec 2023 02:03:57 +0000 (+0100) Subject: Improve accounting scripts. X-Git-Url: https://plomlompom.com/repos/%7B%7Bdb.prefix%7D%7D/task?a=commitdiff_plain;h=3faab835bd9d842cc0a529ba33007b3f85839e12;p=misc Improve accounting scripts. --- diff --git a/ledger.py b/ledger.py index 817def6..cd38b82 100755 --- a/ledger.py +++ b/ledger.py @@ -65,6 +65,9 @@ add_structured_html = """ + + +
@@ -715,10 +718,13 @@ class LedgerDB(PlomDB): lines += [f'Assets {amount:.2f} {currency}'] except PlomException: pass - if 'add_taxes' in postvars.keys(): + elif 'add_taxes' in postvars.keys(): lines += self.add_taxes(lines, finish=False) elif 'add_taxes2' in postvars.keys(): lines += self.add_taxes(lines, finish=True) + elif 'replace' in postvars.keys(): + for i, line in enumerate(lines): + lines[i] = line.replace(postvars['replace_from'][0], postvars['replace_to'][0]) return lines, add_empty_line diff --git a/todo.py b/todo.py index 08fb8b8..8c7029c 100644 --- a/todo.py +++ b/todo.py @@ -23,7 +23,7 @@ forbidden tags: {% for t_tag in db.t_tags | sort %} {% endfor %} - + {% for uuid, t in db.tasks.items() | sort(attribute='1.title', reverse=True) %} {% if t.visible %} @@ -33,7 +33,7 @@ forbidden tags: {% for t_tag in db.t_tags | sort %} - + {% endif %} {% endfor %} @@ -99,6 +99,14 @@ class Task: def title(self): return self._last_of_history(self.title_history, '') + def title_at(self, queried_date): + ret = self.title_history[sorted(self.title_history.keys())[0]] + for date_key, title in self.title_history.items(): + if date_key > f'{queried_date} 23:59:59': + break + ret = title + return ret + def set_tags(self, tags): self._set_with_history(self.tags_history, set(tags)) @@ -130,7 +138,7 @@ class Day: @property def todos_sum(self): s = 0 - for todo in [todo for todo in self.todos.values() if (todo.done or todo.day_weight)]: + for todo in [todo for todo in self.todos.values() if todo.done]: s += todo.weight return s @@ -143,16 +151,16 @@ class Day: class Todo: - def __init__(self, done=False, day_weight=None): + def __init__(self, done=False, weight=None): self.done = done - self.day_weight = day_weight + self.weight = weight @classmethod def from_dict(cls, d): - return cls(d['done'], d['day_weight']) + return cls(d['done'], d['weight']) def to_dict(self): - return {'done': self.done, 'day_weight': self.day_weight} + return {'done': self.done, 'weight': self.weight} class TodoDB(PlomDB): @@ -198,6 +206,14 @@ class TodoDB(PlomDB): def write(self): self.write_text_to_db(json.dumps(self.to_dict())) + def save_today(self): + if self.today_date in self.old_days.keys(): + raise PlomException('cannot use same date twice') + for task_uuid, todo in [(task_uuid, todo) for task_uuid, todo in self.today.todos.items() + if not todo.weight]: + todo.weight = self.tasks[task_uuid].default_weight + self.old_days[self.today_date] = self.today + def reset_today(self, date=None): if date: self.today_date = date @@ -263,8 +279,8 @@ class TodoHandler(PlomHandler): for i, uuid in enumerate(postvars['t_uuid']): if uuid in postvars['do_today']: done = 'done' in postvars and uuid in postvars['done'] - day_weight = float(postvars['day_weight'][i]) if postvars['day_weight'][i] else None - db.today.todos[uuid] = Todo(done, day_weight) + weight = float(postvars['weight'][i]) if postvars['weight'][i] else None + db.today.todos[uuid] = Todo(done, weight) db.today_date = postvars['today_date'][0] db.today.comment = postvars['comment'][0] switch_edited_day = None @@ -273,9 +289,7 @@ class TodoHandler(PlomHandler): switch_edited_day = date break if 'archive_today' in postvars.keys() or switch_edited_day: - if db.today_date in db.old_days.keys(): - raise PlomException('cannot use same date twice') - db.old_days[db.today_date] = db.today + db.save_today() if switch_edited_day: db.reset_today(date) else: @@ -300,12 +314,9 @@ class TodoHandler(PlomHandler): db = TodoDB(t_filter_and, t_filter_not) for i in range(10): db.tasks[f'new{i}'] = Task() - for task_uuid, todo in db.today.todos.items(): - todo.weight = todo.day_weight if todo.day_weight else db.tasks[task_uuid].default_weight for date, day in db.old_days.items(): for task_uuid, todo in day.todos.items(): - todo.title = db.tasks[task_uuid].title - todo.weight = todo.day_weight if todo.day_weight else db.tasks[task_uuid].default_weight + todo.title = db.tasks[task_uuid].title_at(date) page = Template(tmpl).render(db=db) self.send_HTML(page)
datearchive?{{ db.today.todos_sum|round(2) }}comment:
weighttitletagstoday?done?day weight
default
weight
titletagstoday?done?day
weight