usawa

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

commit 800a625e0a03b6a9223e77d5ee06e25236c997a4
parent 33c3013f56b691cf57ce406caf8516650b4cff65
Author: lash <dev@holbrook.no>
Date:   Fri,  1 May 2026 19:11:07 -0600

Make tags in entries tag objects

Diffstat:
Mdummy/tests/entry.py | 16++++++++++++++++
Mdummy/usawa/entry.py | 26+++++++++++++++++---------
Mdummy/usawa/tag.py | 11+++++++++++
3 files changed, 44 insertions(+), 9 deletions(-)

diff --git a/dummy/tests/entry.py b/dummy/tests/entry.py @@ -148,5 +148,21 @@ class TestEntry(unittest.TestCase): o.add_part(dst_two) + def test_entry_serialize_full(self): + dst_one = EntryPart('FOO', 'asset', 'foo', 1337) + dst_two = EntryPart('FOO', 'asset', 'bar', 42) + src = EntryPart('FOO', 'income', 'baz', 1337+42, debit=True) + o = Entry(42, datetime.datetime.strptime('2025-11-11', '%Y-%m-%d'), parent=self.parent, ref=self.ref, description=self.description, tx_datereg=self.dtreg, unitindex=self.uidx) + o.add_part(src) + o.add_part(dst_one) + o.add_part(dst_two) + o.tag('foobar') + o.tag('barbaz') + b = o.serialize() + o = Entry.deserialize(b) + self.assertTrue(o.has_tag('foobar')) + self.assertTrue(o.has_tag('barbaz')) + + if __name__ == '__main__': unittest.main() diff --git a/dummy/usawa/entry.py b/dummy/usawa/entry.py @@ -216,6 +216,8 @@ class Entry(UsawaElement): self.lookup_algo = None self.parts = [] self.balancer = None + if tags == None: + tags = Tags() self.tags = tags self.extref = extref if unitindex != None: @@ -369,7 +371,6 @@ class Entry(UsawaElement): for v in self.attachment: attach.append(v.get_digest(binary=True)) - tags = [] if self.tags: tags = self.tags @@ -386,7 +387,7 @@ class Entry(UsawaElement): credit, debit, attach, - tags, + tags.serialize(), self.extref, ] return d @@ -410,7 +411,7 @@ class Entry(UsawaElement): :rtype: usawa.Entry """ @staticmethod - def deserialize(data, unitindex=None): + def deserialize(data, unitindex=None, store=None): v = rencode.loads(data) parent = v[1] serial = v[2] @@ -426,12 +427,13 @@ class Entry(UsawaElement): dst_data = v[7] src_data = v[8] attach_data = v[9] + tags = Tags.deserialize(v[10], store=store) #tags = None #try: # tags = Tags.deserialize(v[10]) #except TypeError: # pass - tags = [] + #tags = [] # for s in v[10]: # try: # tags.append(s.decode('utf-8')) @@ -718,11 +720,17 @@ class Entry(UsawaElement): return(z.hex(), b,) - def tag(self, tag): - if self.tags == None: - self.tags = [] - if not tag in self.tags: - self.tags.append(tag) + def tag(self, tag, description=None): + self.tags.add(tag, description=description) + #if self.tags == None: + # self.tags = [] + #if not tag in self.tags: + # self.tags.append(tag) + + + def has_tag(self, tag): + logg.debug("tagssss {}".format(self.tags)) + return self.tags.has(tag) def untag(self, tag): diff --git a/dummy/usawa/tag.py b/dummy/usawa/tag.py @@ -1,5 +1,6 @@ import rencode + class Tags: def __init__(self, store=None): @@ -13,6 +14,16 @@ class Tags: self.store.put_tag(tag, description) + def has(self, tag): + r = False + try: + v = self.tags.get(tag) + r = True + except KeyError: + pass + return r + + def remove(self, tag): del(self.tags[tag])