Instead of importing implicited prices I went the other route, just creating a FX commodity and get historical price automatically through this amazing package: https://gitlab.com/chrisberkhout/pricehist. This, together with the Nordigen API / importer <https://tariochbctools.readthedocs.io/en/latest/importers.html#nordigen> for the the non-main accounts works perfectly and everything is automated now! Next step to make everything run form Fava instead of cli. Great!
Op dinsdag 9 november 2021 om 18:47:56 UTC+1 schreef Joost Brok: > Thanks! I will leave it for now then as fava indeed throws errors and > isn't displaying the right values. I wanted to see if I could use one base > currency but I don't have the further skills to develop an importer for > this to import implicit prices at scale from the CSV. :) > > I appreciate your help. > > Op dinsdag 9 november 2021 om 16:00:59 UTC+1 schreef bl...@furius.ca: > >> This is not going to work. >> Don't do that. >> >> If you're trying to build something that will serialize out, use the >> Posting's price. >> Unfortunately you can't build a Posting that will output a total amount >> at the moment, since that field gets converted on parsing. >> You could always just use good old print()... >> >> >> >> >> On Tue, Nov 9, 2021 at 9:56 AM Joost Brok <joos...@gmail.com> wrote: >> >>> 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.currency >>> return 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: >>> >> units has to be of type 'Amount()' when you create the posting. >>>> It looks like you might have set it to a str. >>>> (Python doesn't offer much help, there's a type validation >>>> function somewhere in beancount.core.data.) >>>> >>>> >>>> On Tue, Nov 9, 2021 at 8:05 AM Joost Brok <joos...@gmail.com> wrote: >>>> >>>>> 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 _process >>>>> if 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 >>>>> >>>>> <https://groups.google.com/d/msgid/beancount/d27098b1-c32a-4ea6-b2c2-0eb07ee2a710n%40googlegroups.com?utm_medium=email&utm_source=footer> >>>>> . >>>>> >>>> -- >>> 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/46412d0c-cd1f-49b0-a2ed-2d8899e4709fn%40googlegroups.com >>> >>> <https://groups.google.com/d/msgid/beancount/46412d0c-cd1f-49b0-a2ed-2d8899e4709fn%40googlegroups.com?utm_medium=email&utm_source=footer> >>> . >>> >> -- 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+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/beancount/ccebaef9-2c8c-4979-8b56-3535930f3634n%40googlegroups.com.