ledgersmb / LedgerSMB

Double-entry accounting & ERP for the web
https://ledgersmb.org
Other
429 stars 151 forks source link

Deleting the draft transactions doesn't delete the payment #6529

Open aungzwin10 opened 2 years ago

aungzwin10 commented 2 years ago

Version

1.9.13

What browsers are you seeing the problem on?

This problem isn't browser related

What happened?

When deleting the draft transaction, draft_delete only deletes the acc_trans, tax related table, payment_links and ar/ap/gl. However, if the transaction exist payments, it doesn't delete record in payment. So, there are lots of record left in payment which do not allocate to any transactions.

Please take a look at the draft_delete function. https://github.com/ledgersmb/LedgerSMB/blob/b4768e57b7e94110499094b62cc6f7297e34e17d/sql/modules/Drafts.sql#L117-L163

What should have happened?

If the payment exists in the transaction, delete both payment and payment_links.

ehuelsmann commented 2 years ago

@aungzwin10 thanks for the report. From your report, I understand that you have a lot of payments that pay exactly one invoice (I'm assuming that the payment gets entered on the invoice screen.) The code was written the way it is, because there's the possibility to create payments that are associated with more than one transaction. I was having trouble understanding howto determine which payment records to delete and which ones need to stick around. (The ones that still have links need to stick around, obviously, but the point was how to put that in the SQL in the procedure you're quoting.)

aungzwin10 commented 2 years ago

@ehuelsmann Yes, payment entered on the invoice screen at the time of saving invoice.

Save payment id in the variable before payment_link delete. Then after deleting the payment_links(meaning after following lines) https://github.com/ledgersmb/LedgerSMB/blob/b4768e57b7e94110499094b62cc6f7297e34e17d/sql/modules/Drafts.sql#L127-L135 find entries in the payment_links associated to that payment_id. If there is no entry in the payment_links, delete the payment id, otherwise, leave it.

Do you think the above scenario enough?

tonka128 commented 2 years ago

2nd vote to get sorted - we also do a lot of single invoice/single payment (think of LSMB as a POS terminal)

ehuelsmann commented 1 year ago

I've been contemplating this issue. The solution - I think - is to collect the payment and the transaction into a batch and have the "Delete" option mean batch deletion of the two.