juftin / lunchable

Python Client for the Lunch Money Developer API
https://juftin.com/lunchable/
MIT License
37 stars 8 forks source link

Credit/debit sign #124

Closed Chrismarsh closed 2 months ago

Chrismarsh commented 3 months ago

Description

Negative amount values in a transaction are converted to positive values in the lunchmoney webui

What I Did


# set API
# set asset_id

tx_dict={}
tx_dict['date'] = '2024-06-30'
tx_dict['amount'] = '60'
tx_dict['category'] = 'Groceries'
tx_dict['payee'] = 'sobeys2'
tx_dict['type'] = 'debit'
user_category = get_lunchmoney_categories()

new_transaction = lmtrans.TransactionInsertObject(
    date= tx_dict['date'],
    amount= float(tx_dict['amount']),
    category_id= user_category[tx_dict['category']],
    notes= None,
    payee= tx_dict['payee'],
    type = tx_dict['type'],
    asset_id = my_asset_id,
    status="cleared"
)
# tx.append(new_transaction)
lunchmoney.insert_transactions(transactions=[new_transaction], skip_duplicates=True)

If tx_dict['amount'] = '60', then this is shown as negative in the lunchmoney webui If tx_dict['amount'] = '-60' then this is shown as psitive in the lunchmoney webui

juftin commented 3 months ago

Hey @Chrismarsh, lunchable simply sends the data to the Lunch Money developer API - I think you're describing the default behavior of the API treatment of negative/positive values as credits/expenses?

You should check out the debit_as_negative parameter of the insert_transactions method if you want to change the behavior. 

If true, will assume negative amount values denote expenses and positive amount values denote credits. Defaults to false.

https://juftin.com/lunchable/reference/models/transactions/#lunchable.models.transactions.TransactionsClient.insert_transactions

https://lunchmoney.dev/#insert-transactions

juftin commented 2 months ago

I'm closing this issue for now - if you think this is an actual product with lunchable's implementation of the LunchMoney developer API please feel free to follow up and re-open this issue.