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 104-111 sub add { Link Here
104
            $contact->{booksellerid} = $vendor_to_store->id;
105
            $contact->{booksellerid} = $vendor_to_store->id;
105
            Koha::Acquisition::Bookseller::Contact->new($contact)->store;
106
            Koha::Acquisition::Bookseller::Contact->new($contact)->store;
106
        }
107
        }
107
        $vendor_to_store->aliases($aliases)       if scalar($aliases) > 0;
108
        $vendor_to_store->aliases($aliases)       if scalar(@$aliases) > 0;
108
        $vendor_to_store->interfaces($interfaces) if scalar($interfaces) > 0;
109
        $vendor_to_store->interfaces($interfaces) if scalar(@$interfaces) > 0;
110
111
        if(scalar(@$extended_attributes) > 0) {
112
            my @extended_attributes = map { { 'id' => $_->{field_id}, 'value' => $_->{value} } } @{$extended_attributes};
113
            $vendor_to_store->extended_attributes( \@extended_attributes );
114
        }
109
115
110
        $c->res->headers->location( $c->req->url->to_string . '/' . $vendor_to_store->id );
116
        $c->res->headers->location( $c->req->url->to_string . '/' . $vendor_to_store->id );
111
        return $c->render(
117
        return $c->render(
Lines 134-146 sub update { Link Here
134
        unless $vendor;
140
        unless $vendor;
135
141
136
    return try {
142
    return try {
137
        my $vendor_update = $c->req->json;
143
        my $vendor_update       = $c->req->json;
138
        my $contacts      = delete $vendor_update->{contacts};
144
        my $contacts            = delete $vendor_update->{contacts};
139
        my $interfaces    = delete $vendor_update->{interfaces};
145
        my $interfaces          = delete $vendor_update->{interfaces};
140
        my $aliases       = delete $vendor_update->{aliases};
146
        my $aliases             = delete $vendor_update->{aliases};
141
        my $subscriptions = delete $vendor_update->{subscriptions};
147
        my $subscriptions       = delete $vendor_update->{subscriptions};
142
        my $baskets       = delete $vendor_update->{baskets};
148
        my $baskets             = delete $vendor_update->{baskets};
143
        my $contracts     = delete $vendor_update->{contracts};
149
        my $contracts           = delete $vendor_update->{contracts};
150
        my $extended_attributes = delete $vendor_update->{extended_attributes};
144
151
145
        $vendor->set_from_api($vendor_update);
152
        $vendor->set_from_api($vendor_update);
146
        $vendor->store();
153
        $vendor->store();
Lines 149-156 sub update { Link Here
149
            $contact->{booksellerid} = $vendor_id;
156
            $contact->{booksellerid} = $vendor_id;
150
            Koha::Acquisition::Bookseller::Contact->new($contact)->store;
157
            Koha::Acquisition::Bookseller::Contact->new($contact)->store;
151
        }
158
        }
152
        $vendor->aliases($aliases)       if scalar($aliases) > 0;
159
        $vendor->aliases($aliases)       if scalar(@$aliases) > 0;
153
        $vendor->interfaces($interfaces) if scalar($interfaces) > 0;
160
        $vendor->interfaces($interfaces) if scalar(@$interfaces) > 0;
161
162
        if ( scalar(@$extended_attributes) > 0 ) {
163
            my @extended_attributes =
164
                map { { 'id' => $_->{field_id}, 'value' => $_->{value} } } @{$extended_attributes};
165
            $vendor->extended_attributes( \@extended_attributes );
166
        }
154
167
155
        return $c->render(
168
        return $c->render(
156
            status  => 200,
169
            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 601-606 __PACKAGE__->has_many( Link Here
601
    { cascade_copy        => 0, cascade_delete => 0 },
601
    { cascade_copy        => 0, cascade_delete => 0 },
602
);
602
);
603
603
604
__PACKAGE__->has_many(
605
    "additional_field_values",
606
    "Koha::Schema::Result::AdditionalFieldValue",
607
    sub {
608
        my ($args) = @_;
609
610
        return {
611
            "$args->{foreign_alias}.record_id" => { -ident => "$args->{self_alias}.id" },
612
613
            "$args->{foreign_alias}.field_id" =>
614
                { -in => \'(SELECT id FROM additional_fields WHERE tablename LIKE "aqbooksellers:%")' },
615
        };
616
    },
617
    { cascade_copy => 0, cascade_delete => 0 },
618
);
619
620
__PACKAGE__->has_many(
621
    "extended_attributes",
622
    "Koha::Schema::Result::AdditionalFieldValue",
623
    sub {
624
        my ($args) = @_;
625
626
        return {
627
            "$args->{foreign_alias}.record_id" => { -ident => "$args->{self_alias}.id" },
628
629
            "$args->{foreign_alias}.field_id" =>
630
                { -in => \'(SELECT id FROM additional_fields WHERE tablename LIKE "aqbooksellers:%")' },
631
        };
632
    },
633
    { cascade_copy => 0, cascade_delete => 0 },
634
);
635
604
sub koha_object_class {
636
sub koha_object_class {
605
    'Koha::Acquisition::Bookseller';
637
    'Koha::Acquisition::Bookseller';
606
}
638
}
607
- 

Return to bug 38262