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

(-)a/Koha/Patron.pm (-2 / +26 lines)
Lines 315-321 sub store { Link Here
315
                }
315
                }
316
316
317
                foreach my $guarantor (@$guarantors) {
317
                foreach my $guarantor (@$guarantors) {
318
                    if ( $guarantor->is_child or $guarantor->category->can_be_guarantee ) {
318
                    if ( $guarantor->is_child ) {
319
                        Koha::Exceptions::Patron::Relationship::InvalidRelationship->throw( invalid_guarantor => 1 );
319
                        Koha::Exceptions::Patron::Relationship::InvalidRelationship->throw( invalid_guarantor => 1 );
320
                    }
320
                    }
321
                }
321
                }
Lines 372-378 sub store { Link Here
372
                }
372
                }
373
373
374
                foreach my $guarantor (@$guarantors) {
374
                foreach my $guarantor (@$guarantors) {
375
                    if ( $guarantor->is_child or $guarantor->category->can_be_guarantee ) {
375
                    if ( $guarantor->is_child ) {
376
                        Koha::Exceptions::Patron::Relationship::InvalidRelationship->throw( invalid_guarantor => 1 );
376
                        Koha::Exceptions::Patron::Relationship::InvalidRelationship->throw( invalid_guarantor => 1 );
377
                    }
377
                    }
378
                }
378
                }
Lines 533-538 sub guarantor_relationships { Link Here
533
    return Koha::Patron::Relationships->search( { guarantee_id => $self->id } );
533
    return Koha::Patron::Relationships->search( { guarantee_id => $self->id } );
534
}
534
}
535
535
536
=head3 is_guarantee
537
538
Returns true if the patron has a guarantor.
539
540
=cut
541
542
sub is_guarantee {
543
    my ($self) = @_;
544
    return $self->guarantor_relationships()->count();
545
}
546
547
536
=head3 guarantee_relationships
548
=head3 guarantee_relationships
537
549
538
Returns Koha::Patron::Relationships object for this patron's guarantors
550
Returns Koha::Patron::Relationships object for this patron's guarantors
Lines 557-562 sub guarantee_relationships { Link Here
557
    );
569
    );
558
}
570
}
559
571
572
=head3 is_guarantor
573
574
Returns true if the patron is a guarantor.
575
576
=cut
577
578
sub is_guarantor {
579
    my ($self) = @_;
580
    return $self->guarantee_relationships()->count();
581
}
582
583
560
=head3 relationships_debt
584
=head3 relationships_debt
561
585
562
Returns the amount owed by the patron's guarantors *and* the other guarantees of those guarantors
586
Returns the amount owed by the patron's guarantors *and* the other guarantees of those guarantors
(-)a/members/memberentry.pl (-1 / +1 lines)
Lines 285-291 if ( ( $op eq 'cud-save' || $op eq 'cud-insert' ) Link Here
285
}
285
}
286
286
287
foreach my $guarantor (@guarantors) {
287
foreach my $guarantor (@guarantors) {
288
    if ( ( $op eq 'cud-save' || $op eq 'cud-insert' ) && $guarantor->is_child || $guarantor->category->can_be_guarantee ) {
288
    if ( ( $op eq 'cud-save' || $op eq 'cud-insert' ) && ($guarantor->is_child ) || $guarantor->is_guarantee || $patron->is_guarantor)  {
289
        push @errors, 'ERROR_guarantor_is_guarantee';
289
        push @errors, 'ERROR_guarantor_is_guarantee';
290
    }
290
    }
291
}
291
}
(-)a/t/db_dependent/Koha/Patron.t (-2 / +46 lines)
Lines 19-25 Link Here
19
19
20
use Modern::Perl;
20
use Modern::Perl;
21
21
22
use Test::More tests => 35;
22
use Test::More tests => 36;
23
use Test::Exception;
23
use Test::Exception;
24
use Test::Warn;
24
use Test::Warn;
25
use Time::Fake;
25
use Time::Fake;
Lines 410-415 subtest 'add_guarantor() tests' => sub { Link Here
410
    $schema->storage->txn_rollback;
410
    $schema->storage->txn_rollback;
411
};
411
};
412
412
413
subtest 'guarantor checks on patron creation / update tests' => sub {
414
415
    plan tests => 2;
416
417
    $schema->storage->txn_begin;
418
419
    t::lib::Mocks::mock_preference( 'borrowerRelationship', 'guarantor' );
420
    my $category = $builder->build_object(
421
        { class => 'Koha::Patron::Categories', value => { can_be_guarantee => 1, category_type => 'A' } } );
422
423
    my $guarantor =
424
        $builder->build_object( { class => 'Koha::Patrons', value => { categorycode => $category->categorycode } } );
425
    my $guarantee =
426
        $builder->build_object( { class => 'Koha::Patrons', value => { categorycode => $category->categorycode } } );
427
428
    subtest 'patron update tests' => sub {
429
        plan tests => 4;
430
        ok(
431
            $guarantee->add_guarantor( { guarantor_id => $guarantor->borrowernumber, relationship => 'guarantor' } ),
432
            "Relationship is added, no problem"
433
        );
434
        is( $guarantor->guarantee_relationships->count, 1, 'Relationship added' );
435
        ok( $guarantor->surname("Duck")->store(), "Updating guarantor is okay" );
436
        ok( $guarantee->surname("Duck")->store(), "Updating guarantee is okay" );
437
    };
438
439
    subtest 'patron creation tests' => sub {
440
        plan tests => 1;
441
442
        my $new_guarantee = $builder->build_object(
443
            { class => 'Koha::Patrons', value => { categorycode => $category->categorycode } } );
444
        my $new_guarantee_hash = $new_guarantee->unblessed;
445
        $new_guarantee->delete();
446
447
        delete $new_guarantee_hash->{borrowernumber};
448
449
        ok(
450
            Koha::Patron->new($new_guarantee_hash)->store( { guarantors => [$guarantor] } ),
451
            "We can add the new patron and indicate guarantor"
452
        );
453
    };
454
455
    $schema->storage->txn_rollback;
456
};
457
413
subtest 'relationships_debt() tests' => sub {
458
subtest 'relationships_debt() tests' => sub {
414
459
415
    plan tests => 168;
460
    plan tests => 168;
416
- 

Return to bug 37892