How to use the piecash.Commodity.mnemonic function in piecash

To help you get started, we’ve selected a few piecash examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github sdementen / piecash / tests / test_model_core.py View on Github external
def test_commodities(self, session):
        # no commodities in an empty gnucash file
        commodities = session.query(Commodity.mnemonic).all()
        assert commodities == [("EUR",)]
github MisterY / gnucash-portfolio / gnucash_portfolio / lib / securities.py View on Github external
def get_all(self):
        """ Loads all non-currency commodities, assuming they are stocks. """
        query = (
            self.__get_base_query()
            .order_by(Commodity.mnemonic)
        )
        return query.all()
github MisterY / gnucash-portfolio / gnucash_portfolio / currencies.py View on Github external
def get_by_symbol(self, symbol: str) -> Commodity:
        """ Loads currency by symbol """
        assert isinstance(symbol, str)

        query = (
            self.currencies_query
                .filter(Commodity.mnemonic == symbol)
        )
        return query.one()
github MisterY / gnucash-portfolio / gnucash_portfolio / securitiesaggregate.py View on Github external
def get_stocks(self, symbols: List[str]) -> List[Commodity]:
        """ loads stocks by symbol """
        query = (
            self.query
            .filter(Commodity.mnemonic.in_(symbols))
        ).order_by(Commodity.namespace, Commodity.mnemonic)
        return query.all()
github MisterY / gnucash-portfolio / gnucash_portfolio / securitiesaggregate.py View on Github external
def find(self, search_term: str) -> List[Commodity]:
        """ Searches for security by part of the name """
        query = (
            self.query
            .filter(Commodity.mnemonic.like('%' + search_term + '%') |
                    Commodity.fullname.like('%' + search_term + '%'))
        )
        return query.all()
github sdementen / piecash / examples / read_currencies_sa.py View on Github external
session = book.session

    # query example:
    #accountsFiltered = session.query(Account).filter(Account.name >= "T").all()
    # SQLAlchemy methods: count, first, all, one...

    # Get all the currencies in the book (i.e. for update).
    print("All currencies used in the book:")
    currencies = session.query(Commodity).filter(Commodity.namespace == "CURRENCY").all()
    for c in currencies:
        print(c)

    # Accessing individual records.

    print("\nSelected single currency details (" + symbol + "):")
    cdty = session.query(Commodity).filter(Commodity.namespace == "CURRENCY", Commodity.mnemonic == symbol).first()

    # Accessing attributes of a commodity.
    print("Commodity namespace={cdty.namespace}\n"
        "          mnemonic={cdty.mnemonic}\n"
        "          cusip={cdty.cusip}\n"
        "          fraction={cdty.fraction}".format(cdty=cdty))

    # Loop through the existing commodity prices.
    # This can be used to fetch the points for a price graph.
    print("\nHistorical prices:")
    for pr in cdty.prices:
        print("Price date={pr.date}"
            "      value={pr.value} {pr.currency.mnemonic}/{pr.commodity.mnemonic}".format(pr=pr))
github MisterY / gnucash-portfolio / gnucash_portfolio / lib / securities.py View on Github external
def get_by_symbol(self, symbol: str) -> List[Commodity]:
        """ Returns all commodities with the given symbol """
        query = (
            self.__get_base_query()
            .filter(Commodity.mnemonic == symbol)
        )
        return query.all()
github MisterY / gnucash-portfolio / gnucash_portfolio / securitiesaggregate.py View on Github external
def get_stocks(self, symbols: List[str]) -> List[Commodity]:
        """ loads stocks by symbol """
        query = (
            self.query
            .filter(Commodity.mnemonic.in_(symbols))
        ).order_by(Commodity.namespace, Commodity.mnemonic)
        return query.all()
github MisterY / gnucash-portfolio / gnucash_portfolio / currencies.py View on Github external
def get_book_currencies(self) -> List[Commodity]:
        """ Returns currencies used in the book """
        query = (
            self.currencies_query
                .order_by(Commodity.mnemonic)
        )
        return query.all()
github MisterY / gnucash-portfolio / app / controllers / currency_controller.py View on Github external
def __search(svc: BookAggregate, model: CurrencySearchModel):
    """ performs the search """
    if not model.currency:
        return None

    query = svc.currencies.currencies_query_sorted

    if model.currency:
        query = query.filter(Commodity.mnemonic == model.currency)

        # TODO if not the main currency, load exchange rates and display chart
        if model.ref.currencies != svc.currencies.get_default_currency():
            print("not the default currency. load data.")

    return query.one()