149 lines
No EOL
12 KiB
HTML
149 lines
No EOL
12 KiB
HTML
<!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.models — Accounting API 0.1-beta documentation</title>
|
|
|
|
<link rel="stylesheet" href="../../_static/default.css" type="text/css" />
|
|
<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" href="../accounting.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" accesskey="U">accounting</a> »</li>
|
|
</ul>
|
|
</div>
|
|
|
|
<div class="document">
|
|
<div class="documentwrapper">
|
|
<div class="bodywrapper">
|
|
<div class="body">
|
|
|
|
<h1>Source code for accounting.models</h1><div class="highlight"><pre>
|
|
<span class="kn">import</span> <span class="nn">uuid</span>
|
|
<span class="kn">from</span> <span class="nn">decimal</span> <span class="kn">import</span> <span class="n">Decimal</span>
|
|
|
|
|
|
<div class="viewcode-block" id="Transaction"><a class="viewcode-back" href="../../api/accounting.html#accounting.models.Transaction">[docs]</a><span class="k">class</span> <span class="nc">Transaction</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">date</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span> <span class="n">payee</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span> <span class="n">postings</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span> <span class="n">metadata</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span>
|
|
<span class="n">_generate_id</span><span class="o">=</span><span class="bp">False</span><span class="p">):</span>
|
|
<span class="bp">self</span><span class="o">.</span><span class="n">date</span> <span class="o">=</span> <span class="n">date</span>
|
|
<span class="bp">self</span><span class="o">.</span><span class="n">payee</span> <span class="o">=</span> <span class="n">payee</span>
|
|
<span class="bp">self</span><span class="o">.</span><span class="n">postings</span> <span class="o">=</span> <span class="n">postings</span>
|
|
<span class="bp">self</span><span class="o">.</span><span class="n">metadata</span> <span class="o">=</span> <span class="n">metadata</span> <span class="k">if</span> <span class="n">metadata</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span> <span class="k">else</span> <span class="p">{}</span>
|
|
|
|
<span class="k">if</span> <span class="n">_generate_id</span><span class="p">:</span>
|
|
<span class="bp">self</span><span class="o">.</span><span class="n">generate_id</span><span class="p">()</span>
|
|
|
|
<div class="viewcode-block" id="Transaction.generate_id"><a class="viewcode-back" href="../../api/accounting.html#accounting.models.Transaction.generate_id">[docs]</a> <span class="k">def</span> <span class="nf">generate_id</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
|
|
<span class="bp">self</span><span class="o">.</span><span class="n">metadata</span><span class="o">.</span><span class="n">update</span><span class="p">({</span><span class="s">'Id'</span><span class="p">:</span> <span class="n">uuid</span><span class="o">.</span><span class="n">uuid4</span><span class="p">()})</span>
|
|
</div>
|
|
<span class="k">def</span> <span class="nf">__repr__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
|
|
<span class="k">return</span> <span class="p">(</span><span class="s">'<{self.__class__.__name__} {date}'</span> <span class="o">+</span>
|
|
<span class="s">' {self.payee} {self.postings}'</span><span class="p">)</span><span class="o">.</span><span class="n">format</span><span class="p">(</span>
|
|
<span class="bp">self</span><span class="o">=</span><span class="bp">self</span><span class="p">,</span>
|
|
<span class="n">date</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">date</span><span class="o">.</span><span class="n">strftime</span><span class="p">(</span><span class="s">'%Y-%m-</span><span class="si">%d</span><span class="s">'</span><span class="p">))</span>
|
|
|
|
</div>
|
|
<div class="viewcode-block" id="Posting"><a class="viewcode-back" href="../../api/accounting.html#accounting.models.Posting">[docs]</a><span class="k">class</span> <span class="nc">Posting</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">account</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span> <span class="n">amount</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span> <span class="n">metadata</span><span class="o">=</span><span class="bp">None</span><span class="p">):</span>
|
|
<span class="bp">self</span><span class="o">.</span><span class="n">account</span> <span class="o">=</span> <span class="n">account</span>
|
|
<span class="bp">self</span><span class="o">.</span><span class="n">amount</span> <span class="o">=</span> <span class="n">amount</span>
|
|
<span class="bp">self</span><span class="o">.</span><span class="n">metadata</span> <span class="o">=</span> <span class="n">metadata</span> <span class="k">if</span> <span class="n">metadata</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span> <span class="k">else</span> <span class="p">{}</span>
|
|
|
|
<span class="k">def</span> <span class="nf">__repr__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
|
|
<span class="k">return</span> <span class="p">(</span><span class="s">'<{self.__class__.__name__} "{self.account}"'</span> <span class="o">+</span>
|
|
<span class="s">' {self.amount}>'</span><span class="p">)</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="bp">self</span><span class="o">=</span><span class="bp">self</span><span class="p">)</span>
|
|
|
|
</div>
|
|
<div class="viewcode-block" id="Amount"><a class="viewcode-back" href="../../api/accounting.html#accounting.models.Amount">[docs]</a><span class="k">class</span> <span class="nc">Amount</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">amount</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span> <span class="n">symbol</span><span class="o">=</span><span class="bp">None</span><span class="p">):</span>
|
|
<span class="bp">self</span><span class="o">.</span><span class="n">amount</span> <span class="o">=</span> <span class="n">Decimal</span><span class="p">(</span><span class="n">amount</span><span class="p">)</span>
|
|
<span class="bp">self</span><span class="o">.</span><span class="n">symbol</span> <span class="o">=</span> <span class="n">symbol</span>
|
|
|
|
<span class="k">def</span> <span class="nf">__repr__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
|
|
<span class="k">return</span> <span class="p">(</span><span class="s">'<{self.__class__.__name__} {self.symbol}'</span> <span class="o">+</span>
|
|
<span class="s">' {self.amount}>'</span><span class="p">)</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="bp">self</span><span class="o">=</span><span class="bp">self</span><span class="p">)</span>
|
|
|
|
</div>
|
|
<div class="viewcode-block" id="Account"><a class="viewcode-back" href="../../api/accounting.html#accounting.models.Account">[docs]</a><span class="k">class</span> <span class="nc">Account</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">name</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span> <span class="n">amounts</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span> <span class="n">accounts</span><span class="o">=</span><span class="bp">None</span><span class="p">):</span>
|
|
<span class="bp">self</span><span class="o">.</span><span class="n">name</span> <span class="o">=</span> <span class="n">name</span>
|
|
<span class="bp">self</span><span class="o">.</span><span class="n">amounts</span> <span class="o">=</span> <span class="n">amounts</span>
|
|
<span class="bp">self</span><span class="o">.</span><span class="n">accounts</span> <span class="o">=</span> <span class="n">accounts</span>
|
|
|
|
<span class="k">def</span> <span class="nf">__repr__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
|
|
<span class="k">return</span> <span class="p">(</span><span class="s">'<{self.__class__.__name__} "{self.name}" {self.amounts}'</span> <span class="o">+</span>
|
|
<span class="s">' {self.accounts}>'</span><span class="p">)</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="bp">self</span><span class="o">=</span><span class="bp">self</span><span class="p">)</span></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>
|
|
</ul>
|
|
</div>
|
|
<div class="footer">
|
|
© Copyright 2013, Joar Wandborg.
|
|
Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.2.
|
|
</div>
|
|
</body>
|
|
</html> |