From fccf6acc043b0dd95b992762bdc8182a4d6eae74 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Thu, 28 Jul 2022 10:30:55 +0200 Subject: [PATCH] Bug 32030: ERM - Add vendor to license ALTER TABLE erm_agreement_licenses DROP FOREIGN KEY erm_licenses_ibfk_1; ALTER TABLE erm_agreement_licenses DROP FOREIGN KEY erm_licenses_ibfk_2; ALTER TABLE erm_agreement_licenses ADD CONSTRAINT `erm_agreement_licenses_ibfk_1` FOREIGN KEY (`agreement_id`) REFERENCES `erm_agreements` (`agreement_id`) ON DELETE CASCADE ON UPDATE CASCADE; ALTER TABLE erm_agreement_licenses ADD CONSTRAINT `erm_agreement_licenses_ibfk_2` FOREIGN KEY (`license_id`) REFERENCES `erm_licenses` (`license_id`) ON DELETE CASCADE ON UPDATE CASCADE; ALTER TABLE erm_licenses ADD COLUMN vendor_id INT(11) DEFAULT NULL AFTER license_id; ALTER TABLE erm_licenses ADD CONSTRAINT `erm_licenses_ibfk_1` FOREIGN KEY (`vendor_id`) REFERENCES `aqbooksellers` (`id`) ON DELETE SET NULL ON UPDATE CASCADE; Signed-off-by: Jonathan Field Signed-off-by: Martin Renvoize Signed-off-by: Kyle M Hall Signed-off-by: Tomas Cohen Arazi --- Koha/ERM/Agreement.pm | 14 ++++++++ Koha/ERM/License.pm | 15 ++++++++ api/v1/swagger/definitions/erm_agreement.yaml | 5 +++ api/v1/swagger/definitions/erm_license.yaml | 11 ++++++ api/v1/swagger/paths/erm_licenses.yaml | 5 +++ installer/data/mysql/atomicupdate/erm.pl | 6 ++-- installer/data/mysql/kohastructure.sql | 6 ++-- .../vue/components/ERM/AgreementsFormAdd.vue | 1 + .../js/vue/components/ERM/AgreementsShow.vue | 14 ++------ .../js/vue/components/ERM/LicensesFormAdd.vue | 34 +++++++++++++++++++ .../js/vue/components/ERM/LicensesList.vue | 29 ++++++++++++++-- .../js/vue/components/ERM/LicensesShow.vue | 13 ++++++- koha-tmpl/intranet-tmpl/prog/js/vue/fetch.js | 14 ++++++-- 13 files changed, 145 insertions(+), 22 deletions(-) diff --git a/Koha/ERM/Agreement.pm b/Koha/ERM/Agreement.pm index cc867ef66a..2c6692842f 100644 --- a/Koha/ERM/Agreement.pm +++ b/Koha/ERM/Agreement.pm @@ -23,6 +23,7 @@ use MIME::Types; use Koha::Database; use Koha::DateUtils qw( dt_from_string ); use Koha::Exceptions; +use Koha::Acquisition::Bookseller; use base qw(Koha::Object); @@ -257,6 +258,19 @@ sub agreement_packages { return Koha::ERM::EHoldings::Package::Agreements->_new_from_dbic($packages_agreements_rs); } +=head3 vendor + +Return the vendor for this agreement + +=cut + +sub vendor { + my ( $self ) = @_; + my $vendor_rs = $self->_result->vendor; + return unless $vendor_rs; + return Koha::Acquisition::Bookseller->_new_from_dbic($vendor_rs); +} + =head2 Internal methods =head3 _type diff --git a/Koha/ERM/License.pm b/Koha/ERM/License.pm index cd798ff794..86f20ac10a 100644 --- a/Koha/ERM/License.pm +++ b/Koha/ERM/License.pm @@ -21,6 +21,8 @@ use Koha::Database; use base qw(Koha::Object); +use Koha::Acquisition::Bookseller; + =head1 NAME Koha::ERM::License - Koha ERM License Object class @@ -31,6 +33,19 @@ Koha::ERM::License - Koha ERM License Object class =cut +=head3 vendor + +Return the vendor for this license + +=cut + +sub vendor { + my ( $self ) = @_; + my $vendor_rs = $self->_result->vendor; + return unless $vendor_rs; + return Koha::Acquisition::Bookseller->_new_from_dbic($vendor_rs); +} + =head2 Internal methods =head3 _type diff --git a/api/v1/swagger/definitions/erm_agreement.yaml b/api/v1/swagger/definitions/erm_agreement.yaml index 8e4bf4bd62..88f80f180e 100644 --- a/api/v1/swagger/definitions/erm_agreement.yaml +++ b/api/v1/swagger/definitions/erm_agreement.yaml @@ -64,6 +64,11 @@ properties: description: documents items: $ref: erm_agreement_document.yaml + vendor: + description: Information about the vendor + type: + - object + - "null" additionalProperties: false required: diff --git a/api/v1/swagger/definitions/erm_license.yaml b/api/v1/swagger/definitions/erm_license.yaml index 3431f52082..f9b52dcab1 100644 --- a/api/v1/swagger/definitions/erm_license.yaml +++ b/api/v1/swagger/definitions/erm_license.yaml @@ -5,6 +5,11 @@ properties: type: integer description: internally assigned license identifier readOnly: true + vendor_id: + description: foreign key to aqbooksellers + type: + - integer + - "null" name: description: name of the license type: string @@ -33,6 +38,12 @@ properties: - "null" format: date description: End of the license + vendor: + description: Information about the vendor + type: + - object + - "null" + additionalProperties: false required: - license_id diff --git a/api/v1/swagger/paths/erm_licenses.yaml b/api/v1/swagger/paths/erm_licenses.yaml index 74b88975d3..ad2dd8ce8a 100644 --- a/api/v1/swagger/paths/erm_licenses.yaml +++ b/api/v1/swagger/paths/erm_licenses.yaml @@ -14,6 +14,11 @@ name: license_id required: false type: integer + - description: Case insensitive search on agreement vendor_id + in: query + name: vendor_id + required: false + type: integer - description: Case insensitive search on license name in: query name: name diff --git a/installer/data/mysql/atomicupdate/erm.pl b/installer/data/mysql/atomicupdate/erm.pl index f4a96933a8..df7d09fc94 100755 --- a/installer/data/mysql/atomicupdate/erm.pl +++ b/installer/data/mysql/atomicupdate/erm.pl @@ -97,12 +97,14 @@ return { $dbh->do(q{ CREATE TABLE `erm_licenses` ( `license_id` INT(11) NOT NULL AUTO_INCREMENT COMMENT 'primary key', + `vendor_id` INT(11) DEFAULT NULL COMMENT 'foreign key to aqbooksellers', `name` VARCHAR(255) NOT NULL COMMENT 'name of the license', `description` LONGTEXT DEFAULT NULL COMMENT 'description of the license', `type` VARCHAR(80) NOT NULL COMMENT 'type of the license', `status` VARCHAR(80) NOT NULL COMMENT 'current status of the license', `started_on` DATE COMMENT 'start of the license', `ended_on` DATE COMMENT 'end of the license', + CONSTRAINT `erm_licenses_ibfk_1` FOREIGN KEY (`vendor_id`) REFERENCES `aqbooksellers` (`id`) ON DELETE SET NULL ON UPDATE CASCADE, PRIMARY KEY(`license_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; }); @@ -117,8 +119,8 @@ return { `physical_location` VARCHAR(80) DEFAULT NULL COMMENT 'physical location of the license', `notes` mediumtext DEFAULT NULL COMMENT 'notes about this license', `uri` varchar(255) DEFAULT NULL COMMENT 'URI of the license', - CONSTRAINT `erm_licenses_ibfk_1` FOREIGN KEY (`agreement_id`) REFERENCES `erm_agreements` (`agreement_id`) ON DELETE CASCADE ON UPDATE CASCADE, - CONSTRAINT `erm_licenses_ibfk_2` FOREIGN KEY (`license_id`) REFERENCES `erm_licenses` (`license_id`) ON DELETE CASCADE ON UPDATE CASCADE, + CONSTRAINT `erm_agreement_licenses_ibfk_1` FOREIGN KEY (`agreement_id`) REFERENCES `erm_agreements` (`agreement_id`) ON DELETE CASCADE ON UPDATE CASCADE, + CONSTRAINT `erm_agreement_licenses_ibfk_2` FOREIGN KEY (`license_id`) REFERENCES `erm_licenses` (`license_id`) ON DELETE CASCADE ON UPDATE CASCADE, PRIMARY KEY(`agreement_license_id`), UNIQUE KEY `erm_agreement_licenses_uniq` (`agreement_id`, `license_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; diff --git a/installer/data/mysql/kohastructure.sql b/installer/data/mysql/kohastructure.sql index 7eeb7f6404..8128681f6a 100644 --- a/installer/data/mysql/kohastructure.sql +++ b/installer/data/mysql/kohastructure.sql @@ -2830,12 +2830,14 @@ CREATE TABLE `erm_agreement_user_roles` ( DROP TABLE IF EXISTS `erm_licenses`; CREATE TABLE `erm_licenses` ( `license_id` INT(11) NOT NULL AUTO_INCREMENT COMMENT 'primary key', + `vendor_id` INT(11) DEFAULT NULL COMMENT 'foreign key to aqbooksellers', `name` VARCHAR(255) NOT NULL COMMENT 'name of the license', `description` LONGTEXT DEFAULT NULL COMMENT 'description of the license', `type` VARCHAR(80) NOT NULL COMMENT 'type of the license', `status` VARCHAR(80) NOT NULL COMMENT 'current status of the license', `started_on` DATE COMMENT 'start of the license', `ended_on` DATE COMMENT 'end of the license', + CONSTRAINT `erm_licenses_ibfk_1` FOREIGN KEY (`vendor_id`) REFERENCES `aqbooksellers` (`id`) ON DELETE SET NULL ON UPDATE CASCADE, PRIMARY KEY(`license_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; @@ -2852,8 +2854,8 @@ CREATE TABLE `erm_agreement_licenses` ( `physical_location` VARCHAR(80) DEFAULT NULL COMMENT 'physical location of the license', `notes` mediumtext DEFAULT NULL COMMENT 'notes about this license', `uri` varchar(255) DEFAULT NULL COMMENT 'URI of the license', - CONSTRAINT `erm_licenses_ibfk_1` FOREIGN KEY (`agreement_id`) REFERENCES `erm_agreements` (`agreement_id`) ON DELETE CASCADE ON UPDATE CASCADE, - CONSTRAINT `erm_licenses_ibfk_2` FOREIGN KEY (`license_id`) REFERENCES `erm_licenses` (`license_id`) ON DELETE CASCADE ON UPDATE CASCADE, + CONSTRAINT `erm_agreement_licenses_ibfk_1` FOREIGN KEY (`agreement_id`) REFERENCES `erm_agreements` (`agreement_id`) ON DELETE CASCADE ON UPDATE CASCADE, + CONSTRAINT `erm_agreement_licenses_ibfk_2` FOREIGN KEY (`license_id`) REFERENCES `erm_licenses` (`license_id`) ON DELETE CASCADE ON UPDATE CASCADE, PRIMARY KEY(`agreement_license_id`), UNIQUE KEY `erm_agreement_licenses_uniq` (`agreement_id`, `license_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; diff --git a/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/AgreementsFormAdd.vue b/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/AgreementsFormAdd.vue index 28c529960d..cfe56967ec 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/AgreementsFormAdd.vue +++ b/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/AgreementsFormAdd.vue @@ -332,6 +332,7 @@ export default { apiUrl += '/' + agreement.agreement_id } delete agreement.agreement_id + delete agreement.vendor agreement.is_perpetual = agreement.is_perpetual ? true : false if (agreement.vendor_id == "") { diff --git a/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/AgreementsShow.vue b/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/AgreementsShow.vue index 240da65d50..10dec21003 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/AgreementsShow.vue +++ b/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/AgreementsShow.vue @@ -32,12 +32,8 @@ - {{ - vendors.find( - (e) => e.id == agreement.vendor_id - ).name - }} + {{ agreement.vendor.name }} +
  • @@ -303,19 +299,14 @@