Exemplo n.º 1
0
def main():
    args = get_argparser().parse_args()
    common.enable_debugging(args.debug)

    GObject.threads_init()

    journal, s = gui.load_journal_and_settings_for_gui()
    klass = AddTransApp
    win = klass(journal, s)
    win.connect("delete-event", Gtk.main_quit)
    GObject.idle_add(win.show_all)
    Gtk.main()
Exemplo n.º 2
0
def main():
    args = get_argparser().parse_args()
    common.enable_debugging(args.debug)

    GObject.threads_init()

    journal, s = gui.load_journal_and_settings_for_gui()
    klass = AddTransApp
    win = klass(journal, s)
    win.connect("delete-event", Gtk.main_quit)
    GObject.idle_add(win.show_all)
    Gtk.main()
Exemplo n.º 3
0
def main(argv):
    p = get_argparser()
    args = p.parse_args(argv[1:])
    ledgerhelpers.enable_debugging(args.debug)

    GObject.threads_init()

    journal, settings = gui.load_journal_and_settings_for_gui(
        price_file_mandatory=True
    )
    klass = UpdatePricesApp if not args.batch else UpdatePricesCommon
    app = klass(journal, settings)
    return app.run()
Exemplo n.º 4
0
def main(argv):
    for datum in "PUBLIC_API_URL OAUTH_API_URL DATATABLES_URL".split():
        if getattr(yahoo_finance.yql, datum).startswith("http:"):
            setattr(yahoo_finance.yql, datum,
                    "https" + yahoo_finance.yql.PUBLIC_API_URL[4:])

    p = get_argparser()
    args = p.parse_args(argv[1:])
    ledgerhelpers.enable_debugging(args.debug)

    GObject.threads_init()

    journal, settings = gui.load_journal_and_settings_for_gui(
        price_file_mandatory=True)
    klass = UpdatePricesApp if not args.batch else UpdatePricesCommon
    app = klass(journal, settings)
    return app.run()
Exemplo n.º 5
0
def main():
    journal, s = gui.load_journal_and_settings_for_gui()
    accts, unused_commodities = journal.accounts_and_last_commodity_for_account(
    )

    saleacct = common.prompt_for_account(
        sys.stdin, sys.stdout, accts,
        "Which account was the sold commodity stored in?",
        s.get("last_sellstock_account", None))
    assert saleacct, "Not an account: %s" % saleacct
    s["last_sellstock_account"] = saleacct

    commissionsaccount = common.prompt_for_account(
        sys.stdin, sys.stdout, accts,
        "Which account to account for commissions?",
        s.get("last_commissions_account", None))
    assert commissionsaccount, "Not an account: %s" % commissionsaccount
    s["last_commissions_account"] = commissionsaccount

    gainslossesacct = common.prompt_for_account(
        sys.stdin, sys.stdout, accts,
        "Which account to credit gains and losses?",
        s.get("last_gainslosses_account",
              "Capital:Recognized gains and losses"))
    assert gainslossesacct, "Not an account: %s" % gainslossesacct
    s["last_gainslosses_account"] = gainslossesacct

    target_amount = common.prompt_for_amount(
        sys.stdin, sys.stdout, "How many units of what commodity?",
        ledger.Amount("$ 1"))
    target_sale_price = common.prompt_for_amount(
        sys.stdin, sys.stdout, "What is the sale price of the commodity?",
        ledger.Amount("$ 1"))
    commission = common.prompt_for_amount(
        sys.stdin, sys.stdout, "What was the commission of the trade?",
        ledger.Amount("$ 1"))

    all_lots = Lots()
    lots_text = subprocess.check_output([
        'ledger', 'bal', '--lots', '--lot-dates', '--lot-prices',
        '--date-format=%Y-%m-%d', '--sort=date',
        '--balance-format=++ %(account)\n%(amount)\n', saleacct
    ])
    all_lots.parse_ledger_bal(lots_text)

    print("=========== Read ===========")
    for l in all_lots:
        print(l)

    lots_produced = all_lots.subtract(target_amount)

    print("========= Computed =========")
    for l in lots_produced:
        print(l)

    print("=========== Left ===========")
    for l in all_lots:
        print(l)

    lines = []
    tpl = "%s {%s}%s @ %s"
    datetpl = ' [%s]'
    for l in lots_produced:
        m = -1 * l.amount
        if m.commodity.details.date:
            datetext = datetpl % m.commodity.details.date.strftime("%Y-%m-%d")
        else:
            datetext = ''
        lines.append((l.account,
                      tpl % (m.strip_annotations(), m.commodity.details.price,
                             datetext, target_sale_price)))
        diff = (l.price - target_sale_price) * l.amount
        lines.append((gainslossesacct, diff))
    totalsale = target_sale_price * sum(l.amount.number()
                                        for l in lots_produced)
    lines.append((saleacct, totalsale - commission))
    lines.append((commissionsaccount, commission))

    lines = journal.generate_record(
        "Sale of %s" % (target_amount),
        datetime.date.today(),
        None,
        "",
        lines,
    )
    print("========== Record ==========")
    print("\n".join(lines))
    save = common.yesno(
        sys.stdin, sys.stderr,
        "Hit ENTER or y to save it to the file, BACKSPACE or n to skip saving: "
    )
    if save:
        journal.add_text_to_file(lines)
Exemplo n.º 6
0
def main():
    journal, s = gui.load_journal_and_settings_for_gui()
    accts, commodities = journal.accounts_and_last_commodity_for_account()

    saleacct = common.prompt_for_account(
        sys.stdin, sys.stdout,
        accts, "Which account was the sold commodity stored in?",
        s.get("last_sellstock_account", None)
    )
    assert saleacct, "Not an account: %s" % saleacct
    s["last_sellstock_account"] = saleacct

    commissionsaccount = common.prompt_for_account(
        sys.stdin, sys.stdout,
        accts, "Which account to account for commissions?",
        s.get("last_commissions_account", None)
    )
    assert commissionsaccount, "Not an account: %s" % commissionsaccount
    s["last_commissions_account"] = commissionsaccount

    gainslossesacct = common.prompt_for_account(
        sys.stdin, sys.stdout,
        accts, "Which account to credit gains and losses?",
        s.get("last_gainslosses_account",
              "Capital:Recognized gains and losses")
    )
    assert gainslossesacct, "Not an account: %s" % gainslossesacct
    s["last_gainslosses_account"] = gainslossesacct

    target_amount = common.prompt_for_amount(
        sys.stdin, sys.stdout,
        "How many units of what commodity?", ledger.Amount("$ 1")
    )
    target_sale_price = common.prompt_for_amount(
        sys.stdin, sys.stdout,
        "What is the sale price of the commodity?", ledger.Amount("$ 1")
    )
    commission = common.prompt_for_amount(
        sys.stdin, sys.stdout,
        "What was the commission of the trade?", ledger.Amount("$ 1")
    )

    all_lots = Lots()
    lots_text = subprocess.check_output([
        'ledger', 'bal',
        '--lots', '--lot-dates', '--lot-prices',
        '--date-format=%Y-%m-%d', '--sort=date',
        '--balance-format=++ %(account)\n%(amount)\n',
        saleacct
    ])
    all_lots.parse_ledger_bal(lots_text)

    print "=========== Read ==========="
    for l in all_lots:
        print l

    lots_produced = all_lots.subtract(target_amount)

    print "========= Computed ========="
    for l in lots_produced:
        print l

    print "=========== Left ==========="
    for l in all_lots:
        print l

    lines = []
    tpl = "%s {%s}%s @ %s"
    datetpl = ' [%s]'
    for l in lots_produced:
        m = -1 * l.amount
        if m.commodity.details.date:
            datetext = datetpl % m.commodity.details.date.strftime("%Y-%m-%d")
        else:
            datetext = ''
        lines.append((
            l.account,
            tpl % (m.strip_annotations(),
                   m.commodity.details.price,
                   datetext,
                   target_sale_price)
        ))
        diff = (l.price - target_sale_price) * l.amount
        lines.append((gainslossesacct, diff))
    totalsale = target_sale_price * sum(
        l.amount.number() for l in lots_produced
    )
    lines.append((saleacct, totalsale - commission))
    lines.append((commissionsaccount, commission))

    lines = journal.generate_record(
        "Sale of %s" % (target_amount),
        datetime.date.today(), None, "",
        lines,
    )
    print "========== Record =========="
    print "\n".join(lines)
    save = common.yesno(
        sys.stdin, sys.stderr,
        "Hit ENTER or y to save it to the file, BACKSPACE or n to skip saving: "
    )
    if save:
        journal.add_text_to_file(lines)