commit f2bd67a16c66b2be1865101ca8a3084abd06f478
parent 4267e8de79fccf33592c5237bc33574bf1f432d6
Author: Carlosokumu <carlosokumu254@gmail.com>
Date: Tue, 24 Feb 2026 19:29:44 +0300
add missing fields
Diffstat:
1 file changed, 36 insertions(+), 59 deletions(-)
diff --git a/dummy/usawa/storage/entry_mapper.py b/dummy/usawa/storage/entry_mapper.py
@@ -41,8 +41,9 @@ class EntryMapper:
parent = ledger.current() if ledger else None
ref = domain.transaction_ref if domain.transaction_ref else None
+
entry = Entry(
- serial= ledger.peek(),
+ serial= ledger.serial,
tx_date=tx_date,
parent=parent,
description=domain.description or "",
@@ -50,87 +51,65 @@ class EntryMapper:
unitindex = UnitIndex('BTC')
)
- source_amount = domain.amount
- source_part = EntryPart(
- "BTC",
- domain.source_type.lower(),
- domain.source_path,
- source_amount,
- debit=True
- )
+
+ uidx = UnitIndex('BTC')
+ source_amount = uidx.from_floatstring('BTC', str(domain.amount))
+ dest_amount = -source_amount
+
+ source_part = EntryPart("BTC", domain.source_type.lower(), domain.source_path, source_amount, debit=True)
entry.add_part(source_part, debit=True)
-
-
- dest_amount = -domain.amount
- dest_part = EntryPart(
- "BTC",
- domain.dest_type.lower(),
- domain.dest_path,
- dest_amount,
- debit=False
- )
+
+ dest_part = EntryPart("BTC", domain.dest_type.lower(), domain.dest_path, dest_amount, debit=False)
entry.add_part(dest_part, debit=False)
- logg.debug(f"Mapped entry, serial: {entry.serial} parent: {entry.parent}")
return entry
+
@staticmethod
def to_domain_entry(storage_entry) -> LedgerEntry:
"""
Convert Entry (storage) to LedgerEntry (domain)
-
- :param storage_entry: Storage model entry
- :type storage_entry: Entry
- :return: Domain model entry
- :rtype: LedgerEntry
"""
-
- # Extract debit (source) information
+
source_unit = ""
source_type = ""
source_path = ""
amount = 0.0
-
+
if storage_entry.debit:
debit_part = storage_entry.debit[0]
- source_unit = debit_part.unit
- source_type = debit_part.category
- source_path = debit_part.account
- amount = abs(float(debit_part.value))
-
- # Extract credit (destination) information
+
+ source_unit = getattr(debit_part, "unit", "")
+ source_type = getattr(debit_part, "category", "")
+ source_path = getattr(debit_part, "account", "")
+ amount = abs(float(getattr(debit_part, "value", 0.0)))
+
dest_unit = ""
dest_type = ""
dest_path = ""
-
+
if storage_entry.credit:
credit_part = storage_entry.credit[0]
- dest_unit = credit_part.unit
- dest_type = credit_part.category
- dest_path = credit_part.account
-
- # Convert parent digest to hex string if bytes
- parent_digest = None
- if storage_entry.parent:
- if isinstance(storage_entry.parent, bytes):
- parent_digest = storage_entry.parent.hex()
- else:
- parent_digest = str(storage_entry.parent)
-
+
+ dest_unit = getattr(credit_part, "unit", "")
+ dest_type = getattr(credit_part, "category", "")
+ dest_path = getattr(credit_part, "account", "")
+
+
+ parent_digest = parent_digest = storage_entry.parent.hex()
+
tx_date = storage_entry.dt
+ logg.debug('storage entry #%s tx_date: %s type: %s', storage_entry.serial, tx_date, type(tx_date))
date_registered = storage_entry.dtreg
-
+
transaction_ref = str(storage_entry.ref) if storage_entry.ref else None
-
-
- external_ref = None
- description = storage_entry.description
-
+ external_ref = None
+
domain = LedgerEntry(
external_reference=external_ref,
- description=description,
+ description=storage_entry.description,
amount=amount,
source_unit=source_unit,
source_type=source_type,
@@ -141,11 +120,10 @@ class EntryMapper:
attachments=storage_entry.attachment.copy() if storage_entry.attachment else [],
serial=storage_entry.serial,
tx_date=tx_date,
+ tx_reference=storage_entry.ref,
date_registered=date_registered,
- transaction_ref=transaction_ref,
parent_digest=parent_digest,
unit_index=storage_entry.uidx
)
-
- logg.debug(f"Mapped storage entry #{storage_entry.serial} to domain LedgerEntry")
- return domain
-\ No newline at end of file
+
+ return domain