Пример #1
0
    def fill(self):
        roots = {0:None}
        node = None
        plevel = 0
        plan = AccountsPlan()
        for level, acc in accounts_walk(plan.accounts()):
            if level > plevel:
                roots[level] = node

            node = self.account_store.append(roots[level], (acc.id, acc.name, acc.desc))
            self.accounts[self.account_store.get_path(node)] = acc
            plevel = level

        def add_new(rows):
            if not rows:
                return

            for p in rows:
                if self.account_store.iter_has_child(p.iter):
                    self.account_view.expand_row(p.path, False)

                add_new(list(p.iterchildren()))
                self.add_new_account(p.path)

        add_new(list(self.account_store))
        self.add_new_account(None)
        self.window.set_default_size(-1, max(200, min(400, self.account_view.size_request()[1])))
Пример #2
0
def test_who_choice(db):
    plan = AccountsPlan()

    acc1 = plan.add_account()
    acc2 = plan.add_account()

    t = plan.create_transaction(acc1, acc2, 200.0)
    t.who = u'Бичиков'
    t.save()

    t = plan.create_transaction(acc1, acc2, 300.0)
    t.who = u'Зубков'
    t.save()

    result = bank.get_who_choice()
    assert result == [u'Бичиков', u'Зубков']

    t = plan.create_transaction(acc1, acc2, 300.0)
    t.who = u'Зубков'
    t.save()

    result = bank.get_who_choice()
    assert result == [u'Бичиков', u'Зубков']
Пример #3
0
def test_what_choice(db):
    plan = AccountsPlan()

    acc1 = plan.add_account()
    acc2 = plan.add_account()

    t = plan.create_transaction(acc1, acc2, 200.0)
    t.what = u'за хлеб'
    t.save()

    t = plan.create_transaction(acc1, acc2, 300.0)
    t.what = u'за воду'
    t.save()

    result = bank.get_what_choice()
    assert result == [u'за воду', u'за хлеб']

    t = plan.create_transaction(acc1, acc2, 300.0)
    t.what = u'за воду'
    t.save()

    result = bank.get_what_choice()
    assert result == [u'за воду', u'за хлеб']
Пример #4
0
    def __init__(self, conf, account_name):
        self.conf = conf

        BuilderAware.__init__(self, join_to_file_dir(__file__, "main.glade"))

        self.plan = AccountsPlan()
        self.bank_acc = self.plan.get_by_name(account_name)

        self.last_in_num_param = self.conf.param('last_in_num_for_'+self.bank_acc._id)
        self.last_out_num_param = self.conf.param('last_out_num_for_'+self.bank_acc._id)

        self.update_saldo(date.today())
        self.on_date_month_changed(self.date)
        self.set_date(date.today())
        self.update_last_nums()

        self.window.set_title(
            conf.get('firm_name', 'WTF?') + ' | ' + self.bank_acc.name + ' ' + self.bank_acc.desc)

        self.window.show()
Пример #5
0
def test_transaction_days(db):
    plan = AccountsPlan()

    acc1 = plan.add_account()
    acc2 = plan.add_account()

    plan.create_transaction(acc1, acc2, 200.0, datetime(2010, 5, 20)).save()
    plan.create_transaction(acc1, acc2, 300.0, datetime(2010, 5, 31)).save()
    plan.create_transaction(acc1, acc2, 100.0, datetime(2010, 6, 01)).save()

    result = bank.get_month_transaction_days(acc1, 2010, 5)
    assert result == [20, 31]

    result = bank.get_month_transaction_days(acc2, 2010, 6)
    assert result == [1]

    result = bank.get_month_transaction_days(acc2, 2010, 7)
    assert result == []
Пример #6
0
#!/usr/bin/env python

import sys
sys.path.append('./src')

from datetime import date

import bank.reports.kassa
import bank.reports.month

from taburet import PackageManager
from taburet.accounts import AccountsPlan
import couchdbkit

import taburet.report.excel

s = couchdbkit.Server()
db = s.get_or_create_db('demo')

pm = PackageManager()
pm.use('bank')
pm.set_db(db, 'taburet.transactions', 'taburet.accounts')
pm.sync_design_documents()

plan = AccountsPlan()
account = plan.get_by_name('51/1')

report = bank.reports.kassa.do(account, date(2010, 5, 4))
#report = bank.reports.month.do(account, date(2010, 4, 4), True)
taburet.report.excel.save(report, '/tmp/wow.xls')
Пример #7
0
import couchdbkit
import csv, datetime
import sys

s = couchdbkit.Server()
db = s.get_or_create_db('dalxleb')
pm = PackageManager()
pm.use('taburet.accounts')
pm.set_db(db, 'taburet.accounts', 'taburet.transactions')
pm.sync_design_documents()


accounts_cache = {}

plan = AccountsPlan()
def get_or_create_account(name):
    try:
        return accounts_cache[name]
    except KeyError:
        pass

    result = plan.get_by_name(name)
    if result:
        accounts_cache[name] = result
        return result

    if '/' in name:
        parent, _child = name.split('/', 1)
        return plan.add_account(name, get_or_create_account(parent))
Пример #8
0
class BankApp(CommonApp, BuilderAware):
    """glade-file: main.glade"""
    def __init__(self, conf, account_name):
        self.conf = conf

        BuilderAware.__init__(self, join_to_file_dir(__file__, "main.glade"))

        self.plan = AccountsPlan()
        self.bank_acc = self.plan.get_by_name(account_name)

        self.last_in_num_param = self.conf.param('last_in_num_for_'+self.bank_acc._id)
        self.last_out_num_param = self.conf.param('last_out_num_for_'+self.bank_acc._id)

        self.update_saldo(date.today())
        self.on_date_month_changed(self.date)
        self.set_date(date.today())
        self.update_last_nums()

        self.window.set_title(
            conf.get('firm_name', 'WTF?') + ' | ' + self.bank_acc.name + ' ' + self.bank_acc.desc)

        self.window.show()

    def on_date_day_selected(self, widget, data=None):
        self.update_saldo(self.get_date())

    def update_saldo(self, date):
        balance = self.bank_acc.balance(date, date)

        self.in_total.props.label = "%.2f" % balance.debet
        self.out_total.props.label = "%.2f" % balance.kredit

        saldo = self.bank_acc.balance(None, date - timedelta(days=1))

        self.begin_saldo.props.label = "%.2f" % saldo.balance
        self.end_saldo.props.label = "%.2f" % (saldo.balance + balance.balance)

    def update_last_nums(self):
        self.last_in_num.set_text(str(self.last_in_num_param.get(0)))
        self.last_out_num.set_text(str(self.last_out_num_param.get(0)))

    def on_date_month_changed(self, widget):
        date = self.get_date()
        self.date.clear_marks()
        map(self.date.mark_day, get_month_transaction_days(self.bank_acc, date.year, date.month))

    def set_date(self, date):
        self.date.props.year = date.year
        self.date.props.month = date.month - 1
        self.date.props.day = date.day

    def get_date(self):
        return datetime(self.date.props.year, self.date.props.month + 1, self.date.props.day)

    def on_outcome_transactions_clicked(self, widget):
        self.show_transactions_input_window(False)

    def on_income_transactions_clicked(self, widget):
        self.show_transactions_input_window(True)

    def show_transactions_input_window(self, inout):
        from transactions import TransactionsForm
        form = TransactionsForm(inout, self.bank_acc, self.get_date(),
            self.last_in_num_param, self.last_out_num_param, self.on_transaction_input_hide)
        form.show()

    def on_transaction_input_hide(self, *args):
        idle(self.update_saldo, self.get_date())
        idle(self.update_last_nums)

    def on_last_out_num_focus_out_event(self, entry, event):
        self.last_out_num_param.set(int(entry.get_text()))

    def on_last_in_num_focus_out_event(self, entry, event):
        self.last_in_num_param.set(int(entry.get_text()))

    def on_kassa_report_activate(self, *args):
        from ..reports import kassa
        import taburet.report.excel
        import tempfile
        from taburet.utils import start_file

        report = kassa.do(self.conf, self.bank_acc, self.get_date())
        filename = tempfile.mkstemp('.xls')[1]
        taburet.report.excel.save(report, filename)

        start_file(filename)

    def on_in_report_activate(self, *args):
        from ..reports import month
        import taburet.report.excel
        import tempfile
        from taburet.utils import start_file

        report = month.do(self.conf, self.bank_acc, self.get_date(), True)
        filename = tempfile.mkstemp('.xls')[1]
        taburet.report.excel.save(report, filename)

        start_file(filename)

    def on_out_report_activate(self, *args):
        from ..reports import month
        import taburet.report.excel
        import tempfile
        from taburet.utils import start_file

        report = month.do(self.conf, self.bank_acc, self.get_date(), False)
        filename = tempfile.mkstemp('.xls')[1]
        taburet.report.excel.save(report, filename)

        start_file(filename)

    def show_dialog(self, *args):
        from cakeplant.accounts import AccountsForm
        AccountsForm().show()