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

(-)a/Koha/Acquisition/Bookseller.pm (-1 / +1 lines)
Lines 25-31 use Koha::Subscriptions; Link Here
25
25
26
use C4::Contract qw( GetContracts );
26
use C4::Contract qw( GetContracts );
27
27
28
use base qw( Koha::Object );
28
use base qw( Koha::Object::Mixin::AdditionalFields Koha::Object );
29
29
30
=head1 NAME
30
=head1 NAME
31
31
(-)a/Koha/Acquisition/Booksellers.pm (-1 / +1 lines)
Lines 19-25 use Modern::Perl; Link Here
19
19
20
use Koha::Acquisition::Bookseller;
20
use Koha::Acquisition::Bookseller;
21
21
22
use base qw( Koha::Objects );
22
use base qw( Koha::Object::Mixin::AdditionalFields Koha::Objects );
23
23
24
=head1 NAME
24
=head1 NAME
25
25
(-)a/Koha/AdditionalField.pm (+1 lines)
Lines 63-68 sub to_api { Link Here
63
        'erm_agreements'      => 'agreement',
63
        'erm_agreements'      => 'agreement',
64
        'erm_packages'        => 'package',
64
        'erm_packages'        => 'package',
65
        'aqorders'            => 'order',
65
        'aqorders'            => 'order',
66
        'aqbooksellers:vendor'       => 'vendor',
66
    };
67
    };
67
68
68
    my $json = $self->SUPER::to_api($params);
69
    my $json = $self->SUPER::to_api($params);
(-)a/Koha/REST/V1/Acquisitions/Vendors.pm (-18 / +31 lines)
Lines 87-99 Controller function that handles adding a new Koha::Acquisition::Bookseller obje Link Here
87
sub add {
87
sub add {
88
    my $c = shift->openapi->valid_input or return;
88
    my $c = shift->openapi->valid_input or return;
89
89
90
    my $vendor        = $c->req->json;
90
    my $vendor              = $c->req->json;
91
    my $contacts      = delete $vendor->{contacts};
91
    my $contacts            = delete $vendor->{contacts};
92
    my $interfaces    = delete $vendor->{interfaces};
92
    my $interfaces          = delete $vendor->{interfaces};
93
    my $aliases       = delete $vendor->{aliases};
93
    my $aliases             = delete $vendor->{aliases};
94
    my $subscriptions = delete $vendor->{subscriptions};
94
    my $subscriptions       = delete $vendor->{subscriptions};
95
    my $baskets       = delete $vendor->{baskets};
95
    my $baskets             = delete $vendor->{baskets};
96
    my $contracts     = delete $vendor->{contracts};
96
    my $contracts           = delete $vendor->{contracts};
97
    my $extended_attributes = delete $vendor->{extended_attributes};
97
98
98
    my $vendor_to_store = Koha::Acquisition::Bookseller->new_from_api( $c->req->json );
99
    my $vendor_to_store = Koha::Acquisition::Bookseller->new_from_api( $c->req->json );
99
100
Lines 101-108 sub add { Link Here
101
        $vendor_to_store->store;
102
        $vendor_to_store->store;
102
103
103
        $vendor_to_store->contacts($contacts)     if scalar($contacts) > 0;
104
        $vendor_to_store->contacts($contacts)     if scalar($contacts) > 0;
104
        $vendor_to_store->aliases($aliases)       if scalar($aliases) > 0;
105
        $vendor_to_store->aliases($aliases)       if scalar(@$aliases) > 0;
105
        $vendor_to_store->interfaces($interfaces) if scalar($interfaces) > 0;
106
        $vendor_to_store->interfaces($interfaces) if scalar(@$interfaces) > 0;
107
108
        if(scalar(@$extended_attributes) > 0) {
109
            my @extended_attributes = map { { 'id' => $_->{field_id}, 'value' => $_->{value} } } @{$extended_attributes};
110
            $vendor_to_store->extended_attributes( \@extended_attributes );
111
        }
106
112
107
        $c->res->headers->location( $c->req->url->to_string . '/' . $vendor_to_store->id );
113
        $c->res->headers->location( $c->req->url->to_string . '/' . $vendor_to_store->id );
108
        return $c->render(
114
        return $c->render(
Lines 131-150 sub update { Link Here
131
        unless $vendor;
137
        unless $vendor;
132
138
133
    return try {
139
    return try {
134
        my $vendor_update = $c->req->json;
140
        my $vendor_update       = $c->req->json;
135
        my $contacts      = delete $vendor_update->{contacts};
141
        my $contacts            = delete $vendor_update->{contacts};
136
        my $interfaces    = delete $vendor_update->{interfaces};
142
        my $interfaces          = delete $vendor_update->{interfaces};
137
        my $aliases       = delete $vendor_update->{aliases};
143
        my $aliases             = delete $vendor_update->{aliases};
138
        my $subscriptions = delete $vendor_update->{subscriptions};
144
        my $subscriptions       = delete $vendor_update->{subscriptions};
139
        my $baskets       = delete $vendor_update->{baskets};
145
        my $baskets             = delete $vendor_update->{baskets};
140
        my $contracts     = delete $vendor_update->{contracts};
146
        my $contracts           = delete $vendor_update->{contracts};
147
        my $extended_attributes = delete $vendor_update->{extended_attributes};
141
148
142
        $vendor->set_from_api($vendor_update);
149
        $vendor->set_from_api($vendor_update);
143
        $vendor->store();
150
        $vendor->store();
144
151
145
        $vendor->contacts($contacts)     if scalar($contacts) > 0;
152
        $vendor->contacts($contacts)     if scalar($contacts) > 0;
146
        $vendor->aliases($aliases)       if scalar($aliases) > 0;
153
        $vendor->aliases($aliases)       if scalar(@$aliases) > 0;
147
        $vendor->interfaces($interfaces) if scalar($interfaces) > 0;
154
        $vendor->interfaces($interfaces) if scalar(@$interfaces) > 0;
155
156
        if ( scalar(@$extended_attributes) > 0 ) {
157
            my @extended_attributes =
158
                map { { 'id' => $_->{field_id}, 'value' => $_->{value} } } @{$extended_attributes};
159
            $vendor->extended_attributes( \@extended_attributes );
160
        }
148
161
149
        return $c->render(
162
        return $c->render(
150
            status  => 200,
163
            status  => 200,
(-)a/Koha/REST/V1/ExtendedAttributeTypes.pm (+1 lines)
Lines 54-59 sub list { Link Here
54
        agreement => 'erm_agreements',
54
        agreement => 'erm_agreements',
55
        package   => 'erm_packages',
55
        package   => 'erm_packages',
56
        order     => 'aqorders',
56
        order     => 'aqorders',
57
        vendor  => 'aqbooksellers:vendor',
57
    };
58
    };
58
59
59
    return try {
60
    return try {
(-)a/Koha/Schema/Result/Aqbookseller.pm (-1 / +32 lines)
Lines 566-571 __PACKAGE__->has_many( Link Here
566
    { cascade_copy        => 0, cascade_delete => 0 },
566
    { cascade_copy        => 0, cascade_delete => 0 },
567
);
567
);
568
568
569
__PACKAGE__->has_many(
570
    "additional_field_values",
571
    "Koha::Schema::Result::AdditionalFieldValue",
572
    sub {
573
        my ($args) = @_;
574
575
        return {
576
            "$args->{foreign_alias}.record_id" => { -ident => "$args->{self_alias}.id" },
577
578
            "$args->{foreign_alias}.field_id" =>
579
                { -in => \'(SELECT id FROM additional_fields WHERE tablename LIKE "aqbooksellers:%")' },
580
        };
581
    },
582
    { cascade_copy => 0, cascade_delete => 0 },
583
);
584
585
__PACKAGE__->has_many(
586
    "extended_attributes",
587
    "Koha::Schema::Result::AdditionalFieldValue",
588
    sub {
589
        my ($args) = @_;
590
591
        return {
592
            "$args->{foreign_alias}.record_id" => { -ident => "$args->{self_alias}.id" },
593
594
            "$args->{foreign_alias}.field_id" =>
595
                { -in => \'(SELECT id FROM additional_fields WHERE tablename LIKE "aqbooksellers:%")' },
596
        };
597
    },
598
    { cascade_copy => 0, cascade_delete => 0 },
599
);
600
569
sub koha_object_class {
601
sub koha_object_class {
570
    'Koha::Acquisition::Bookseller';
602
    'Koha::Acquisition::Bookseller';
571
}
603
}
572
- 

Return to bug 38262