experimental-accounting-api/accounting/models.py
Joar Wandborg f2b9decf27 SQL, GTK
- Made the storage model slightly more flexible
- Made a small P-o-C GUI application in GTK
- Polished accounting.client
- models.Transaction.id is now a str
- Fixed transaction.id marshalling for storage.ledgercli
2013-12-16 07:33:56 +01:00

56 lines
1.6 KiB
Python

import uuid
from decimal import Decimal
class Transaction:
def __init__(self, id=None, date=None, payee=None, postings=None,
metadata=None, _generate_id=False):
self.id = id
self.date = date
self.payee = payee
self.postings = postings
self.metadata = metadata if metadata is not None else {}
if _generate_id:
self.generate_id()
def generate_id(self):
self.id = str(uuid.uuid4())
def __repr__(self):
return ('<{self.__class__.__name__} {self.id} {date}' +
' {self.payee} {self.postings}').format(
self=self,
date=self.date.strftime('%Y-%m-%d'))
class Posting:
def __init__(self, account=None, amount=None, metadata=None):
self.account = account
self.amount = amount
self.metadata = metadata if metadata is not None else {}
def __repr__(self):
return ('<{self.__class__.__name__} "{self.account}"' +
' {self.amount}>').format(self=self)
class Amount:
def __init__(self, amount=None, symbol=None):
self.amount = Decimal(amount)
self.symbol = symbol
def __repr__(self):
return ('<{self.__class__.__name__} {self.symbol}' +
' {self.amount}>').format(self=self)
class Account:
def __init__(self, name=None, amounts=None, accounts=None):
self.name = name
self.amounts = amounts
self.accounts = accounts
def __repr__(self):
return ('<{self.__class__.__name__} "{self.name}" {self.amounts}' +
' {self.accounts}>').format(self=self)