Exemplo n.º 1
0
      flush=True)
accounts_ = ledger.queryHledgerForAccountListWithBalance(hledger_ledgerpath_,
                                                         depth=depth,
                                                         args=sys.argv[1:])
print("done")

#need to convert filter-generator to actual list or we can only read it once
print(
    "getting journal from hledger (apply filters) and parsing it into python objects ...",
    end="",
    flush=True)
transactions = list(
    filter(
        lambda t: len(t.postings) > 0,
        ledger.parseJournal(
            ledger.getHLedger(hledger_ledgerpath_, ["--cost"] + sys.argv[1:],
                              depth=None))))
print("done")

print("depth limiting transactions ...", end="", flush=True)
for t in transactions:
    t.reduceDepth(depth)
print("done")

transactions_with_tempaccounts_without_multidates = list(
    ledger.sortTransactionsByDate(
        list(
            ledger.createTempAccountsForAndConvertFromMultiDatePostings(
                transactions))))

## make running sum of journal for the graphs
Exemplo n.º 2
0
from functools import reduce

register_account_ = "assets:current:cash:register"
revenue_accounts_ = ["revenue:sales:edibles", "revenue:sales:materials"]
inventory_accounts_ = ["assets:current:inventory-edibles", "assets:current:inventory-materials" ]
schwund_account_ = "expenses:shrinkage"
donation_account_ = "expenses:shrinkage"
#donation_account_ = "revenue:donations:shrinkage"
default_currency_ = "EUR"

hledger_ledgerpath_=os.path.split(__file__)[0]+'/../Ledgers/r3.ledger'

ledger_fileobj = open(hledger_ledgerpath_)
journal = ledger.sortTransactionsByDate(
    list(ledger.createTempAccountsForAndConvertFromMultiDatePostings(
        ledger.parseJournal(ledger_fileobj)
        ))
    )
ledger_fileobj.close()

acct_currency_amt_dict, asstresult = ledger.sumUpJournalVerifyAssertions(journal, abort_on_assrtfail=True)
#print(ledger.showSums(acct_currency_amt_dict, [register_account_, revenue_account_]+ inventory_accounts_))

if asstresult == True:
    sys.exit(0)
    ##nothing to do

asstresult, problematic_transaction, posting_with_failed_assertion = asstresult

assert(asstresult == False)
if problematic_transaction.name != "INVENTUR":
Exemplo n.º 3
0
import datetime

register_account_ = "assets:current:cash:register"
revenue_accounts_ = ["revenue:sales:edibles", "revenue:sales:materials"]
inventory_accounts_ = ["assets:current:inventory-edibles", "assets:current:inventory-materials" ]
schwund_account_ = "expenses:shrinkage"
donation_account_ = "expenses:shrinkage"
#donation_account_ = "revenue:donations:shrinkage"
default_currency_ = "EUR"

hledger_ledgerpath_=os.path.split(__file__)[0]+'/../Ledgers/r3.ledger'

ledger_fileobj = open(hledger_ledgerpath_)
journal = ledger.sortTransactionsByDate(
    list(ledger.createTempAccountsForAndConvertFromMultiDatePostings(
        ledger.parseJournal(ledger_fileobj)
        ))
    )
ledger_fileobj.close()

dates = []
interval = [] # days between taking inventory
d1 = []
d2 = []
d3 = []
d4 = []

# 3 datapoints of umsatz:
# - minimum break even point: summmer der einkaufspreise der getränke/snaks die aus assets:current:inventory-edibles verkauft wurden
# - tatsächlicher umsatz: erwarteter umsatz mit getränken - schwund in euro
# - maximum we should get: erw. umsatz mit getränken
Exemplo n.º 4
0
#!/usr/bin/python3
# -*- coding: utf-8 -*-

import ledger
import sys
with open(sys.argv[1]) as jf:
    j = ledger.sortTransactionsByDate(ledger.parseJournal(jf))
#    j = ledger.parseJournal(jf)

#for t in j:
#    sys.stdout.write("%s\n\n" % (t,))

for t, acctsum, assrt in ledger.runningSumOfJournal(j):
    sys.stdout.write("%s\n-----------\n%s%s\n\n" % (t,ledger.showSums(acctsum,["assets:current:cash:register"]),assrt))
Exemplo n.º 5
0
    def addLabel(self, label):
        self.graph.append('labelloc="t"')
        if self.html:
            self.graph.append('label=<<u><b>%s</b></u>>' % cgi.escape(label))
        else:
            self.graph.append('label="%s"' % label.replace("\"","\\\""))

    def mkGraph(self, name):
        return "digraph %s {\n" % (name,) + "".join(map(lambda s: "\t%s;\n" % s ,self.graph)) + "}\n"


depth = 3
#depth = None
accounts = ledger.queryHledgerForAccountListWithBalance(hledger_ledgerpath_, depth=depth)
transactions = filter(lambda t: len(t.postings) > 0, ledger.parseJournal(ledger.getHLedger(hledger_ledgerpath_, ["--cost"],depth=None)))
#transactions_all = ledger.parseJournal(ledger.getHLedger(hledger_ledgerpath_, ["--cost"],depth=None))
transactions_dict = {}
for t in transactions:
    if t.name in transactions_dict:
        try:
            transactions_dict[t.name].mergeInPostingsFrom(t)
        except ledger.DifferentCurrency:
            print("Transaction Currencies Differ:", file=sys.stderr)
            print(transactions_dict[t.name], file=sys.stderr)
            print(t, file=sys.stderr)
    else:
        transactions_dict[t.name] = t.reduceDepth(None) # make sure each posting has an unique account

for t in transactions_dict.values():
    t.reduceDepth(depth)
#exactly one of these options must be set
if not (output_csv ^ output_html):
    printhelp()
    sys.exit(1)

depth = 3
#depth = None

#need to convert filter-generator to actual list or we can only read it once
#getting journal from hledger (apply filters) and parsing it into python objects ...
transactions = list(
    filter(
        lambda t: len(t.postings) > 0,
        ledger.parseJournal(
            ledger.getHLedger(hledger_ledgerpath_, ["--cost"] + args,
                              depth=None))))

#depth limiting transactions ...
for t in transactions:
    t.reduceDepth(depth)

in_out_postingslist_ = []
if inventory_mode:
    for t in transactions:
        ## if transaction contains revenue:sales-gewinn:* postings it is a GEWINN transaction
        if any([(posting.account in inventory_source_accounts_)
                for posting in t.postings]):
            ## in that case: only add the postings to cash:register which contains actual cash income
            ## and ignore all the inventory account postings
            for posting in t.postings:
Exemplo n.º 7
0

############## MAIN #####################

depth = 3
#depth = None
print("running hledger (apply filters), getting balances ...", end="", flush=True)
accounts_ = ledger.queryHledgerForAccountListWithBalance(hledger_ledgerpath_, depth=depth, args=sys.argv[1:])
print("done")

#need to convert filter-generator to actual list or we can only read it once
print("getting journal from hledger (apply filters) and parsing it into python objects ...", end="", flush=True)
transactions = list(
                filter(
                    lambda t: len(t.postings) > 0, ledger.parseJournal(
                        ledger.getHLedger(hledger_ledgerpath_, ["--cost"] + sys.argv[1:],depth=None)
                        )
                    )
                )
print("done")

print("depth limiting transactions ...", end="", flush=True)
for t in transactions:
    t.reduceDepth(depth)
print("done")

transactions_with_tempaccounts_without_multidates = list(ledger.sortTransactionsByDate(
        list(ledger.createTempAccountsForAndConvertFromMultiDatePostings(transactions))
    ))

## make running sum of journal for the graphs