capabilities.bank: add Transaction.unique_id

This commit is contained in:
Noé Rubinstein 2013-07-26 20:53:30 +02:00 committed by Romain Bignon
commit 4502b9b015

View file

@ -20,6 +20,7 @@
import re
from datetime import date, datetime
from binascii import crc32
from .base import CapBaseObject, Field, StringField, DateField, DecimalField, IntField, UserError
from .collection import ICapCollection
@ -147,6 +148,22 @@ class Transaction(CapBaseObject):
return "<Transaction date='%s' label='%s' amount=%s>" % (self.date,
label, self.amount)
def unique_id(self, seen=None, account_id=None):
crc = crc32(str(self.date))
crc = crc32(str(self.amount), crc)
crc = crc32(self.label.encode("utf-8"), crc)
if account_id is not None:
crc = crc32(str(account_id), crc)
if seen is not None:
while crc in seen:
crc = crc32("*", crc)
seen.add(crc)
return "%08x" % (crc & 0xffffffff)
class Investment(CapBaseObject):
"""