capabilities.bank: add Transaction.unique_id
This commit is contained in:
parent
539eceef2e
commit
4502b9b015
1 changed files with 17 additions and 0 deletions
|
|
@ -20,6 +20,7 @@
|
||||||
|
|
||||||
import re
|
import re
|
||||||
from datetime import date, datetime
|
from datetime import date, datetime
|
||||||
|
from binascii import crc32
|
||||||
|
|
||||||
from .base import CapBaseObject, Field, StringField, DateField, DecimalField, IntField, UserError
|
from .base import CapBaseObject, Field, StringField, DateField, DecimalField, IntField, UserError
|
||||||
from .collection import ICapCollection
|
from .collection import ICapCollection
|
||||||
|
|
@ -147,6 +148,22 @@ class Transaction(CapBaseObject):
|
||||||
return "<Transaction date='%s' label='%s' amount=%s>" % (self.date,
|
return "<Transaction date='%s' label='%s' amount=%s>" % (self.date,
|
||||||
label, self.amount)
|
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):
|
class Investment(CapBaseObject):
|
||||||
"""
|
"""
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue