sub check_lineitem_received {
my($mgr, $li_id) = @_;
-
- my $non_recv = $mgr->editor->search_acq_lineitem_detail(
- {recv_time => undef, lineitem => $li_id}, {idlist=>1});
+ # we account for cancel_reasons with keep_debits = false
+ # here to make sure the lineitem gets marked "received"
+ # when, say, all but one are received and the last is
+ # canceled
+ my $non_recv = $mgr->editor->json_query({
+ select => {acqlid => ['id']},
+ from => {
+ jub => {
+ acqlid => {
+ join => {
+ acqcr => {
+ type => 'left'
+ }
+ }
+ }
+ }
+ },
+ where => {
+ '-or' => [
+ {'+acqlid' => {cancel_reason => undef}},
+ {'+acqcr' => {keep_debits => 't'}}
+ ],
+ '+jub' => {id => $li_id}
+ },
+ limit => 1
+ });
return 1 if @$non_recv;