Excellent! The case I had in mind is in an importer, and thus wouldn't work 
because beancount.ingest doesn't support it, but nevertheless, it's great 
to know of a way to  programmatically construct and serialize. Thank you!

On Monday, January 23, 2023 at 4:33:46 PM UTC-8 seia...@gmail.com wrote:

> As Dan said, this is not possible with the beancount v2 data model. It is 
> however possible with autobean.refactor 
> <https://github.com/SEIAROTg/autobean-refactor>, which is not integrated 
> with `beancount.ingest` or `beangulp` but is ready to use if all you are 
> looking for is a way to structurally constructing beancount files and 
> programmatically serializing them into text. Example:
>
> ```
> import io
> from autobean_refactor import models, printer
>
> total_price = models.TotalPrice.from_value(decimal.Decimal(100), 'USD')
> posting = models.Posting.from_value('Assets:Foo', decimal.Decimal(75), 
> 'GBP', price=total_price)
> txn = models.Transaction.from_value(datetime.date(2000, 1, 1), payee=None, 
> narration=None, postings=[posting])
> file = models.File.from_value([txn])
>
> text = printer.print_model(file, io.StringIO()).getvalue()
> ```
>
> I still haven't got around with the documentation so feel free to ping me 
> for any questions.
>
> On Saturday, January 21, 2023 at 11:29:56 AM UTC Red S wrote:
>
>> On 21/01/2023 11:21, Red S wrote: 
>> > I'm probably missing it, but how can I create via code (eg: an 
>> > importer), a posting with a price conversion based on a total price 
>> like 
>> > so: "20 EUR @@ 10 USD" ? 
>>
>> It cannot be done. 
>>
>> It is one of the things that will be resolved in Beancount 3 so there 
>> hasn't been much pressure to fix it in Beancount 2. However, with the 
>> work on version 3 stalled, I'm starting to think to resume actively 
>> working on version 2.
>>  
>> Good to know, thanks! 
>>
>

-- 
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/4d7f94b4-47a0-435e-b6d6-73f801583c89n%40googlegroups.com.

Reply via email to