Closed hpoon closed 5 years ago
If the currency has never been used in gnucash, it does not exist in the database of the book.
You can create it by using the function create_currency_from_ISO
https://piecash.readthedocs.io/en/master/api/piecash.core.factories.html#piecash.core.factories.create_currency_from_ISO
And then add the currency to the book and save the book or just use the currency in a new Price object, add the Price object to the book nd save the book.
Does that work for you?
In my case, I'm looking to add a specific price, so I think I want the second option of adding the Price object to the book since that will let me control the pricing information.
OK what you said makes sense. This worked.
new_book = piecash.create_book("./book.gnucash")
cad = create_currency_from_ISO("CAD")
usd = create_currency_from_ISO("USD")
price = Price(commodity=cad,
currency=usd,
date=datetime.date.today(),
value=2,
type="unknown",
source="whatever")
new_book.add(price)
new_book.save()
I'm trying to add currency conversion information to a new book. There aren't any transactions directly converting between two currencies, but I'd like to add a currency conversion value between the two currencies as different accounts use different currency units.
How do I add these currency conversions to a new book? I've tried doing this as a commodity, but they aren't showing up. The commodity I tried to add is following the currency namespace. Am I supposed to add a "Price" object instead?