I would start with this line 
<https://github.com/beancount/beancount/blob/cb3526a1af95b3b5be70347470c381b5a86055fe/beancount/query/query_compile.py#L210>
:

class EvalSub(EvalBinaryOp): 

 def __init__(self, left, right): 
   f = lambda x, y: Decimal(x - y)
   super().__init__(f, left, right, Decimal) 

It's in query_compile.py:210. I'd imagine subtraction done via Decimal 
should instead be modified to handle your case. Tests are here 
<https://github.com/beancount/beancount/blob/master/beancount/query/query_compile_test.py>
.

"unsupported operand type(s) for -:" is a python TypeError (not specific to 
Beancount), which is why you didn't find it in the code. I did "git grep 
operand" to find the above.

This would be a good addition, BTW. Thanks for taking a stab at it!


On Tuesday, December 14, 2021 at 1:05:37 PM UTC-8 Ben L wrote:

> Happy to take a stab at it if you want to point where it look. I can't 
> find where in the beancount code to start. Since the error raised is 
> TypeError,  I searched that and for the "unsupported operand" error, but I 
> can't find that in the code. Can you point me to where does the bql stuff 
> for math (add, subtract, etc) get handled?
>
> Thanks,
>
>
>
> On Tuesday, December 14, 2021 at 12:23:50 AM UTC-5 [email protected] wrote:
>
>> I don't think it's supported; you can try adding it (in branch master), 
>> should be easy, just check the currencies match
>>
>>
>>
>> On Mon, Dec 13, 2021 at 9:13 PM Ben L <[email protected]> wrote:
>>
>>> Is there a way to subtract Amounts (same currency) in bql? 
>>>
>>> select cost(position) - value(position);
>>>
>>> I get:
>>>
>>> TypeError: unsupported operand type(s) for -: 'Amount' and 'Amount'
>>>
>>> I can structure the query so the results are only one currency. Is there 
>>> a function that will report an Amount as just a number (lose the currency)? 
>>>
>>> Thanks,
>>>
>>> Ben
>>>
>>> -- 
>>> 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/3bb043d0-e8a9-4cef-ad93-1987100df5ccn%40googlegroups.com
>>>  
>>> <https://groups.google.com/d/msgid/beancount/3bb043d0-e8a9-4cef-ad93-1987100df5ccn%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/0f320fc0-e9ae-4ceb-94ba-43f879d815f0n%40googlegroups.com.

Reply via email to