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

(-)a/Koha/Patron/Attribute.pm (-51 lines)
Lines 80-136 sub opac_editable { Link Here
80
    return Koha::Patron::Attribute::Types->find( $self->code )->opac_editable;
80
    return Koha::Patron::Attribute::Types->find( $self->code )->opac_editable;
81
}
81
}
82
82
83
=head3 display_checkout
84
85
    my $attribute = Koha::Patron::Attribute->new({ code => 'a_code', ... });
86
    if ( $attribute->display_checkout ) { ... }
87
88
=cut
89
90
sub display_checkout {
91
92
    my $self = shift;
93
94
    return $self->type->display_checkout;
95
}
96
97
=head3 value_description
98
99
    my $description = $attribute->value_description
100
101
    Return authorised value description or free text based on attribute type settings
102
103
=cut
104
105
sub value_description {
106
107
    my $self = shift;
108
109
    if ( $self->type->authorised_value_category ) {
110
        my $av = Koha::AuthorisedValues->search({
111
            category => $self->type->authorised_value_category,
112
            authorised_value => $self->attribute,
113
        });
114
        return $av->next->lib if $av->count;
115
    }
116
    return $self->attribute;
117
}
118
119
=head3 type_description
120
121
    my $description = $attribute->type_description
122
123
    Return description of attribute type
124
125
=cut
126
127
sub type_description {
128
129
    my $self = shift;
130
131
    return $self->type->description;
132
}
133
134
=head3 type
83
=head3 type
135
84
136
    my $attribute_type = $attribute->type;
85
    my $attribute_type = $attribute->type;
(-)a/Koha/Schema/Result/BorrowerAttribute.pm (+15 lines)
Lines 109-114 __PACKAGE__->belongs_to( Link Here
109
# Created by DBIx::Class::Schema::Loader v0.07042 @ 2016-12-08 04:41:27
109
# Created by DBIx::Class::Schema::Loader v0.07042 @ 2016-12-08 04:41:27
110
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:EarETnedFsmRmAAJAUrKGg
110
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:EarETnedFsmRmAAJAUrKGg
111
111
112
=head2 borrower_attribute_types
113
114
Type: belongs_to
115
116
Related object: L<Koha::Schema::Result::BorrowerAttributeType>
117
118
=cut
119
120
__PACKAGE__->belongs_to(
121
    "borrower_attribute_types",
122
    "Koha::Schema::Result::BorrowerAttributeType",
123
    { "foreign.code" => "self.code" },
124
    { is_deferrable => 1, on_delete => "CASCADE", on_update => "CASCADE" },);
125
126
112
sub koha_object_class {
127
sub koha_object_class {
113
    'Koha::Patron::Attribute';
128
    'Koha::Patron::Attribute';
114
}
129
}
(-)a/t/db_dependent/Koha/Patron/Attributes.t (-64 / +1 lines)
Lines 19-25 Link Here
19
19
20
use Modern::Perl;
20
use Modern::Perl;
21
21
22
use Test::More tests => 7;
22
use Test::More tests => 3;
23
23
24
use t::lib::TestBuilder;
24
use t::lib::TestBuilder;
25
use Test::Exception;
25
use Test::Exception;
Lines 274-339 subtest 'type() tests' => sub { Link Here
274
274
275
    $schema->storage->txn_rollback;
275
    $schema->storage->txn_rollback;
276
};
276
};
277
278
subtest 'display_checkout() tests' => sub {
279
280
    plan tests => 2;
281
282
    $schema->storage->txn_begin;
283
284
    my $patron = $builder->build( { source => 'Borrower' } )->{borrowernumber};
285
    my $attribute_type_1 = $builder->build(
286
        {   source => 'BorrowerAttributeType',
287
            value  => { display_checkout => 1 }
288
        }
289
    );
290
291
    my $attribute_1 = Koha::Patron::Attribute->new(
292
        {   borrowernumber => $patron,
293
            code           => $attribute_type_1->{code},
294
            attribute      => $patron
295
        }
296
    );
297
    is( $attribute_1->display_checkout, 1, '->display_checkout returns 1' );
298
299
    my $attribute_type_2 = $builder->build(
300
        {   source => 'BorrowerAttributeType',
301
            value  => { display_checkout => 0 }
302
        }
303
    );
304
305
    my $attribute_2 = Koha::Patron::Attribute->new(
306
        {   borrowernumber => $patron,
307
            code           => $attribute_type_2->{code},
308
            attribute      => $patron
309
        }
310
    );
311
    is( $attribute_2->display_checkout, 0, '->display_checkout returns 0' );
312
313
    $schema->storage->txn_rollback;
314
};
315
316
subtest 'type_description() and value_description tests' => sub {
317
318
    plan tests => 2;
319
320
    $schema->storage->txn_begin;
321
322
    my $patron = $builder->build( { source => 'Borrower' } )->{borrowernumber};
323
    my $attribute_type_1 = $builder->build(
324
        {   source => 'BorrowerAttributeType',
325
            value  => { description => "Type 1" }
326
        }
327
    );
328
329
    my $attribute_1 = Koha::Patron::Attribute->new(
330
        {   borrowernumber => $patron,
331
            code           => $attribute_type_1->{code},
332
            attribute      => "Attribute 1"
333
        }
334
    );
335
    is( $attribute_1->type_description, "Type 1" , '->type_description returns right value' );
336
    is( $attribute_1->value_description, "Attribute 1" , '->value_description returns right value' );
337
338
    $schema->storage->txn_rollback;
339
};
(-)a/t/db_dependent/Koha/Patrons.t (-50 lines)
Lines 1641-1695 subtest 'generate_userid' => sub { Link Here
1641
    $patron_2->delete;
1641
    $patron_2->delete;
1642
};
1642
};
1643
1643
1644
subtest 'attributes' => sub {
1645
    plan tests => 2;
1646
1647
    my $library1 = Koha::Library->new({
1648
        branchcode => 'LIBPATRON',
1649
        branchname => 'Library of testing patron',
1650
    })->store;
1651
1652
    my $library2 = Koha::Library->new({
1653
        branchcode => 'LIBATTR',
1654
        branchname => 'Library for testing attribute',
1655
    })->store;
1656
1657
    my $category = Koha::Patron::Category->new({
1658
        categorycode => 'CAT1',
1659
        description => 'Category 1',
1660
    })->store;
1661
1662
    my $patron = Koha::Patron->new({
1663
        firstname => 'Patron',
1664
        surname => 'with attributes',
1665
        branchcode => 'LIBPATRON',
1666
        categorycode => 'CAT1',
1667
    })->store;
1668
1669
    my $attribute_type1 = Koha::Patron::Attribute::Type->new({
1670
        code => 'CODE_A',
1671
        description => 'Code A desciption',
1672
    })->store;
1673
1674
    my $attribute_type2 = Koha::Patron::Attribute::Type->new({
1675
        code => 'CODE_B',
1676
        description => 'Code A desciption',
1677
    })->store;
1678
1679
    $attribute_type2->library_limits ( [ $library2->branchcode ] );
1680
1681
    Koha::Patron::Attribute->new({ borrowernumber => $patron->borrowernumber, code => $attribute_type1->code, attribute => 'value 1' } )->store();
1682
    Koha::Patron::Attribute->new({ borrowernumber => $patron->borrowernumber, code => $attribute_type2->code, attribute => 'value 2' } )->store();
1683
1684
    is( $patron->attributes->count, 1, 'There should be one attribute');
1685
1686
    $attribute_type2->library_limits ( [ $library1->branchcode ] );
1687
1688
    is( $patron->attributes->count, 2, 'There should be 2 attributes');
1689
1690
    $patron->delete;
1691
};
1692
1693
$nb_of_patrons = Koha::Patrons->search->count;
1644
$nb_of_patrons = Koha::Patrons->search->count;
1694
$retrieved_patron_1->delete;
1645
$retrieved_patron_1->delete;
1695
is( Koha::Patrons->search->count, $nb_of_patrons - 1, 'Delete should have deleted the patron' );
1646
is( Koha::Patrons->search->count, $nb_of_patrons - 1, 'Delete should have deleted the patron' );
1696
- 

Return to bug 20443