Exemplo n.º 1
0
def import_files(args):
    global import_thread
    if import_thread is None:
        import_thread = bucks.tximport.ScanInboxThread()
    if not args:
        acc = input("Account?")
        file_name = input("File name?")
        args = (acc + ":" + file_name, )
    for arg in args:
        if isinstance(arg, str):
            acc, file_name = arg.split(':', 2)
        elif isinstance(arg, (list, tuple)):
            acc, file_name = arg
        else:
            print("Cannot import " + arg)
            continue
        if not gripe.exists(file_name):
            print("File '%s' does not exist.".format(file_name))
            continue
        account = Account.by("acc_name",
                             acc) if not isinstance(acc, Account) else acc
        if account is None:
            print("Account '%s' does not exist.".format(acc))
            continue
        import_thread.addfile(account, file_name)
    return True
Exemplo n.º 2
0
 def __init__(self, parent):
     super(TransactionTable, self).__init__(parent)
     layout = QVBoxLayout(self)
     l = QHBoxLayout()
     l.addWidget(QLabel("Account: "))
     self.account_combo = QComboBox()
     self.account_combo.setModel(
         grumpy.model.ListModel(Account.query(keys_only=False), "acc_name"))
     self.account_combo.activated[int].connect(self.select_account)
     l.addWidget(self.account_combo)
     self.import_button = QPushButton("Import")
     self.import_button.clicked.connect(self.import_transactions)
     l.addWidget(self.import_button)
     l.addStretch(1)
     l.addWidget(QLabel("Current Balance: "))
     self.balance_label = QLabel("1000000.00")
     l.addWidget(self.balance_label)
     layout.addLayout(l)
     self.table = grumpy.view.TableView(None, [
         "date", "type", "credit", "debit", "description",
         "+category.cat_name", "+project.proj_name", "+contact.contact_name"
     ], self)
     self.table.setMinimumSize(800, 400)
     layout.addWidget(self.table)
     self.setLayout(layout)
     self.table.objectSelected.connect(parent.set_instance)
     QCoreApplication.instance().importer.imported.connect(self.refresh)
     QTimer.singleShot(0, lambda: self.select_account(0))
Exemplo n.º 3
0
 def account(self, account=None):
     if not self._account:
         accounts = Account.get_accounts()
         choices = {}
         num = 1
         for acc in accounts:
             if not account or acc.acc_name.upper().startswith(
                     account.upper()):
                 choices[num] = acc
                 num += 1
         if not choices:
             self._account = None
         elif len(choices) == 1:
             self._account = choices[1]
         else:
             for ix in range(1, num):
                 print("{0:3d}. {1}".format(ix, choices[ix].acc_name))
             ix = None
             while ix is None:
                 ix = input("? ")
                 if ix == 'b':
                     ix = -1
                 else:
                     try:
                         ix = int(ix)
                     except ValueError:
                         ix = -1
                     if (ix > 0) and ix not in choices:
                         ix = None
             if ix <= 0:
                 self._account = None
             else:
                 self._account = choices[ix]
     return self._account
Exemplo n.º 4
0
 def __init__(self, account, file_name):
     super(PaypalReader, self).__init__(account, file_name)
     self.headerline = True
     assert self.counter
     self.counter: Account = Account.by("acc_name", self.counter)
     assert self.counter
     self.currency = self.counter.currency
     self.last_tx = None
Exemplo n.º 5
0
 def __init__(self, tab):
     super(InstitutionForm, self).__init__(None, Institution)
     self.addProperty(Institution, "inst_name", 0, 1)
     self.addProperty(Institution, "description", 1, 1)
     self.acc_label = QLabel("Accounts:")
     self.addWidget(self.acc_label, 2, 1, 1, 1, Qt.AlignTop)
     self.accounts = grumpy.view.TableView(Account.query(keys_only=False),
                                           ["acc_name", "description"])
     self.addWidget(self.accounts, 2, 2)
Exemplo n.º 6
0
def list_accounts(dummy=None):
    def list_account(acc):
        print("{0:30s}|{1:>10s}|{2:>10s}|{3:>10s}|".format(
            acc.acc_name, amt(acc.total_debit), amt(acc.total_credit),
            amt(acc.total)))

    with gripe.db.Tx.begin():
        accounts = Account.get_accounts()
        if accounts:
            table_header(("Account", 30), ("Debit", 10), ("Credit", 10),
                         ("Total", 10))
            total = Account(parent=None,
                            acc_name='Total',
                            total_debit=0.0,
                            total_credit=0.0,
                            total=0.0)
            for account in accounts:
                list_account(account)
                total.total_debit += account.total_debit
                total.total_credit += account.total_credit
                total.total += account.total
            list_account(total)
    return True
Exemplo n.º 7
0
 def accounts(inst, accounts):
     for account in accounts:
         name = account.get("acc_name")
         if name:
             acc = Account(parent=inst, acc_name=name, acc_nr=account.get("acc_nr"),
                           description=account.get("description", name), importer=account.get("importer"))
             acc.put()
             if "opening_date" in account or "opening_balance" in account:
                 acc.set_opening_balance(account.get("opening_balance"), account.get("opening_date"))
Exemplo n.º 8
0
 def start(self, cmdline):
     self.splash.show()
     self.processEvents()
     with gripe.db.Tx.begin():
         ok = True
         if cmdline.clear:
             gripe.db.Tx.reset_schema(True)
         if Account.query().get() is None:
             if cmdline.schema:
                 bucks.schema.SchemaImporter.import_file(cmdline.schema)
                 self.processEvents()
             if not cmdline.schema or Account.query().get() is None:
                 wiz = bucks.app.wizard.FirstUse()
                 ok = wiz.exec_()
         if cmdline.imp:
             acc, file_name = cmdline.imp.split(':', 2)
             account = Account.by("acc_name", acc)
             assert account
             self.importer.execute(account, file_name)
         if ok:
             self.main_window = MainWindow(self)
     self.processEvents()
     t = grumpy.bg.bg.BackgroundThread.get_thread()
     t.statusMessage.connect(self.status_message)
     t.progressInit.connect(self.progress_init)
     t.progressUpdate.connect(self.progress)
     t.progressEnd.connect(self.progress_done)
     t.jobStarted.connect(self.job_started)
     t.jobFinished.connect(self.job_finished)
     t.jobError.connect(self.job_error)
     t.add_plugin(bucks.tximport.ScanInbox)
     t.start()
     self.processEvents()
     self.splash.finish(self.main_window)
     self.splash = None
     if self.main_window is not None:
         self.main_window.show()
Exemplo n.º 9
0
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument("-c",
                        "--clear",
                        action="store_true",
                        help="Erase all data")
    parser.add_argument("-s",
                        "--schema",
                        type=str,
                        help="Use the given file as the initial schema")
    parser.add_argument("-i",
                        "--imp",
                        type=str,
                        nargs="+",
                        help="Import the given transactions file")
    parser.add_argument("commands",
                        type=str,
                        nargs="*",
                        help="Commands string")

    cmdline = parser.parse_args()

    ok = True
    with gripe.db.Tx.begin():
        if cmdline.clear:
            gripe.db.Tx.reset_schema(True)
        if Account.query().get() is None:
            if cmdline.schema:
                bucks.schema.SchemaImporter.import_file(cmdline.schema)
            # else:
            #     wizard = bucks.wizard.FirstUse()
            #     ok = wizard.exec_()
        if cmdline.imp:
            import_files(cmdline.imp)

    if ok:
        global import_thread
        if import_thread is None:
            import_thread = bucks.tximport.ScanInboxThread()
        readline.set_pre_input_hook(pre_input_hook)
        try:
            mainloop(cmdline.commands)
        except Exception as e:
            traceback.print_exc()
Exemplo n.º 10
0
 def set_account(self, acc_name):
     account = self._accounts.get(acc_name)
     if account is None:
         account = Account.by("acc_name", acc_name)
         if account is not None:
             self._accounts[acc_name] = account
     if account is not None:
         self.acc_name = acc_name
         self.initial = os.path.join(self.data_dir, acc_name, "initial")
         gripe.mkdir(self.initial)
         self.inbox = os.path.join(self.data_dir, acc_name, "inbox")
         gripe.mkdir(self.inbox)
         self.queue = os.path.join(self.data_dir, acc_name, "queue")
         gripe.mkdir(self.queue)
         self.done = os.path.join(self.data_dir, acc_name, "done")
         gripe.mkdir(self.done)
         self.errors = os.path.join(self.data_dir, acc_name, "error")
         gripe.mkdir(self.errors)
     return account is not None
Exemplo n.º 11
0
    def __init__(self, parent):
        super(AccountTab, self).__init__(parent=parent)
        layout = QVBoxLayout(self)

        q = Account.get_accounts()

        self.table = grumpy.view.TableView(q, [
            "acc_name", "description", "current_balance",
            grumpy.model.TableColumn("total_debit"),
            grumpy.model.TableColumn("total_credit")
        ],
                                           kind=Account)
        self.table.setMinimumSize(400, 300)
        layout.addWidget(self.table)
        self.form = AccountForm(self)
        layout.addWidget(self.form)
        self.setLayout(layout)
        self.table.objectSelected.connect(self.form.set_instance)
        self.form.refresh.connect(self.table.refresh)
        QCoreApplication.instance().importer.imported.connect(
            self.table.refresh)
Exemplo n.º 12
0
 def get_reader(self, account, file_name):
     if not isinstance(account, Account):
         account = Account.by("acc_name", account)
     reader = gripe.resolve(account.importer, Reader)(account, file_name)
     return reader