Beispiel #1
0
    def update_consigment_grid(self):
        self.cons_nb.hide()
        for i in range(self.cons_nb.get_n_pages()):
            self.cons_nb.remove_page(-1)

        dt = self.get_date()
        consigments = get_consignments(dt, self.current_point)

        if not consigments:
            self.cons_are_out_lb.show()
            return

        self.cons_are_out_lb.hide()

        def new():
            return {'id':None, 'count':0, 'price':0.0, '_isnew_':True}

        for i, c in enumerate(consigments):
            sw = gtk.ScrolledWindow()
            sw.set_policy(gtk.POLICY_NEVER, gtk.POLICY_ALWAYS)

            def make_on_commit(cons):
                def inner(dr, row):
                    if '_isnew_' in row:
                        del row['_isnew_']
                        isnew = True
                    else:
                        isnew = False

                    cons.positions[:] = [r for r in cons.positions if '_isnew_' not in r]
                    cons.save()

                    cons.positions.append(new())

                    if isnew:
                        dr.jump_to_new_row(0)

                return inner

            gr = Grid([
                GoodColumn('id', label='Наименование', width=40),
                FloatGridColumn('count', label='Кол-во', width=7, format="%g"),
                FloatGridColumn('price', label='Цена', width=7),
            ])

            dr = GridDirtyRow(gr, make_on_commit(c))
            c.positions.append(new())
            gr.set_model(c.positions, dr)
            sw.add(gr)
            sw.show_all()

            self.cons_nb.append_page(sw, gtk.Label('Накладная #%d' % (i + 1)))

        self.cons_nb.show()
Beispiel #2
0
class TransactionsForm(BuilderAware):
    """glade-file: transactions.glade"""
    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'))

    def show(self):
        self.window.show_all()
        refresh_gui()
        idle(self.tv.set_cursor, len(self.tv.model) - 1, 1)

    def on_window_delete_event(self, *args):
        if self.on_close:
            self.on_close()

    def on_move_btn_clicked(self, btn):
        dlg = create_calendar_dialog(parent=self.window, date=self.date)

        if dlg.run() == gtk.RESPONSE_APPLY:
            dt = dlg.get_date()
            for r in self.check_col.checked_rows:
                if self.date.date() != dt.date():
                    self.transactions.remove(r)
                r.date = dt
                r.save()

            self.check_col.clear()
            self.tv.refresh()

        dlg.destroy()

    def on_delete_btn_clicked(self, btn):
        dlg = gtk.MessageDialog(self.window, gtk.DIALOG_MODAL, gtk.MESSAGE_QUESTION,
            gtk.BUTTONS_YES_NO, "Удалить выделенные проводки?")

        if dlg.run() == gtk.RESPONSE_YES:
            for r in self.check_col.checked_rows:
                self.transactions.remove(r)
                r.delete()

            self.check_col.clear()
            self.tv.refresh()

        dlg.destroy()
Beispiel #3
0
        dr.jump_to_new_row()
        idle(dr.grid.populate, dr.grid.from_row+1, False, (dr.model_row+1, 0))

def on_error(dr, e):
    print e

model = [{'aaa': r, 'bbb': 'wow'} for r in range(50)]
model.append({'aaa':'', 'bbb':'', 'isnew':True})

window = gtk.Window(gtk.WINDOW_TOPLEVEL)
window.set_type_hint(gtk.gdk.WINDOW_TYPE_HINT_DIALOG)
window.set_position(gtk.WIN_POS_CENTER)
window.set_default_size(100, 400)

sw = gtk.ScrolledWindow()
sw.set_policy(gtk.POLICY_NEVER, gtk.POLICY_ALWAYS)
window.add(sw)

table = Grid([IntGridColumn('aaa'), GridColumn('bbb')])
sw.add(table)
dr = DirtyRow(table, on_commit, on_error)
table.set_model(model, dr)
table.show()

w, h = sw.size_request()
window.set_default_size(w, min(max(400, h), 500))
window.show_all()

window.connect('delete-event', lambda *args:gtk.main_quit())

gtk.main()