Hello everyone, I'm really learning beancount and building my importers. We're an international family so the multi-currency support trough fava makes our life easier to keep track of expenses against our two base account currencies. After doing some research I found out I can simplify currency reporting quite a bit by adding implicit prices. One of our main banks exposes the following fields in their export csv: amount, currency, local amount, local currency. I;m trying to write an importer with explicit prices (e.g. Expenses:Foo 100 GBP @@ 110 EUR) however I'm having trouble using the data.Posting function to validate it.from my importers/bank_name.py:def implicit_amount(self, base_amount, local_amt, local_cur):implicit_formatted = "" + local_amt + local_cur + " @@ " + amount + self.currency # try to see if we hardcode the string...return amount.Amount(D(base_amount), self.currency) if (base_amount, self.currency) == (local_amt, local_cur) else implicit_formatted[....]amount = self.implicit_amount(row['Amount'], row['Local amount'], row['Local currency'])[....]postings = [data.Posting(self.account, amount, None, None, None, None),]Gives..--...r.py", line 31, in _processif entry.postings[0].units.number > 0:AttributeError: 'str' object has no attribute 'number'
How do I build an importer that supports implicit prices? I couldn't find any example/existing importers that support that and where I could re-use code from.Thanks a lot!
You received this message because you are subscribed to the Google Groups "Beancount" group.
To unsubscribe from this group and stop receiving emails from it, send an email to beancount+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/beancount/d27098b1-c32a-4ea6-b2c2-0eb07ee2a710n%40googlegroups.com.
Thanks for your reply! After fiddling around and looking at the docs it seemed only the currency arg is not validated and allows any string. Also number couldn't been set to None. So I'm now using a creative solution to put the base decimal amount in number (e.g. -139.99)and the rest of the string in currency (e.g. EUR @@ -119.04 GBP). It's a bit of a hack but works for now (using amount.Amount(D(local_amt), implicit_formatted).Hacky solution:def implicit_amount(self, base_amt, local_amt, local_cur):implicit_formatted = local_cur + " @@ " + str(D(base_amt)) + " " + self.currencyreturn amount.Amount(D(base_amt), self.currency) if (base_amt, self.currency) == (local_amt, local_cur) else amount.Amount(D(local_amt), implicit_formatted)From the docs:beancount.core.amount.Amount.__new__(cls, number, currency)Args: number: A string or Decimal instance. Will get converted automatically. currency: A string, the currency symbol to use. """Any thoughts on making it less hacky and more in line with the api? :)Op dinsdag 9 november 2021 om 14:19:41 UTC+1 schreef bl...@furius.ca:
To view this discussion on the web visit https://groups.google.com/d/msgid/beancount/46412d0c-cd1f-49b0-a2ed-2d8899e4709fn%40googlegroups.com.
Beancount's bean-price tool fetches
prices and addresses other workflow concerns in a Beancount-specific manner,
generally requiring a Beancount file as input.
AFAICT it's very similar in intent to beanprice:
With more active maintenance (this is what's needed for beanprice). I spent time trying to figure out how to contact the author, creating an account on gitlab, etc. couldn't figure out how to log a ticket. (gitlab seems a bit more closed than github)
To view this discussion on the web visit https://groups.google.com/d/msgid/beancount/ccebaef9-2c8c-4979-8b56-3535930f3634n%40googlegroups.com.