Re: Cryptocurrencies transactions that are exchanges (cost basis)

2024-03-17 Thread CD
Another question on your two examples...

If it's set to FIFO...

What if you have multiple Assets accounts for ETH?

For example - if you had 100 ETH in Assets:Coinbase:ETH and another 100 ETH 
in Assets:BItstamp:ETH  would the transactions below  still pull FIFO from 
both of those accounts or do they all have to be on the same account?

https://github.com/ericaltendorf/magicbeans/blob/master/data/magicbeans_example.beancount#L101
2020-06-10 * "Exchange 20. ETH for 4943.2960 USDT"
  Assets:Account:USDT  4943.296022386568059164501299 USDT {1.0006 USD}
  Assets:Account:ETH -20 ETH {} @ 247.3131 USD
  Income:CapGains


On Sunday, March 17, 2024 at 1:35:40 PM UTC-4 erical...@gmail.com wrote:

> TLDR: it's a hack to try to get beancount to carry cost basis along if 
> that position is ever transferred to another account.
>
> There have been a bunch of discussions about this and to be honest, I'm 
> not 100% confident in the current state of affairs.
>
> In general, beancount is not very reliable about carrying cost basis along 
> with transfers.  Asset transfers are a very uncommon pattern in general 
> beancount usage, it seems of concern mostly to crypto traders (who 
> frequently transfer between exchanges and wallets).  So it's not a 
> well-exercised or supported functionality.  See e.g.
> https://github.com/beancount/beancount/issues/476
> https://groups.google.com/g/beancount/c/WF3Ta9yVQVo
> (and many more crypto discussions on the list)
>
> There have been a couple workarounds discussed.  It looks like what I 
> eventually got working for me was inserting an empty cost spec:
>
> https://github.com/ericaltendorf/magicbeans/blob/4a0856aa0558abb5dc1b78123ea4feff263646cd/src/magicbeans/common.py#L102
>
> It is possible this depends on this tweak I made to beancount core:
>
> https://github.com/beancount/beancount/compare/master...ericaltendorf:beancount:cost-transfer
>
> However like I said I have seen inconsistent behavior and so I don't have 
> confidence in my mental model of what beancount is actually doing here.  It 
> would be really nice to get this rigorously understood and supported.
>
>
>
> On Sun, Mar 17, 2024 at 8:44 AM CD  wrote:
>
>> Thank you for this.
>>
>> I figured out the USD price importing (I downloaded price histories from 
>> Yahoo and put them all in a folder that my script references) but I am not 
>> clear on what the empty {} does
>>
>>
>> I understand if I want to book the price I purchased at in the database I 
>> want to use something like this...
>>
>>  Assets:XRP   1107.10301990 XRP {0.66587 USD}
>>
>> But in your example
>>
>> 2020-04-10 * "Exchange 1483.9889 USDT for 9.4000 ETH"
>>   Assets:Account:ETH  9.4 ETH {158.1869 USD}
>>   Assets:Account:USDT  -1483.92235528942115768463 USDT {} @ 1.0020 USD
>>   Income:CapGains
>>
>> What does the  USDT {} @ 1.0020 USD part do?
>>
>>
>> Thank you for the reply.  I saw that you replied in the other thread, I 
>> will be checking that out in the next few days once I get this sorted.
>> On Saturday, March 16, 2024 at 6:16:35 PM UTC-4 erical...@gmail.com 
>> wrote:
>>
>>> All of the following is not tax or accounting advice, but simply my 
>>> understanding.  Feedback from other beancounters would be welcome.
>>>
>>> I think you have to figure out the USD values yourself, based on your 
>>> assessment of the FMV.  Here's some examples of how I structure exchanges.  
>>> (Reminder: this is a generated file with fake data)
>>>
>>>
>>> https://github.com/ericaltendorf/magicbeans/blob/master/data/magicbeans_example.beancount#L69
>>> 2020-04-10 * "Exchange 1483.9889 USDT for 9.4000 ETH"
>>>   Assets:Account:ETH  9.4 ETH {158.1869 USD}
>>>   Assets:Account:USDT  -1483.92235528942115768463 USDT {} @ 1.0020 
>>> USD
>>>   Income:CapGains
>>>
>>>
>>> https://github.com/ericaltendorf/magicbeans/blob/master/data/magicbeans_example.beancount#L101
>>> 2020-06-10 * "Exchange 20. ETH for 4943.2960 USDT"
>>>   Assets:Account:USDT  4943.296022386568059164501299 USDT {1.0006 USD}
>>>   Assets:Account:ETH -20 ETH {} @ 247.3131 
>>> USD
>>>   Income:CapGains
>>>
>>> I do this in my importers.  For example, the coinbase pro importer, when 
>>> a transaction has an increase leg, looks up the USD price of the increasing 
>>> currency:
>>>
>>> https://github.com/ericaltendorf/magicbeans/b

Re: Cryptocurrencies transactions that are exchanges (cost basis)

2024-03-17 Thread CD
Thank you for this.

I figured out the USD price importing (I downloaded price histories from 
Yahoo and put them all in a folder that my script references) but I am not 
clear on what the empty {} does


I understand if I want to book the price I purchased at in the database I 
want to use something like this...

 Assets:XRP   1107.10301990 XRP {0.66587 USD}

But in your example

2020-04-10 * "Exchange 1483.9889 USDT for 9.4000 ETH"
  Assets:Account:ETH  9.4 ETH {158.1869 USD}
  Assets:Account:USDT  -1483.92235528942115768463 USDT {} @ 1.0020 USD
  Income:CapGains

What does the  USDT {} @ 1.0020 USD part do?


Thank you for the reply.  I saw that you replied in the other thread, I 
will be checking that out in the next few days once I get this sorted.
On Saturday, March 16, 2024 at 6:16:35 PM UTC-4 erical...@gmail.com wrote:

> All of the following is not tax or accounting advice, but simply my 
> understanding.  Feedback from other beancounters would be welcome.
>
> I think you have to figure out the USD values yourself, based on your 
> assessment of the FMV.  Here's some examples of how I structure exchanges.  
> (Reminder: this is a generated file with fake data)
>
>
> https://github.com/ericaltendorf/magicbeans/blob/master/data/magicbeans_example.beancount#L69
> 2020-04-10 * "Exchange 1483.9889 USDT for 9.4000 ETH"
>   Assets:Account:ETH  9.4 ETH {158.1869 USD}
>   Assets:Account:USDT  -1483.92235528942115768463 USDT {} @ 1.0020 USD
>   Income:CapGains
>
>
> https://github.com/ericaltendorf/magicbeans/blob/master/data/magicbeans_example.beancount#L101
> 2020-06-10 * "Exchange 20. ETH for 4943.2960 USDT"
>   Assets:Account:USDT  4943.296022386568059164501299 USDT {1.0006 USD}
>   Assets:Account:ETH -20 ETH {} @ 247.3131 USD
>   Income:CapGains
>
> I do this in my importers.  For example, the coinbase pro importer, when a 
> transaction has an increase leg, looks up the USD price of the increasing 
> currency:
>
> https://github.com/ericaltendorf/magicbeans/blob/master/src/magicbeans/importers/coinbasepro.py#L238
> See also the gateio importer:
>
> https://github.com/ericaltendorf/magicbeans/blob/master/src/magicbeans/importers/gateio.py#L265
> I am sad I never had the time to clean all this up and create an elegant 
> and consistent code path for handling both of these. :(
>
> Regarding prices, I wrote my own code for price fetching (rationale in the 
> header of the file):
>
> https://github.com/ericaltendorf/magicbeans/blob/master/src/magicbeans/prices.py
>
> Then for tax reporting you want to report the value of the proceeds in 
> USD.  Take a look at the last entry in the Disposals table on page 5 of the 
> example PDF report: 
> https://github.com/ericaltendorf/magicbeans/blob/master/data/magicbeans_example.pdf
>   
> There was an exchange, where there was a disposal of 20 ETH and an 
> acquisition of 4943.2960 USDT, but the "proceeds" (i.e., USD value on which 
> taxes might be assessed) was 4946.26 (because 1 USDT ~= 1.0006 USD at the 
> time).
>
> hope this helps. i am sorry i haven't had a chance to get back to you on 
> the other thread yet.
>
>
> On Sat, Mar 16, 2024 at 12:45 PM CD  wrote:
>
>> Two random transactions that I created based from an old Poloniex export 
>> a friend gave me...
>>
>> 2018-01-03 * "Crypto Buy" "Order number: x"
>>   Assets:DGB   5171.00018694 DGB @ 0.0447 BTC
>>   Assets:BTC  -0.02317230 BTC
>>   Expenses:TradingFees12.95990021 DGB @ 0.0447 BTC
>>
>> 2018-01-08 * "Crypto Sell" "Order number: xx"
>>   Assets:ETC  -13.30376940 ETC @ 0.00225500 BTC
>>   Assets:BTC   0.02995500 BTC
>>   Expenses:TradingFees0.4499 BTC
>>
>>
>> Poloniex at the time only had transactions made between different 
>> cryptocurrencies, so there are no USD trades.  Everything is priced in one 
>> half of the pair  ie BTC/ETC DGB/BTC in the above examples.
>>
>> How does one go about making everything into USD in reporting  (cost 
>> basis, etc)
>>
>> I'm baffled.
>>
>> If I set price directives for the different cryptos before each 
>> transaction will that do it?  Or am I going about it all wrong?
>>
>> There doesn't seem to be a way to do double @ either.  So for example I 
>> couldn't do  5171.00018694 DGB @ 0.0447 BTC @ 21000.00 USD  right?
>>
>> Is there some way to set up the cost basis in USD in the initial 
>> transaction or using price directives?
>>
>>
>> -- 
>> You received this message because you a

Cryptocurrencies transactions that are exchanges (cost basis)

2024-03-16 Thread CD
Two random transactions that I created based from an old Poloniex export a 
friend gave me...

2018-01-03 * "Crypto Buy" "Order number: x"
  Assets:DGB   5171.00018694 DGB @ 0.0447 BTC
  Assets:BTC  -0.02317230 BTC
  Expenses:TradingFees12.95990021 DGB @ 0.0447 BTC

2018-01-08 * "Crypto Sell" "Order number: xx"
  Assets:ETC  -13.30376940 ETC @ 0.00225500 BTC
  Assets:BTC   0.02995500 BTC
  Expenses:TradingFees0.4499 BTC


Poloniex at the time only had transactions made between different 
cryptocurrencies, so there are no USD trades.  Everything is priced in one 
half of the pair  ie BTC/ETC DGB/BTC in the above examples.

How does one go about making everything into USD in reporting  (cost basis, 
etc)

I'm baffled.

If I set price directives for the different cryptos before each transaction 
will that do it?  Or am I going about it all wrong?

There doesn't seem to be a way to do double @ either.  So for example I 
couldn't do  5171.00018694 DGB @ 0.0447 BTC @ 21000.00 USD  right?

Is there some way to set up the cost basis in USD in the initial 
transaction or using price directives?


-- 
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/a537f66b-f03b-4aac-bd50-deda8584a179n%40googlegroups.com.


Bean-File not placing files in "documents" folder

2024-03-04 Thread CD
I just tried the OFX importer for the first time.

My directory looks like this:

I have a root directory (x family folder)

Under that I have...
Downloads
documents
importers
config.py
mybcfile.beancount

when i run bean-file the folders and documents are being placed in this 
root directory X family (folder).

So it appears like this...

Downloads
documents
importers
Liabilities (and all the subdirectories)
config.py
mybcfile.beancount

How do I adjust this so that it goes into the documents folder like in the 
examples?


-- 
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/33679e68-af08-4d4d-a7d1-252cefe03d0en%40googlegroups.com.


Re: Mileage Standard IRS deduction - how to record

2024-03-03 Thread CD
OK.  I think I have this figured out.  

Unfortunately I don't think the deferred method you are suggesting will 
work well in the US, because from my understanding it's used as an expense 
to reduce overall income (which in turn reduces your taxes).

So I am going with something like this...

2017-01-01 open Equity:Miles
2017-01-01 open Expenses:Consulting:Mileage

2024-01-01 price MILES 00.67 USD ;IRS standard mileage deduction 2024

2024-01-04 * "XYZ Company Paid Invoice" "Completion of Project XXX"
; Project for XYZ company at Site 
  Assets:Banking:MyBank   1000.00 USD 
  Income:Consulting:XYZ -1000.00 USD
  Expenses:Consulting:Mileage 227.8 MILES
  Equity:Miles-227.8 MILES

Then in FAVA I can then click "Converted to USD" to see the mileage expense 
in USD and also removed from my net income on the Income Statement.

Or I can click on Units and see it separated out as MILES.


On Thursday, February 29, 2024 at 6:32:21 AM UTC-5 char...@gmail.com wrote:

> On Wednesday, February 28, 2024 at 7:33:42 PM UTC+1 CD wrote:
>
> Thanks for taking the time to do this!
>
> It does make sense.
>
> I don't fully understand the "pad" directive yet.  I guess I do 
> theoretically - it's sort of like creating an opening balance?  But in 
> practice it seems confusing to me.  
>
>
>
> It just saves you some manual calculation. 
>
> In my new example 
> <https://colab.research.google.com/drive/1FRttWZWgphX5SSZnViF5GlV6FDPGhbbT> 
> it will automatically add the following entry. I
>
> 2021-03-02 P "(Padding inserted for Balance of 0 USD for difference 10 
> USD)" Assets:Deffered-Tax:Y20 10 USD Income:Tax-Refund:Car-Mileage -10 USD
>  
>

-- 
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/817ff351-4bf9-413d-8f69-578a48ba3ce3n%40googlegroups.com.


Re: Mileage Standard IRS deduction - how to record

2024-02-28 Thread CD
Thanks for taking the time to do this!

It does make sense.

I don't fully understand the "pad" directive yet.  I guess I do 
theoretically - it's sort of like creating an opening balance?  But in 
practice it seems confusing to me.  

Everything else though makes sense to me, but couldn't the actual rate be 
used and be put in as an expense, since it's going to be removed from the 
gross income (I think - I'm not an accountant either).  

I guess that would make it tricky how to book them though and income would 
seem necessary no matter what.


I'm going to play around with what you wrote and will reply more soon.

Thanks again.

On Wednesday, February 28, 2024 at 7:03:57 AM UTC-5 char...@gmail.com wrote:

> Hi,
>
> disclaimer: I am not an accountant, I am not from the US.
>
> But let us just think together.
>
> The only reason you would want to use beancount to record the IRS 
> deductible mileage instead of just writing it somewhere on a paper is to be 
> able to track the future tax refund.
>
> So, this is how I would do it:
>
> 
>
> ; https://groups.google.com/g/beancount/c/oBLRF71jDqY
>
>
> 2020-01-01 commodity MILE
>
> 2020-01-01 commodity USD
>
> 2020-01-01 open Assets:Bank:Checking USD
> 2020-01-01 open Assets:Deffered-Tax
>
> 2020-01-01 open Income:Tax-Refund:Car-Mileage 
>
> 2020-01-02 * "Driving car somewhere, which is tax deductible"
>   ; I think you need to put here not the actual rate (e.g. 65.5 
> cents/mile), but expected tax return you will get. Let us assume 0.3 
> USD/mile
>   ; also cgeck this 
> https://www.accaglobal.com/gb/en/student/exam-support-resources/fundamentals-exams-study-resources/f7/technical-articles/deferred-tax.html
>  
>  
>   ; and this ; and this 
> https://getswipe.in/blog/post/concept-of-deferred-tax-and-its-presentation-in-financial-statements
>  
>  
>   Income:Tax-Refund:Car-Mileage   -100 MILE @   0.3 USD 
>   Assets:Deffered-Tax  30 USD
>
> 2020-03-02 * "Tax authorities" "Tax refund received"
>   Assets:Bank:Checking 40 USD
>   Assets:Deffered-Tax  -40 USD
>
> ; You will probably never guess the tax return 100% correctly, so you will 
> need to pad it
> 2020-03-02 pad Assets:Deffered-Tax Income:Tax-Refund
> 2020-03-03 balance Assets:Deffered-Tax 0 USD  
>
> ;=== 
>
> Does it make sense?
>
> On Monday, February 26, 2024 at 10:57:30 PM UTC+1 CD wrote:
>
>> I would have thought I would have found something on this from a search, 
>> but I haven't.
>>
>> What is the best practice for recording mileage on business trips and 
>> what are the accounts that are used for this if you are using the IRS 
>> standard deduction per mile?
>>
>> Does a new commodity/currency need to be created for this?
>>
>

-- 
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/c74d0afe-f0db-4960-9d25-a30a0354a0cbn%40googlegroups.com.


Re: Seeking beta-testers/devs for crypto tax tools

2024-02-28 Thread CD
Thank you.  I think I have the CoinbaseImporter set up properly but it is 
saying it can't import beangulp.  


On Sunday, February 25, 2024 at 1:04:42 PM UTC-5 erical...@gmail.com wrote:

> If you're new to both Beancount and Python, it could be ambitious to get 
> deep into this experimental package :)  But no harm in giving it a try!
>
> I will write some installation/getting-started docs on github and then get 
> back to you.  Thanks for the interest!
>
> On Sat, Feb 24, 2024 at 11:28 AM CDT  wrote:
>
>> I'm relatively new to Python scripting and have been hand entering things 
>> while I'm learning, but this looks very interesting considering the volume 
>> of transactions that can occur with cryptos when the bull market heats up.
>>
>> How do I install this?  (I'm using Windows 11 but I can use pip on 
>> command line)
>>
>> On Saturday, February 17, 2024 at 6:23:37 PM UTC-5 erical...@gmail.com 
>> wrote:
>>
>>> It's 2024, so, time to dust off Magicbeans and prepare 2023 taxes -- 
>>> hope folks don't mind me bumping this thread.  If anyone else is interested 
>>> in using Beancount to track crypto transactions, take a look below and if 
>>> you're willing to beta-test and help develop, feel free to reach out to me.
>>>
>>> best,
>>> eric
>>>
>>> On Wed, Nov 1, 2023 at 3:49 AM Chary Chary  wrote:
>>>
 Ok,

 thanks for clarification

 On Tuesday, October 31, 2023 at 5:30:39 PM UTC+1 erical...@gmail.com 
 wrote:

> No worries.  I suspect that a lot of crypto traders/investors fall 
> into these categories:
>
> - Casual users who make minimal trades on one or two exchanges.  These 
> are probably adequately served by existing commercial offerings like 
> cointracker.io etc.
> - Professional traders who already have some other professional 
> commercial trade recording/reporting software.
>
> For people in between, who are doing something more complex (multiple 
> exchanges, offline wallets, mining income, large numbers of transactions 
> or 
> lots) but are not professional traders, I suspect that probably most tax 
> returns are full of errors that neither the filers nor the IRS are 
> readily 
> able to untangle.  If the amounts are low, then it's not worth either of 
> their time.  If the amounts are large, I am not sure.  I talked to a tax 
> preparer, asking how one would verify the numbers, and he said that 
> probably you'd have to engage a mid-to-large accounting firm and hand 
> them 
> your raw data -- not sure how they would analyze it.  He also said that 
> with the IRS it would probably be a bit hit and miss how an auditor would 
> handle or analyze it -- they probably wouldn't be reading one's Python 
> code, no :)
>
> My goal with Magicbeans was to generate PDF reports which lay out the 
> lots in both inventories and transactions such that one could actually 
> manually match everything up, even if it would be tedious.  The goal was 
> to 
> be able to walk into an IRS office with that report and be able to 
> justify 
> the cap gains/losses of any sale someone questions.
>
> On Thu, Oct 26, 2023 at 1:11 PM Chary Chary  wrote:
>
>> I know this is an offtopic, but I am just wondering: if it takes that 
>> much efforts plus python programming skills to file a tax return, then:
>>
>>
>>- How do other people (mortals) do it?
>>- How on the earth someone is able to verify it? One can't 
>>imagine a tax officer debugging a Python code?
>>
>>
>> On Thursday, October 26, 2023 at 8:57:27 PM UTC+2 erical...@gmail.com 
>> wrote:
>>
>>> I recently filed my 2022 tax return using Magicbeans 
>>>  to do detailed lot 
>>> tracking and capital gains/losses reporting for my crypto assets.  
>>> Magicbeans is a set of tools (importers and report generation tools) 
>>> built 
>>> around Beancount.  I wrote it because I was not satisfied with the 
>>> accuracy 
>>> or transparency of existing commercial services for crypto tax 
>>> reporting.
>>>
>>> Although I was confident enough in the numbers to file my return, I 
>>> am equally confident there's a lot of latent issues in the software.  I 
>>> am 
>>> looking for folks who (1) are interested in better tools for crypto 
>>> transaction tracking, (2) are willing to beta-test and debug some rough 
>>> software, and (3) are skilled enough devs (Python) to also contribute 
>>> fixes.
>>>
>>> Hope to hear from someone out there... :)
>>>
>>> --eric
>>>
>> -- 
>> 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.
>> 

Mileage Standard IRS deduction - how to record

2024-02-26 Thread CD
I would have thought I would have found something on this from a search, 
but I haven't.

What is the best practice for recording mileage on business trips and what 
are the accounts that are used for this if you are using the IRS standard 
deduction per mile?

Does a new commodity/currency need to be created for this?

-- 
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/8240e7f1-89e3-44cd-a181-328201947c20n%40googlegroups.com.


Re: ATM Transaction that has Fee included in Total

2024-02-26 Thread CD
I got it to work, unfortunately I don't have more than 2 ATM transactions 
to test it on.

It was nice to figure out though.  Having something like Beancount as an 
impetus to write a Python script on something practical is kind fun and a 
cool way for me to learn a bit about both (Python and Beancount).  Still 
don't understand everything but I am getting things to work, so that's a 
start.

Here's the revised script (please let me know if this could have been 
organized better)...

from beancount.ingest.importer import ImporterProtocol
from beancount.core import data
from beancount.core import amount
from beancount.core.number import D
from dateutil.parser import parse
import datetime 
import csv
import re
import logging
import warnings
from beancount.core import flags

class PNCChecking(ImporterProtocol):
def __init__(self, account, currency="USD"):
self.account = account
self.currency = currency
self.other_account = "Expenses"  # Default other account
self.second_other_account = None  # Second other account
super().__init__()

def identify(self, file):
# Check if the file name contains "pnc checking" and ends with 
".csv"
if "pnc checking" in file.name.lower() and file
.name.lower().endswith('.csv'):
return True
else:
return False

def file_account(self, file):
return self.account

def extract(self, file):
entries = []

with open(file.name) as infile:
reader = csv.reader(infile)
next(reader, None)  # Skip the header row

for index, row in enumerate(reader):
if len(row) < 5:  # Checking if the row has at least 5 
elements
logging.warning("Row %d does not have enough elements. 
Skipping.", index)
continue

meta = data.new_metadata(file.name, index)  # Beancount meta
date = datetime.datetime.strptime(row[0], "%m/%d/%Y").date() 
 # Parse the date of the transaction

# Extracting relevant information from the description to 
determine payee and other_account
description = row[1]  # Assuming description is in the 
second column
payee = ""  # Placeholder, modify this based on the 
description
self.other_account = "Expenses"  # Reset other account to 
default
self.second_other_account = None  # Reset second other 
account

# Check if the description contains "CARD PMT"
if "CARD PMT" in description and "1234" in description:
payee = "PNC Cash Rewards"
self.other_account = "Liabilities:PNC:CashRewards"

# Check if this is an ATM withdrawal. If fee is included in 
withdrawal, separate out.
if "ATM" in description:
payee = "ATM Withdrawal"
self.other_account = "Assets:Cash"  # Main account
self.second_other_account = "Expenses:BankFees"  # 
Second other account

# Adjustments for ATM withdrawal transaction
withdrawal = row[2]  # Withdrawals amount
deposit = row[3]  # Deposits amount

if withdrawal:
withdrawal_amount = D(withdrawal.replace('$', ''))
fee_amount = withdrawal_amount % 10  # Calculate 
the fee as the remainder after division by 10
units = -amount.Amount(withdrawal_amount, self.
currency)  # Withdrawal amount

# Subtract the fee from the withdrawal amount to 
get the cash amount
cash_amount = withdrawal_amount - fee_amount

account = self.account  # Modify this according to 
your data

txn = data.Transaction(
meta,
date,
None,  # No specific flag
payee,
description,
data.EMPTY_SET,
data.EMPTY_SET,
[
data.Posting(
account, units, None, None, None, None
),
data.Posting(
self.other_account, amount.Amount(
cash_amount, self.currency), None, None, None, None
),
],
)

# Add second_other_account if available
if self.second_other_account:
txn.postings.append(
data.Posting(
self.second_other_account, amount.Amount
(fee_amount, self.currency), None, None, 

Re: ATM Transaction that has Fee included in Total

2024-02-26 Thread CD
You wrote...

"First comment; the code 
   withdrawal_amount % 2 != 0"

How about... fee_amount = withdrawal_amount % 10...


I almost have a working script.  I'll post the completed one up shortly.
On Monday, February 26, 2024 at 12:22:51 PM UTC-5 erical...@gmail.com wrote:

> First comment; the code 
>withdrawal_amount % 2 != 0
>
> checks for "evenness" in the sense of odd (1, 3, 5) vs even (2, 4, 6) 
> numbers.   This doesn't seem like what you'd want, since if your fee were 
> $5 and you withdraw $100, it would count it one way, but if the fee were $2 
> it would count it the other.  Only you can come up with the best heuristic 
> for yourself (based on your typical withdrawal amounts and typical fees) 
> but you might want to revisit this one.
>
>
> as for not appending the posting, it's a bit hard to figure out from your 
> two code snippets since I can't tell where the 2nd code snippet lives in 
> relation to the 1st.  But I suspect that in the 2nd snippet, the "txn" 
> you're adding the postings to is not the one you expect.  If the 2nd 
> snippet actually lives in the context of the
> if "ATM" in description:
> condition in the first snippet, then you're adding to "txn" before you 
> create the txn for this input.  That means you're probably adding it to the 
> txn from the previous iteration, which is still visible and accessible 
> (thanks, Python).
>
> On Mon, Feb 26, 2024 at 7:11 AM CDT  wrote:
>
>> I don't like to carry much cash when I travel for business, so from time 
>> to time I use my ATM card at a machine when I'm away and it charges a fee 
>> that is included in the total.
>>
>> ie - I get $500 cash but the full amount shows as one transaction of 
>> $507.99 (the fee isn't separated)
>>
>> I am trying to figure out a way to have this separated out when I use an 
>> Importer so that it would show up as $500 USD in cash and 7.99 USD in fees
>>
>> I have a working CSV import for my PNC transactions, but I can't seem to 
>> figure out how to include this.
>>
>> Here's the code I use at them moment (without the fees)...
>>
>> from beancount.ingest.importer import ImporterProtocol
>> from beancount.core import data
>> from beancount.core import amount
>> from beancount.core.number import D
>> from dateutil.parser import parse
>> import datetime 
>> import csv
>> import re
>> import logging
>> import warnings
>> from beancount.core import flags
>>
>> class PNCChecking(ImporterProtocol):
>> def __init__(self, account, currency="USD"):
>> self.account = account
>> self.currency = currency
>> super().__init__()
>>
>> def identify(self, file):
>> # Check if the file name contains "pnc checking" and ends with 
>> ".csv"
>> if "pnc checking" in file.name.lower() and file
>> .name.lower().endswith('.csv'):
>> return True
>> else:
>> return False
>>
>> def file_account(self, file):
>> return self.account
>>
>> def extract(self, file):
>> entries = []
>>
>> with open(file.name) as infile:
>> reader = csv.reader(infile)
>> next(reader, None)  # Skip the header row
>>
>> for index, row in enumerate(reader):
>> if len(row) < 5:  # Checking if the row has at least 5 
>> elements
>> logging.warning("Row %d does not have enough 
>> elements. Skipping.", index)
>> continue
>>
>> meta = data.new_metadata(file.name, index)  # Beancount 
>> meta
>> date = datetime.datetime.strptime(row[0], "%m/%d/%Y").
>> date()  # Parse the date of the transaction
>>
>> # Extracting relevant information from the description 
>> to determine payee and other_account
>> description = row[1]  # Assuming description is in the 
>> second column
>> payee = ""  # Placeholder, modify this based on the 
>> description
>> other_account = "Expenses"  # Placeholder, modify this 
>> based on the description
>>
>> # Check if the description contains "CARD PMT"
>> if "CARD PMT" in description:
>> payee = "PNC Cash Rewards"
>> other_account = "Liabilities:PNC:CashRewards"
>>
>> # Check if this is an ATM withdrawal 
>> # and then subtract their ATM Fee and put that in 
>> separate expense
>> 
>> if "ATM" in description:
>> other_account = "Assets:Cash"
>>
>>
>> # Determining the credit/debit type based on withdrawals 
>> and deposits
>> withdrawal = row[2]  # Withdrawals amount
>> deposit = row[3]  # Deposits amount
>>
>> if withdrawal:
>> units = -amount.Amount(D(withdrawal.replace('$', '')), 
>> self.currency)  # Using withdrawal amount
>> elif