2013-12-17 08:42:53 +00:00
< !DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
< html xmlns = "http://www.w3.org/1999/xhtml" >
< head >
< meta http-equiv = "Content-Type" content = "text/html; charset=utf-8" / >
< title > accounting.storage.sql — Accounting API 0.1-beta documentation< / title >
2013-12-18 18:17:02 +00:00
< link rel = "stylesheet" href = "../../../_static/pydoctheme.css" type = "text/css" / >
2013-12-17 08:42:53 +00:00
< link rel = "stylesheet" href = "../../../_static/pygments.css" type = "text/css" / >
< script type = "text/javascript" >
var DOCUMENTATION_OPTIONS = {
URL_ROOT: '../../../',
VERSION: '0.1-beta',
COLLAPSE_INDEX: false,
FILE_SUFFIX: '.html',
HAS_SOURCE: true
};
< / script >
< script type = "text/javascript" src = "../../../_static/jquery.js" > < / script >
< script type = "text/javascript" src = "../../../_static/underscore.js" > < / script >
< script type = "text/javascript" src = "../../../_static/doctools.js" > < / script >
< link rel = "top" title = "Accounting API 0.1-beta documentation" href = "../../../index.html" / >
< link rel = "up" title = "accounting.storage" href = "../storage.html" / >
< / head >
< body >
< div class = "related" >
< h3 > Navigation< / h3 >
< ul >
< li class = "right" style = "margin-right: 10px" >
< a href = "../../../genindex.html" title = "General Index"
accesskey="I">index< / a > < / li >
< li class = "right" >
< a href = "../../../py-modindex.html" title = "Python Module Index"
>modules< / a > |< / li >
< li > < a href = "../../../index.html" > Accounting API 0.1-beta documentation< / a > » < / li >
< li > < a href = "../../index.html" > Module code< / a > » < / li >
< li > < a href = "../../accounting.html" > accounting< / a > » < / li >
< li > < a href = "../storage.html" accesskey = "U" > accounting.storage< / a > » < / li >
< / ul >
< / div >
< div class = "document" >
< div class = "documentwrapper" >
< div class = "bodywrapper" >
< div class = "body" >
< h1 > Source code for accounting.storage.sql< / h1 > < div class = "highlight" > < pre >
< span class = "kn" > import< / span > < span class = "nn" > logging< / span >
< span class = "kn" > import< / span > < span class = "nn" > json< / span >
< span class = "kn" > from< / span > < span class = "nn" > flask.ext.sqlalchemy< / span > < span class = "kn" > import< / span > < span class = "n" > SQLAlchemy< / span >
< span class = "kn" > from< / span > < span class = "nn" > accounting.exceptions< / span > < span class = "kn" > import< / span > < span class = "n" > AccountingException< / span >
< span class = "kn" > from< / span > < span class = "nn" > accounting.storage< / span > < span class = "kn" > import< / span > < span class = "n" > Storage< / span >
< span class = "kn" > from< / span > < span class = "nn" > accounting.models< / span > < span class = "kn" > import< / span > < span class = "n" > Transaction< / span > < span class = "p" > ,< / span > < span class = "n" > Posting< / span > < span class = "p" > ,< / span > < span class = "n" > Amount< / span >
< span class = "n" > _log< / span > < span class = "o" > =< / span > < span class = "n" > logging< / span > < span class = "o" > .< / span > < span class = "n" > getLogger< / span > < span class = "p" > (< / span > < span class = "n" > __name__< / span > < span class = "p" > )< / span >
< span class = "n" > db< / span > < span class = "o" > =< / span > < span class = "bp" > None< / span >
< div class = "viewcode-block" id = "SQLStorage" > < a class = "viewcode-back" href = "../../../api/accounting.storage.sql.html#accounting.storage.sql.SQLStorage" > [docs]< / a > < span class = "k" > class< / span > < span class = "nc" > SQLStorage< / span > < span class = "p" > (< / span > < span class = "n" > Storage< / span > < span class = "p" > ):< / span >
< span class = "k" > def< / span > < span class = "nf" > __init__< / span > < span class = "p" > (< / span > < span class = "bp" > self< / span > < span class = "p" > ,< / span > < span class = "n" > app< / span > < span class = "o" > =< / span > < span class = "bp" > None< / span > < span class = "p" > ):< / span >
< span class = "k" > global< / span > < span class = "n" > db< / span >
< span class = "k" > if< / span > < span class = "ow" > not< / span > < span class = "n" > app< / span > < span class = "p" > :< / span >
< span class = "k" > raise< / span > < span class = "ne" > Exception< / span > < span class = "p" > (< / span > < span class = "s" > ' Missing app keyword argument' < / span > < span class = "p" > )< / span >
< span class = "bp" > self< / span > < span class = "o" > .< / span > < span class = "n" > app< / span > < span class = "o" > =< / span > < span class = "n" > app< / span >
< span class = "n" > db< / span > < span class = "o" > =< / span > < span class = "bp" > self< / span > < span class = "o" > .< / span > < span class = "n" > db< / span > < span class = "o" > =< / span > < span class = "n" > SQLAlchemy< / span > < span class = "p" > (< / span > < span class = "n" > app< / span > < span class = "p" > )< / span >
< span class = "kn" > from< / span > < span class = "nn" > .models< / span > < span class = "kn" > import< / span > < span class = "n" > Transaction< / span > < span class = "k" > as< / span > < span class = "n" > SQLTransaction< / span > < span class = "p" > ,< / span > \
< span class = "n" > Posting< / span > < span class = "k" > as< / span > < span class = "n" > SQLPosting< / span > < span class = "p" > ,< / span > < span class = "n" > Amount< / span > < span class = "k" > as< / span > < span class = "n" > SQLAmount< / span >
< span class = "n" > db< / span > < span class = "o" > .< / span > < span class = "n" > create_all< / span > < span class = "p" > ()< / span >
< span class = "bp" > self< / span > < span class = "o" > .< / span > < span class = "n" > Transaction< / span > < span class = "o" > =< / span > < span class = "n" > SQLTransaction< / span >
< span class = "bp" > self< / span > < span class = "o" > .< / span > < span class = "n" > Posting< / span > < span class = "o" > =< / span > < span class = "n" > SQLPosting< / span >
< span class = "bp" > self< / span > < span class = "o" > .< / span > < span class = "n" > Amount< / span > < span class = "o" > =< / span > < span class = "n" > SQLAmount< / span >
< div class = "viewcode-block" id = "SQLStorage.get_transactions" > < a class = "viewcode-back" href = "../../../api/accounting.storage.sql.html#accounting.storage.sql.SQLStorage.get_transactions" > [docs]< / a > < span class = "k" > def< / span > < span class = "nf" > get_transactions< / span > < span class = "p" > (< / span > < span class = "bp" > self< / span > < span class = "p" > ,< / span > < span class = "o" > *< / span > < span class = "n" > args< / span > < span class = "p" > ,< / span > < span class = "o" > **< / span > < span class = "n" > kw< / span > < span class = "p" > ):< / span >
< span class = "n" > transactions< / span > < span class = "o" > =< / span > < span class = "p" > []< / span >
< span class = "k" > for< / span > < span class = "n" > transaction< / span > < span class = "ow" > in< / span > < span class = "bp" > self< / span > < span class = "o" > .< / span > < span class = "n" > Transaction< / span > < span class = "o" > .< / span > < span class = "n" > query< / span > < span class = "o" > .< / span > < span class = "n" > all< / span > < span class = "p" > ():< / span >
< span class = "n" > dict_transaction< / span > < span class = "o" > =< / span > < span class = "n" > transaction< / span > < span class = "o" > .< / span > < span class = "n" > as_dict< / span > < span class = "p" > ()< / span >
< span class = "n" > dict_postings< / span > < span class = "o" > =< / span > < span class = "n" > dict_transaction< / span > < span class = "o" > .< / span > < span class = "n" > pop< / span > < span class = "p" > (< / span > < span class = "s" > ' postings' < / span > < span class = "p" > )< / span >
< span class = "n" > postings< / span > < span class = "o" > =< / span > < span class = "p" > []< / span >
< span class = "k" > for< / span > < span class = "n" > dict_posting< / span > < span class = "ow" > in< / span > < span class = "n" > dict_postings< / span > < span class = "p" > :< / span >
< span class = "n" > dict_amount< / span > < span class = "o" > =< / span > < span class = "n" > dict_posting< / span > < span class = "o" > .< / span > < span class = "n" > pop< / span > < span class = "p" > (< / span > < span class = "s" > ' amount' < / span > < span class = "p" > )< / span >
< span class = "n" > posting< / span > < span class = "o" > =< / span > < span class = "n" > Posting< / span > < span class = "p" > (< / span > < span class = "o" > **< / span > < span class = "n" > dict_posting< / span > < span class = "p" > )< / span >
< span class = "n" > posting< / span > < span class = "o" > .< / span > < span class = "n" > amount< / span > < span class = "o" > =< / span > < span class = "n" > Amount< / span > < span class = "p" > (< / span > < span class = "o" > **< / span > < span class = "n" > dict_amount< / span > < span class = "p" > )< / span >
< span class = "n" > postings< / span > < span class = "o" > .< / span > < span class = "n" > append< / span > < span class = "p" > (< / span > < span class = "n" > posting< / span > < span class = "p" > )< / span >
< span class = "n" > dict_transaction< / span > < span class = "o" > .< / span > < span class = "n" > update< / span > < span class = "p" > ({< / span > < span class = "s" > ' postings' < / span > < span class = "p" > :< / span > < span class = "n" > postings< / span > < span class = "p" > })< / span >
< span class = "n" > transactions< / span > < span class = "o" > .< / span > < span class = "n" > append< / span > < span class = "p" > (< / span > < span class = "n" > Transaction< / span > < span class = "p" > (< / span > < span class = "o" > **< / span > < span class = "n" > dict_transaction< / span > < span class = "p" > ))< / span >
< span class = "k" > return< / span > < span class = "n" > transactions< / span >
< / div >
< div class = "viewcode-block" id = "SQLStorage.update_transaction" > < a class = "viewcode-back" href = "../../../api/accounting.storage.sql.html#accounting.storage.sql.SQLStorage.update_transaction" > [docs]< / a > < span class = "k" > def< / span > < span class = "nf" > update_transaction< / span > < span class = "p" > (< / span > < span class = "bp" > self< / span > < span class = "p" > ,< / span > < span class = "n" > transaction< / span > < span class = "p" > ):< / span >
< span class = "k" > if< / span > < span class = "n" > transaction< / span > < span class = "o" > .< / span > < span class = "n" > id< / span > < span class = "ow" > is< / span > < span class = "bp" > None< / span > < span class = "p" > :< / span >
< span class = "k" > raise< / span > < span class = "n" > AccountingException< / span > < span class = "p" > (< / span > < span class = "s" > ' The transaction id must be set for' < / span >
< span class = "s" > ' update_transaction calls' < / span > < span class = "p" > )< / span >
< span class = "n" > _log< / span > < span class = "o" > .< / span > < span class = "n" > debug< / span > < span class = "p" > (< / span > < span class = "s" > ' DUMMY: Update transaction: < / span > < span class = "si" > %s< / span > < span class = "s" > ' < / span > < span class = "p" > ,< / span > < span class = "n" > transaction< / span > < span class = "p" > )< / span >
< / div >
< div class = "viewcode-block" id = "SQLStorage.add_transaction" > < a class = "viewcode-back" href = "../../../api/accounting.storage.sql.html#accounting.storage.sql.SQLStorage.add_transaction" > [docs]< / a > < span class = "k" > def< / span > < span class = "nf" > add_transaction< / span > < span class = "p" > (< / span > < span class = "bp" > self< / span > < span class = "p" > ,< / span > < span class = "n" > transaction< / span > < span class = "p" > ):< / span >
< span class = "k" > if< / span > < span class = "n" > transaction< / span > < span class = "o" > .< / span > < span class = "n" > id< / span > < span class = "ow" > is< / span > < span class = "bp" > None< / span > < span class = "p" > :< / span >
< span class = "n" > transaction< / span > < span class = "o" > .< / span > < span class = "n" > generate_id< / span > < span class = "p" > ()< / span >
< span class = "n" > _t< / span > < span class = "o" > =< / span > < span class = "bp" > self< / span > < span class = "o" > .< / span > < span class = "n" > Transaction< / span > < span class = "p" > ()< / span >
< span class = "n" > _t< / span > < span class = "o" > .< / span > < span class = "n" > uuid< / span > < span class = "o" > =< / span > < span class = "n" > transaction< / span > < span class = "o" > .< / span > < span class = "n" > id< / span >
< span class = "n" > _t< / span > < span class = "o" > .< / span > < span class = "n" > date< / span > < span class = "o" > =< / span > < span class = "n" > transaction< / span > < span class = "o" > .< / span > < span class = "n" > date< / span >
< span class = "n" > _t< / span > < span class = "o" > .< / span > < span class = "n" > payee< / span > < span class = "o" > =< / span > < span class = "n" > transaction< / span > < span class = "o" > .< / span > < span class = "n" > payee< / span >
< span class = "n" > _t< / span > < span class = "o" > .< / span > < span class = "n" > meta< / span > < span class = "o" > =< / span > < span class = "n" > json< / span > < span class = "o" > .< / span > < span class = "n" > dumps< / span > < span class = "p" > (< / span > < span class = "n" > transaction< / span > < span class = "o" > .< / span > < span class = "n" > metadata< / span > < span class = "p" > )< / span >
< span class = "bp" > self< / span > < span class = "o" > .< / span > < span class = "n" > db< / span > < span class = "o" > .< / span > < span class = "n" > session< / span > < span class = "o" > .< / span > < span class = "n" > add< / span > < span class = "p" > (< / span > < span class = "n" > _t< / span > < span class = "p" > )< / span >
< span class = "k" > for< / span > < span class = "n" > posting< / span > < span class = "ow" > in< / span > < span class = "n" > transaction< / span > < span class = "o" > .< / span > < span class = "n" > postings< / span > < span class = "p" > :< / span >
< span class = "n" > _p< / span > < span class = "o" > =< / span > < span class = "bp" > self< / span > < span class = "o" > .< / span > < span class = "n" > Posting< / span > < span class = "p" > ()< / span >
< span class = "n" > _p< / span > < span class = "o" > .< / span > < span class = "n" > transaction_uuid< / span > < span class = "o" > =< / span > < span class = "n" > transaction< / span > < span class = "o" > .< / span > < span class = "n" > id< / span >
< span class = "n" > _p< / span > < span class = "o" > .< / span > < span class = "n" > account< / span > < span class = "o" > =< / span > < span class = "n" > posting< / span > < span class = "o" > .< / span > < span class = "n" > account< / span >
< span class = "n" > _p< / span > < span class = "o" > .< / span > < span class = "n" > meta< / span > < span class = "o" > =< / span > < span class = "n" > json< / span > < span class = "o" > .< / span > < span class = "n" > dumps< / span > < span class = "p" > (< / span > < span class = "n" > posting< / span > < span class = "o" > .< / span > < span class = "n" > metadata< / span > < span class = "p" > )< / span >
< span class = "n" > _p< / span > < span class = "o" > .< / span > < span class = "n" > amount< / span > < span class = "o" > =< / span > < span class = "bp" > self< / span > < span class = "o" > .< / span > < span class = "n" > Amount< / span > < span class = "p" > (< / span > < span class = "n" > symbol< / span > < span class = "o" > =< / span > < span class = "n" > posting< / span > < span class = "o" > .< / span > < span class = "n" > amount< / span > < span class = "o" > .< / span > < span class = "n" > symbol< / span > < span class = "p" > ,< / span >
< span class = "n" > amount< / span > < span class = "o" > =< / span > < span class = "n" > posting< / span > < span class = "o" > .< / span > < span class = "n" > amount< / span > < span class = "o" > .< / span > < span class = "n" > amount< / span > < span class = "p" > )< / span >
< span class = "bp" > self< / span > < span class = "o" > .< / span > < span class = "n" > db< / span > < span class = "o" > .< / span > < span class = "n" > session< / span > < span class = "o" > .< / span > < span class = "n" > add< / span > < span class = "p" > (< / span > < span class = "n" > _p< / span > < span class = "p" > )< / span >
< span class = "bp" > self< / span > < span class = "o" > .< / span > < span class = "n" > db< / span > < span class = "o" > .< / span > < span class = "n" > session< / span > < span class = "o" > .< / span > < span class = "n" > commit< / span > < span class = "p" > ()< / span > < / div > < / div >
< / pre > < / div >
< / div >
< / div >
< / div >
< div class = "sphinxsidebar" >
< div class = "sphinxsidebarwrapper" >
< div id = "searchbox" style = "display: none" >
< h3 > Quick search< / h3 >
< form class = "search" action = "../../../search.html" method = "get" >
< input type = "text" name = "q" / >
< input type = "submit" value = "Go" / >
< input type = "hidden" name = "check_keywords" value = "yes" / >
< input type = "hidden" name = "area" value = "default" / >
< / form >
< p class = "searchtip" style = "font-size: 90%" >
Enter search terms or a module, class or function name.
< / p >
< / div >
< script type = "text/javascript" > $ ( '#searchbox' ) . show ( 0 ) ; < / script >
< / div >
< / div >
< div class = "clearer" > < / div >
< / div >
< div class = "related" >
< h3 > Navigation< / h3 >
< ul >
< li class = "right" style = "margin-right: 10px" >
< a href = "../../../genindex.html" title = "General Index"
>index< / a > < / li >
< li class = "right" >
< a href = "../../../py-modindex.html" title = "Python Module Index"
>modules< / a > |< / li >
< li > < a href = "../../../index.html" > Accounting API 0.1-beta documentation< / a > » < / li >
< li > < a href = "../../index.html" > Module code< / a > » < / li >
< li > < a href = "../../accounting.html" > accounting< / a > » < / li >
< li > < a href = "../storage.html" > accounting.storage< / a > » < / li >
< / ul >
< / div >
< div class = "footer" >
© Copyright 2013, Joar Wandborg.
Created using < a href = "http://sphinx-doc.org/" > Sphinx< / a > 1.2.
< / div >
< / body >
< / html >