Bug 38262: Enable additional fields support for acquisition vendors
Implements backend support for additional fields on vendor records by: - Adding AdditionalFields mixin to Bookseller/Booksellers classes - Defining additional_field_values and extended_attributes relationships in Aqbookseller schema with proper table name filtering - Updating REST API controller to handle extended_attributes during vendor creation and updates - Adding vendor to AdditionalField resource type mapping This provides the ORM-level support needed for vendors to have custom additional fields, matching the existing pattern used for other resource types like agreements, packages, and orders. Signed-off-by: David Nind <david@davidnind.com> Signed-off-by: Martin Renvoize <martin.renvoize@openfifth.co.uk> Signed-off-by: Michaela <michaela.sieber@kit.edu> Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>
This commit is contained in:
parent
ee6f5a3ee9
commit
0c4ccf6d6f
|
|
@ -25,7 +25,7 @@ use Koha::Subscriptions;
|
|||
|
||||
use C4::Contract qw( GetContracts );
|
||||
|
||||
use base qw( Koha::Object );
|
||||
use base qw( Koha::Object::Mixin::AdditionalFields Koha::Object );
|
||||
|
||||
=head1 NAME
|
||||
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ use Modern::Perl;
|
|||
|
||||
use Koha::Acquisition::Bookseller;
|
||||
|
||||
use base qw( Koha::Objects );
|
||||
use base qw( Koha::Object::Mixin::AdditionalFields Koha::Objects );
|
||||
|
||||
=head1 NAME
|
||||
|
||||
|
|
|
|||
|
|
@ -55,14 +55,15 @@ sub to_api {
|
|||
my ( $self, $params ) = @_;
|
||||
|
||||
my $table_to_resource = {
|
||||
'accountlines:credit' => 'credit',
|
||||
'accountlines:debit' => 'debit',
|
||||
'aqbasket' => 'basket',
|
||||
'aqinvoices' => 'invoice',
|
||||
'erm_licenses' => 'license',
|
||||
'erm_agreements' => 'agreement',
|
||||
'erm_packages' => 'package',
|
||||
'aqorders' => 'order',
|
||||
'accountlines:credit' => 'credit',
|
||||
'accountlines:debit' => 'debit',
|
||||
'aqbasket' => 'basket',
|
||||
'aqinvoices' => 'invoice',
|
||||
'erm_licenses' => 'license',
|
||||
'erm_agreements' => 'agreement',
|
||||
'erm_packages' => 'package',
|
||||
'aqorders' => 'order',
|
||||
'aqbooksellers:vendor' => 'vendor',
|
||||
};
|
||||
|
||||
my $json = $self->SUPER::to_api($params);
|
||||
|
|
|
|||
|
|
@ -99,10 +99,11 @@ Controller function that handles adding a new Koha::Acquisition::Bookseller obje
|
|||
sub add {
|
||||
my $c = shift->openapi->valid_input or return;
|
||||
|
||||
my $vendor = $c->req->json;
|
||||
my $contacts = delete $vendor->{contacts};
|
||||
my $interfaces = delete $vendor->{interfaces};
|
||||
my $aliases = delete $vendor->{aliases};
|
||||
my $vendor = $c->req->json;
|
||||
my $contacts = delete $vendor->{contacts};
|
||||
my $interfaces = delete $vendor->{interfaces};
|
||||
my $aliases = delete $vendor->{aliases};
|
||||
my $extended_attributes = delete $vendor->{extended_attributes};
|
||||
|
||||
my $vendor_to_store = Koha::Acquisition::Bookseller->new_from_api( $c->req->json );
|
||||
|
||||
|
|
@ -113,6 +114,12 @@ sub add {
|
|||
$vendor_to_store->aliases( $aliases || [] );
|
||||
$vendor_to_store->interfaces( $interfaces || [] );
|
||||
|
||||
if ( scalar(@$extended_attributes) > 0 ) {
|
||||
my @extended_attributes =
|
||||
map { { 'id' => $_->{field_id}, 'value' => $_->{value} } } @{$extended_attributes};
|
||||
$vendor_to_store->extended_attributes( \@extended_attributes );
|
||||
}
|
||||
|
||||
$c->res->headers->location( $c->req->url->to_string . '/' . $vendor_to_store->id );
|
||||
return $c->render(
|
||||
status => 201,
|
||||
|
|
@ -143,6 +150,8 @@ sub update {
|
|||
my $contacts = exists $vendor_update->{contacts} ? delete $vendor_update->{contacts} : undef;
|
||||
my $interfaces = exists $vendor_update->{interfaces} ? delete $vendor_update->{interfaces} : undef;
|
||||
my $aliases = exists $vendor_update->{aliases} ? delete $vendor_update->{aliases} : undef;
|
||||
my $extended_attributes =
|
||||
exists $vendor_update->{extended_attributes} ? delete $vendor_update->{extended_attributes} : undef;
|
||||
|
||||
$vendor->set_from_api($vendor_update);
|
||||
$vendor->store();
|
||||
|
|
@ -151,6 +160,12 @@ sub update {
|
|||
$vendor->aliases( $aliases || [] ) if defined $aliases;
|
||||
$vendor->interfaces( $interfaces || [] ) if defined $interfaces;
|
||||
|
||||
if ( scalar(@$extended_attributes) > 0 ) {
|
||||
my @extended_attributes =
|
||||
map { { 'id' => $_->{field_id}, 'value' => $_->{value} } } @{$extended_attributes};
|
||||
$vendor->extended_attributes( \@extended_attributes );
|
||||
}
|
||||
|
||||
return $c->render(
|
||||
status => 200,
|
||||
openapi => $c->objects->to_api($vendor),
|
||||
|
|
|
|||
|
|
@ -52,6 +52,7 @@ sub _list {
|
|||
agreement => 'erm_agreements',
|
||||
package => 'erm_packages',
|
||||
order => 'aqorders',
|
||||
vendor => 'aqbooksellers:vendor',
|
||||
};
|
||||
|
||||
my @tables;
|
||||
|
|
|
|||
|
|
@ -565,6 +565,38 @@ __PACKAGE__->has_many(
|
|||
{ cascade_copy => 0, cascade_delete => 0 },
|
||||
);
|
||||
|
||||
__PACKAGE__->has_many(
|
||||
"additional_field_values",
|
||||
"Koha::Schema::Result::AdditionalFieldValue",
|
||||
sub {
|
||||
my ($args) = @_;
|
||||
|
||||
return {
|
||||
"$args->{foreign_alias}.record_id" => { -ident => "$args->{self_alias}.id" },
|
||||
|
||||
"$args->{foreign_alias}.field_id" =>
|
||||
{ -in => \'(SELECT id FROM additional_fields WHERE tablename LIKE "aqbooksellers:%")' },
|
||||
};
|
||||
},
|
||||
{ cascade_copy => 0, cascade_delete => 0 },
|
||||
);
|
||||
|
||||
__PACKAGE__->has_many(
|
||||
"extended_attributes",
|
||||
"Koha::Schema::Result::AdditionalFieldValue",
|
||||
sub {
|
||||
my ($args) = @_;
|
||||
|
||||
return {
|
||||
"$args->{foreign_alias}.record_id" => { -ident => "$args->{self_alias}.id" },
|
||||
|
||||
"$args->{foreign_alias}.field_id" =>
|
||||
{ -in => \'(SELECT id FROM additional_fields WHERE tablename LIKE "aqbooksellers:%")' },
|
||||
};
|
||||
},
|
||||
{ cascade_copy => 0, cascade_delete => 0 },
|
||||
);
|
||||
|
||||
=head2 koha_object_class
|
||||
|
||||
Missing POD for koha_object_class.
|
||||
|
|
|
|||
Loading…
Reference in New Issue