Acq: Certain workflows produce orphaned fund debits

Bug #1175740 reported by Lebbeous Fogle-Weekley
14
This bug affects 2 people
Affects Status Importance Assigned to Milestone
Evergreen
Incomplete
Undecided
Unassigned

Bug Description

Observed in Evergreen 2.2.8, but probably affecting newer versions too.

Users at an Evergreen site have noticed unexpected and undesired acquisitions fund_debits affecting their funds' balances. Such fund_debits seem to have arrived thanks to interface or middle layer bugs (see later in this bug report).

In cooperation with the site so afflicted, Jason Etheridge put together this SQL query to identify fund_debits that lack clear justification for their existence:

select fd.*
from
acq.fund_debit fd
left join acq.invoice_item ii on ii.fund_debit = fd.id
left join acq.po_item poi on poi.fund_debit = fd.id
left join acq.lineitem_detail ld on ld.fund_debit = fd.id
left join acq.debit_attribution da on da.fund_debit = fd.id
where
fd.debit_type <> 'prorated_charge'
and ii.id is null
and poi.id is null
and ld.id is null
and da.id is null;

As far as I can tell, indeed, any fund debits that show up in result rows from such a query are either bad data (probably but not necessarily introduced by bugs in Evergreen) or intentional, hand-entered adjustments to funds (users at some sites *may* create fund_debits for balancing purposes, although I wouldn't say it's a good idea).

The user, whom I commend anonymously, along with her associates, until she might wish to claim credit for this legwork, relay these actions of Acquisitions staff at one of her libraries:

> [...] they cancelled the line items by selecting them all and using the PO
> Actions menu "Cancel selected lineitems" option and then used the PO
> Actions menu option "Delete selected items" to delete the line items.
> They then cancelled the PO itself using the cancel option in the
> header of the PO. The result was that the debits were orphaned. The
> actual copies did not get deleted either. They wanted to delete this
> PO because it was a duplicate. Is there any way to delete lineitems
> and POs such that the encumbrance is removed properly and the copy is
> deleted from the catalog?

We need to 1) determine whether the situation is any different in current Evergreen master, 2) make sure there's not some valid reason for keeping the fund_debits and copies around in this situation that I just don't get, and 3) fix it.

Tags: acq
Revision history for this message
Bill Erickson (berick) wrote :

I know of no reason for a fund_debit, which is linked to a lineitem_detail, to persist after the lineitem_detail has been deleted. In a perfect world, the lineitem_detail would have been cancelled with a cancel_reason whose keep_debits value is FALSE, which would have caused the debits to be deleted during cancellation.

I don't, however, think that we should delete an asset.copy when its linked lineitem_detail is deleted, at least not without a warning/confirmation.

Ben Shum (bshum)
Changed in evergreen:
status: New → Triaged
Revision history for this message
Lebbeous Fogle-Weekley (lebbeous) wrote :

This commit does what Bill suggests.

If the user deletes a lineitem that for any reason has fund debits attached to its constituent lineitem details, those fund debits are deleted, assuming they're not related to any other acq objects such as PO items / invoice items for misc. charges (this is mostly just a data-integrity test). Since leaving the fund debits around, as we do today, leads to imbalanced funds, I think this whole thing is in bug-fix territory more than new-feature territory.

If the user deletes lineitems with copies attached to them, the system will prompt that user to ask whether to delete the copies, and act accordingly.

http://git.evergreen-ils.org/?p=working/Evergreen.git;a=shortlog;h=refs/heads/user/senator/acq-li-delete-debits-and-copies

Revision history for this message
Lebbeous Fogle-Weekley (lebbeous) wrote :

This bug has been missing its pullrequest tag for some time.

tags: added: pullrequest
Revision history for this message
Kathy Lussier (klussier) wrote :

We've had some interest in getting this code tested. However, we are no longer able to replicate the situation that produced orphan debits due to https://bugs.launchpad.net/evergreen/+bug/1271610, where we are no longer able to delete lineitems.

Ideally, we would like bug 1271610 fixed so that we can return to deleting lineitems, at which point we may still need this code to prevent the orphan debits. Or perhaps 1271610 can be fixed in such a way to prevent this scenario from happening to begin with.

Revision history for this message
Kathy Lussier (klussier) wrote :

I'm removing the pullrequest tag from this one and marking incomplete since bug 127160 has put us in situation where the original problem doesn't occur (see my comments above).

tags: removed: pullrequest
Changed in evergreen:
status: Triaged → Incomplete
no longer affects: evergreen/2.3
no longer affects: evergreen/2.4
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.