usawa

Signed, immutable accounting.
Log | Files | Refs | Submodules | LICENSE

commit 4331567668f94667fd7c4541bad5563c02cf8240
parent 4430dab62f242fc33f1702faee954f2fa13c4454
Author: Carlosokumu <carlosokumu254@gmail.com>
Date:   Mon, 13 Jul 2026 23:25:33 +0300

access unitindex via the ctx

Diffstat:
Mdummy/usawa/storage/entry_mapper.py | 15+++++----------
Mdummy/usawa/storage/ledger_repository.py | 3++-
2 files changed, 7 insertions(+), 11 deletions(-)

diff --git a/dummy/usawa/storage/entry_mapper.py b/dummy/usawa/storage/entry_mapper.py @@ -4,7 +4,6 @@ from datetime import datetime, date from usawa.entry import Entry, EntryPart from usawa.ledger import Ledger from usawa.account import Account -from usawa.unit import UnitIndex from ..gui.core.models import LedgerEntry from usawa import Entry, EntryPart @@ -15,7 +14,7 @@ class EntryMapper: """Maps between domain model (LedgerEntry) and storage model (Entry)""" @staticmethod - def to_entry(domain: LedgerEntry, ledger): + def to_entry(ctx, domain: LedgerEntry, ledger): if domain.tx_date is None: raise ValueError("Transaction date is required for storage") @@ -23,8 +22,6 @@ class EntryMapper: if isinstance(tx_date, date) and not isinstance(tx_date, datetime): tx_date = datetime.combine(tx_date, datetime.min.time()) - unitindex = UnitIndex(base=domain.dest_unit) - parent = ledger.current() if ledger else None ref = domain.transaction_ref if domain.transaction_ref else None @@ -34,15 +31,13 @@ class EntryMapper: parent=parent, description=domain.description or "", ref=ref, - unitindex=UnitIndex(domain.dest_unit), + unitindex=ctx.uidx, ) - source_amount = unitindex.from_floatstring(unitindex.base, str(domain.amount)) + source_amount = ctx.uidx.from_floatstring(ctx.uidx.base, str(domain.amount)) dest_amount = -source_amount - account = Account( - unitindex.base, domain.source_type.lower(), domain.source_path - ) + account = Account(ctx.uidx.base, domain.source_type.lower(), domain.source_path) source_part = EntryPart( account, source_amount, @@ -50,7 +45,7 @@ class EntryMapper: ) entry.add_part(source_part) - account = Account(unitindex.base, domain.dest_type.lower(), domain.dest_path) + account = Account(ctx.uidx.base, domain.dest_type.lower(), domain.dest_path) dest_part = EntryPart( account, dest_amount, diff --git a/dummy/usawa/storage/ledger_repository.py b/dummy/usawa/storage/ledger_repository.py @@ -25,6 +25,7 @@ class LedgerRepository: self, ctx, ): + self.ctx = ctx self.resolver = ctx.resolver self.wallet = ctx.wallet self.store = ctx.store @@ -47,7 +48,7 @@ class LedgerRepository: try: store, ledger, wallet = self._init_store(write=True) - entry = EntryMapper.to_entry(domain_entry, ledger=ledger) + entry = EntryMapper.to_entry(self.ctx, domain_entry, ledger=ledger) entry.sign(wallet) for attachment in domain_entry.attachments: