View | Details | Raw Unified | Return to bug 32054
Collapse All | Expand All

(-)a/Koha/Item.pm (-47 / +45 lines)
Lines 1187-1244 sub _set_found_trigger { Link Here
1187
            }
1187
            }
1188
        }
1188
        }
1189
1189
1190
        # restore fine for lost book
1190
        # possibly restore fine for lost book
1191
        if ( $lostreturn_policy eq 'restore' ) {
1191
        my $lost_overdue = Koha::Account::Lines->search(
1192
            my $lost_overdue = Koha::Account::Lines->search(
1192
            {
1193
                {
1193
                itemnumber      => $self->itemnumber,
1194
                    itemnumber      => $self->itemnumber,
1194
                debit_type_code => 'OVERDUE',
1195
                    debit_type_code => 'OVERDUE',
1195
                status          => 'LOST'
1196
                    status          => 'LOST'
1196
            },
1197
                },
1197
            {
1198
                {
1198
                order_by => { '-desc' => 'date' },
1199
                    order_by => { '-desc' => 'date' },
1199
                rows     => 1
1200
                    rows     => 1
1200
            }
1201
                }
1201
        )->single;
1202
            )->single;
1202
        if ( $lostreturn_policy eq 'restore' && $lost_overdue ) {
1203
1204
            if ( $lost_overdue ) {
1205
1206
                my $patron = $lost_overdue->patron;
1207
                if ($patron) {
1208
                    my $account = $patron->account;
1209
1203
1210
                    # Update status of fine
1204
            my $patron = $lost_overdue->patron;
1211
                    $lost_overdue->status('FOUND')->store();
1205
            if ($patron) {
1206
                my $account = $patron->account;
1212
1207
1213
                    # Find related forgive credit
1208
                # Update status of fine
1214
                    my $refund = $lost_overdue->credits(
1209
                $lost_overdue->status('FOUND')->store();
1210
1211
                # Find related forgive credit
1212
                my $refund = $lost_overdue->credits(
1213
                    {
1214
                        credit_type_code => 'FORGIVEN',
1215
                        itemnumber       => $self->itemnumber,
1216
                        status           => [ { '!=' => 'VOID' }, undef ]
1217
                    },
1218
                    { order_by => { '-desc' => 'date' }, rows => 1 }
1219
                )->single;
1220
1221
                if ( $refund ) {
1222
                    # Revert the forgive credit
1223
                    $refund->void({ interface => 'trigger' });
1224
                    $self->add_message(
1215
                        {
1225
                        {
1216
                            credit_type_code => 'FORGIVEN',
1226
                            type    => 'info',
1217
                            itemnumber       => $self->itemnumber,
1227
                            message => 'lost_restored',
1218
                            status           => [ { '!=' => 'VOID' }, undef ]
1228
                            payload => { refund_id => $refund->id }
1219
                        },
1229
                        }
1220
                        { order_by => { '-desc' => 'date' }, rows => 1 }
1230
                    );
1221
                    )->single;
1231
                }
1222
1232
1223
                    if ( $refund ) {
1233
                # Reconcile balances if required
1224
                        # Revert the forgive credit
1234
                if ( C4::Context->preference('AccountAutoReconcile') ) {
1225
                        $refund->void({ interface => 'trigger' });
1235
                    $account->reconcile_balance;
1226
                        $self->add_message(
1227
                            {
1228
                                type    => 'info',
1229
                                message => 'lost_restored',
1230
                                payload => { refund_id => $refund->id }
1231
                            }
1232
                        );
1233
                    }
1234
1235
                    # Reconcile balances if required
1236
                    if ( C4::Context->preference('AccountAutoReconcile') ) {
1237
                        $account->reconcile_balance;
1238
                    }
1239
                }
1236
                }
1240
            }
1237
            }
1241
        } elsif ( $lostreturn_policy eq 'charge' ) {
1238
1239
        } elsif ( $lostreturn_policy eq 'charge' && ( $lost_overdue || $lost_charge ) ) {
1242
            $self->add_message(
1240
            $self->add_message(
1243
                {
1241
                {
1244
                    type    => 'info',
1242
                    type    => 'info',
(-)a/t/db_dependent/Koha/Item.t (-2 / +9 lines)
Lines 1206-1212 subtest 'store() tests' => sub { Link Here
1206
1206
1207
    subtest '_set_found_trigger() tests' => sub {
1207
    subtest '_set_found_trigger() tests' => sub {
1208
1208
1209
        plan tests => 6;
1209
        plan tests => 7;
1210
1210
1211
        $schema->storage->txn_begin;
1211
        $schema->storage->txn_begin;
1212
1212
Lines 1253-1258 subtest 'store() tests' => sub { Link Here
1253
        is( $message_2->message, 'lost_charge', 'message is correct' );
1253
        is( $message_2->message, 'lost_charge', 'message is correct' );
1254
        is( $message_2->payload, undef,         'no payload' );
1254
        is( $message_2->payload, undef,         'no payload' );
1255
1255
1256
1257
        # Let's build a new item
1258
        $item   = $builder->build_sample_item({ itemlost => 1, itemlost_on => dt_from_string() });
1259
        $item->set( { itemlost => 0 } )->store;
1260
1261
        $messages = $item->object_messages;
1262
        is( scalar @{$messages}, 0, 'This item has no history, no associated lost fines, presumed not lost by patron, no messages returned');
1263
1256
        $schema->storage->txn_rollback;
1264
        $schema->storage->txn_rollback;
1257
    };
1265
    };
1258
1266
1259
- 

Return to bug 32054