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.

On Tuesday, 9 November 2021 at 16:00:59 UTC+1 [email protected] wrote:

> 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 <[email protected]> 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 [email protected]:
>>
> 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 <[email protected]> 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 [email protected].
>>>> 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 [email protected].
>>
> 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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/beancount/0016feae-9ccc-4c75-ad02-03920c02e5d7n%40googlegroups.com.

Reply via email to