예제 #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 __init__(self, inout, other_account, date, last_in, last_out, on_close=None):
        BuilderAware.__init__(self, join_to_file_dir(__file__, "transactions.glade"))
        self.on_close = on_close
        self.date = date

        self.transactions = transactions = sorted(other_account.transactions(
            date, date, income=inout, outcome=not inout), key=lambda r: r.num)

        last = last_in if inout else last_out

        def new():
            tran = Transaction()
            tran.what = ''
            tran.who = ''
            tran.date = date

            tran._isnew_ = True

            if inout:
                tran.to_acc = other_account.account_path
            else:
                tran.from_acc = other_account.account_path

            return tran

        def on_commit(dr, row):
            if not hasattr(row, 'num'):
                row.num = last.inc()

            row.save()

            if row.who:
                cached_choices[0].append(unicode(row.who))

            if row.what:
                cached_choices[1].append(unicode(row.what))

            if hasattr(row, '_isnew_'):
                del row._isnew_
                transactions.append(new())
                dr.jump_to_new_row(2)

        def on_error(dr, e):
            show_message(self.sw, str(e), 5000)

        def on_check(checks):
            for k, v in checks.iteritems():
                if k and v:
                    self.delete_btn.set_sensitive(True)
                    self.move_btn.set_sensitive(True)
                    return

            self.delete_btn.set_sensitive(False)
            self.move_btn.set_sensitive(False)


        choices = [(r._id, r.name) for _, r in accounts_walk(AccountsPlan().accounts(), True)]

        self.check_col = CheckBoxColumn(transactions, on_check)

        columns = [
            self.check_col,
            IntGridColumn('num', label='№', editable=False, width=3),
            AccountColumn('from_acc' if inout else 'to_acc', choices, label='Счет', width=4),
            AutocompleteColumn('who', get_who_choice(), label='Контрагент', width=15),
            FloatGridColumn('amount', label='Сколько', width=7),
            AutocompleteColumn('what', get_what_choice(), label='За что', width=10),
        ]

        self.tv = Grid(columns)
        self.sw.add(self.tv)

        transactions.append(new())
        self.tv.set_model(transactions, DirtyRow(self.tv, on_commit, on_error))
        self.tv.show_all()

        self.window.set_title(('Приход за ' if inout else 'Расход за ') + date.strftime('%d.%m.%Y'))