Bug 32030: Add eholdings.vendor_id
authorJonathan Druart <jonathan.druart@bugs.koha-community.org>
Wed, 25 May 2022 11:41:21 +0000 (13:41 +0200)
committerTomas Cohen Arazi <tomascohen@theke.io>
Tue, 8 Nov 2022 12:44:00 +0000 (09:44 -0300)
Signed-off-by: Jonathan Field <jonathan.field@ptfs-europe.com>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
api/v1/swagger/definitions/erm_eholding.yaml
api/v1/swagger/paths/erm_eholdings.yaml
installer/data/mysql/atomicupdate/erm.pl
installer/data/mysql/kohastructure.sql
koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/EHoldingsFormAdd.vue
koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/EHoldingsList.vue
koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/EHoldingsShow.vue

index 36ce4b7..61847b3 100644 (file)
@@ -5,6 +5,11 @@ properties:
     type: integer
     description: internally assigned identifier
     readOnly: true
+  vendor_id:
+    description: foreign key to aqbooksellers
+    type:
+      - integer
+      - "null"
   publication_title:
     description: publication_title of the eHolding
     type: string
index b7d769d..280a7bf 100644 (file)
         name: eholding_id
         required: false
         type: integer
+      - description: Case insensitive search on eholding vendor_id
+        in: query
+        name: vendor_id
+        required: false
+        type: integer
       - description: Case insensitive search on eholding publication_title
         in: query
         name: publication_title
index 859b4ca..c892174 100755 (executable)
@@ -215,6 +215,7 @@ return {
             $dbh->do(q{
                 CREATE TABLE `erm_eholdings` (
                     `eholding_id` INT(11) NOT NULL AUTO_INCREMENT COMMENT 'primary key',
+                    `vendor_id` INT(11) DEFAULT NULL,
                     `publication_title` VARCHAR(255) DEFAULT NULL,
                     `print_identifier` VARCHAR(255) DEFAULT NULL,
                     `online_identifier` VARCHAR(255) DEFAULT NULL,
@@ -240,6 +241,7 @@ return {
                     `parent_publication_title_id` VARCHAR(255) DEFAULT NULL,
                     `preceeding_publication_title_id` VARCHAR(255) DEFAULT NULL,
                     `access_type` VARCHAR(255) DEFAULT NULL,
+                    CONSTRAINT `erm_eholdings_ibfk_1` FOREIGN KEY (`vendor_id`) REFERENCES `aqbooksellers` (`id`) ON DELETE SET NULL ON UPDATE CASCADE,
                     PRIMARY KEY(`eholding_id`)
                 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
             });
index fc22324..f5a6253 100644 (file)
@@ -2928,6 +2928,7 @@ CREATE TABLE `erm_packages_agreements` (
 DROP TABLE IF EXISTS `erm_eholdings`;
 CREATE TABLE `erm_eholdings` (
     `eholding_id` INT(11) NOT NULL AUTO_INCREMENT COMMENT 'primary key',
+    `vendor_id` INT(11) DEFAULT NULL,
     `publication_title` VARCHAR(255) DEFAULT NULL,
     `print_identifier` VARCHAR(255) DEFAULT NULL,
     `online_identifier` VARCHAR(255) DEFAULT NULL,
@@ -2953,6 +2954,7 @@ CREATE TABLE `erm_eholdings` (
     `parent_publication_title_id` VARCHAR(255) DEFAULT NULL,
     `preceeding_publication_title_id` VARCHAR(255) DEFAULT NULL,
     `access_type` VARCHAR(255) DEFAULT NULL,
+    CONSTRAINT `erm_eholdings_ibfk_1` FOREIGN KEY (`vendor_id`) REFERENCES `aqbooksellers` (`id`) ON DELETE SET NULL ON UPDATE CASCADE,
     PRIMARY KEY(`eholding_id`)
 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
 
index bdb3d00..df7eb85 100644 (file)
                         </li>
 
                         <li>
+                            <label for="eholding_vendor_id">{{
+                                $t("Vendor:")
+                            }}</label>
+                            <select
+                                id="eholding_vendor_id"
+                                v-model="eholding.vendor_id"
+                            >
+                                <option value=""></option>
+                                <option
+                                    v-for="vendor in vendors"
+                                    :key="vendor.vendor_id"
+                                    :value="vendor.id"
+                                    :selected="
+                                        vendor.id == eholding.vendor_id
+                                            ? true
+                                            : false
+                                    "
+                                >
+                                    {{ vendor.name }}
+                                </option>
+                            </select>
+                        </li>
+
+                        <li>
                             <label for="eholding_print_identifier">{{
                                 $t("Print-format identifier:")
                             }}</label>
 </template>
 
 <script>
+import { useVendorStore } from "../../stores/vendors"
 import EHoldingPackages from "./EHoldingPackages.vue"
 import { setMessage, setError } from "../../messages"
 import { fetchEHolding } from '../../fetch'
+import { storeToRefs } from "pinia"
 
 export default {
     setup() {
+        const vendorStore = useVendorStore()
+        const { vendors } = storeToRefs(vendorStore)
+
+        return {
+            vendors,
+        }
     },
     data() {
         return {
             eholding: {
                 eholding_id: null,
+                vendor_id: null,
                 publication_title: '',
                 print_identifier: '',
                 online_identifier: '',
index 3516470..14dd771 100644 (file)
 <script>
 import Toolbar from "./EHoldingsToolbar.vue"
 import { createVNode, render } from 'vue'
+import { useVendorStore } from "../../stores/vendors"
+import { storeToRefs } from "pinia"
 import { fetchEHoldings } from "../../fetch"
 
 export default {
+    setup() {
+        const vendorStore = useVendorStore()
+        const { vendors } = storeToRefs(vendorStore)
+
+        return {
+            vendors,
+        }
+    },
     data: function () {
         return {
             eholdings: [],
@@ -48,6 +58,16 @@ export default {
         let edit_eholding = this.edit_eholding
         let delete_eholding = this.delete_eholding
 
+        window['vendors'] = this.vendors.map(e => {
+            e['_id'] = e['id']
+            e['_str'] = e['name']
+            return e
+        })
+        let vendors_map = this.vendors.reduce((map, e) => {
+            map[e.id] = e
+            return map
+        }, {})
+
         $('#eholding_list').kohaTable({
             "ajax": {
                 "url": eholdings_table_url,
@@ -71,6 +91,15 @@ export default {
                     // Rendering done in drawCallback
                 },
                 {
+                    "title": __("Vendor"),
+                    "data": "vendor_id",
+                    "searchable": true,
+                    "orderable": true,
+                    "render": function (data, type, row, meta) {
+                        return row.vendor_id != undefined ? escape_str(vendors_map[row.vendor_id].name) : ""
+                    }
+                },
+                {
                     "title": __("Publication type"),
                     "data": "publication_type",
                     "searchable": true,
@@ -84,8 +113,8 @@ export default {
                     "render": function (data, type, row, meta) {
                         let print_identifier = row.print_identifier
                         let online_identifier = row.online_identifier
-                        return ( print_identifier ? escape_str(_("ISBN (Print): %s").format(print_identifier)) : "" ) + 
-                               ( online_identifier ? escape_str(_("ISBN (Online): %s").format(online_identifier)) : "" )
+                        return (print_identifier ? escape_str(_("ISBN (Print): %s").format(print_identifier)) : "") +
+                            (online_identifier ? escape_str(_("ISBN (Online): %s").format(online_identifier)) : "")
                     }
                 },
                 {
@@ -136,6 +165,10 @@ export default {
                     render(n, e)
                 })
             },
+            preDrawCallback: function (settings) {
+                var table_id = settings.nTable.id
+                $("#" + table_id).find("thead th").eq(2).attr('data-filter', 'vendors')
+            }
         }, eholding_table_settings, 1)
     },
     beforeUnmount() {
index 07e70e5..267de21 100644 (file)
                         </span>
                     </li>
                     <li>
+                        <label>{{ $t("Vendor:") }}</label>
+                        <span v-if="eholding.vendor_id">
+                            {{
+                                vendors.find((e) => e.id == eholding.vendor_id)
+                                    .name
+                            }}
+                        </span>
+                    </li>
+                    <li>
                         <label>{{ $t("Print-format identifier:") }}</label>
                         <span>
                             {{ eholding.print_identifier }}
 
 <script>
 import { fetchEHolding } from "../../fetch"
-
+import { useVendorStore } from "../../stores/vendors"
+import { storeToRefs } from "pinia"
 export default {
     setup() {
+        const vendorStore = useVendorStore()
+        const { vendors } = storeToRefs(vendorStore)
+
+        return {
+            vendors,
+        }
     },
     data() {
         return {
             eholding: {
                 eholding_id: null,
+                vendor_id: null,
                 publication_title: '',
                 print_identifier: '',
                 online_identifier: '',