Subject: [PATCH 05/16] Not working. Trying to get branches to show up in guided_reports_start.tt.

From: Casey Conlin <[email-masked]>
Date: Sun, 6 Jul 2025 18:54:25 -0400

---
 Koha/Report.pm                                | 16 +++-
 Koha/Reports.pm                               |  2 +-
 Koha/Schema/Result/ReportsBranch.pm           | 87 +++++++++++++++++++
 .../modules/reports/guided_reports_start.tt   |  2 +-
 4 files changed, 104 insertions(+), 3 deletions(-)
 create mode 100644 Koha/Schema/Result/ReportsBranch.pm

diff --git a/Koha/Report.pm b/Koha/Report.pm
index 54511cdc4c..2f8da9de2b 100644
--- a/Koha/Report.pm
+++ b/Koha/Report.pm
@@ -22,7 +22,7 @@ use Koha::Reports;
 
 #use Koha::DateUtils qw( dt_from_string output_pref );
 
-use base qw(Koha::Object);
+use base qw(Koha::Object Koha::Object::Limit::Library);
 #
 # FIXME We could only return an error code instead of the arrayref
 # Only 1 error is returned
@@ -258,6 +258,20 @@ sub _might_add_limit {
     return $sql;
 }
 
+=head3 _library_limits
+
+Configurable library limits
+
+=cut
+
+sub _library_limits {
+    return {
+        class   => "ReportsBranch",
+        id      => "report_id",
+        library => "branchcode",
+    };
+}
+
 =head3 _type
 
 Returns name of corresponding DBIC resultset
diff --git a/Koha/Reports.pm b/Koha/Reports.pm
index 7d99232b9b..605a1fc0aa 100644
--- a/Koha/Reports.pm
+++ b/Koha/Reports.pm
@@ -21,7 +21,7 @@ use Koha::Database;
 
 use Koha::Report;
 
-use base qw(Koha::Objects);
+use base qw(Koha::Objects Koha::Objects::Limit::Library);
 
 =head1 NAME
 
diff --git a/Koha/Schema/Result/ReportsBranch.pm b/Koha/Schema/Result/ReportsBranch.pm
new file mode 100644
index 0000000000..d6d40f71b3
--- /dev/null
+++ b/Koha/Schema/Result/ReportsBranch.pm
@@ -0,0 +1,87 @@
+use utf8;
+package Koha::Schema::Result::ReportsBranch;
+
+# Created by DBIx::Class::Schema::Loader
+# DO NOT MODIFY THE FIRST PART OF THIS FILE
+
+=head1 NAME
+
+Koha::Schema::Result::ItemtypesBranch
+
+=cut
+
+use strict;
+use warnings;
+
+use base 'DBIx::Class::Core';
+
+=head1 TABLE: C<itemtypes_branches>
+
+=cut
+
+__PACKAGE__->table("reports_branches");
+
+=head1 ACCESSORS
+
+=head2 report_id
+
+  data_type: 'varchar'
+  is_foreign_key: 1
+  is_nullable: 1
+  size: 80
+
+=head2 branchcode
+
+  data_type: 'varchar'
+  is_foreign_key: 1
+  is_nullable: 0
+  size: 10
+
+=cut
+
+__PACKAGE__->add_columns(
+  "report_id",
+  { data_type => "varchar", is_foreign_key => 1, is_nullable => 1, size => 80 },
+  "branchcode",
+  { data_type => "varchar", is_foreign_key => 1, is_nullable => 0, size => 10 },
+);
+
+=head1 RELATIONS
+
+=head2 branchcode
+
+Type: belongs_to
+
+Related object: L<Koha::Schema::Result::Branch>
+
+=cut
+
+__PACKAGE__->belongs_to(
+  "branchcode",
+  "Koha::Schema::Result::Branch",
+  { branchcode => "branchcode" },
+  { is_deferrable => 1, on_delete => "CASCADE", on_update => "RESTRICT" },
+);
+
+=head2 itemtype
+
+Type: belongs_to
+
+Related object: L<Koha::Schema::Result::Itemtype>
+
+=cut
+
+__PACKAGE__->belongs_to(
+  "report_id",
+  "Koha::Schema::Result::Report",
+  { report_id => "report_id" },
+  { is_deferrable => 1, on_delete => "CASCADE", on_update => "RESTRICT" },
+);
+
+
+# Created by DBIx::Class::Schema::Loader v0.07048 @ 2019-07-04 04:56:48
+# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:cBTswjKV8VWN1iueB+PygQ
+
+
+# You can replace this text with custom code or comments, and it will be preserved on regeneration
+1;
diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/reports/guided_reports_start.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/reports/guided_reports_start.tt
index f418345d03..b6aa9bc032 100644
--- a/koha-tmpl/intranet-tmpl/prog/en/modules/reports/guided_reports_start.tt
+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/reports/guided_reports_start.tt
@@ -1554,7 +1554,7 @@
                                 <div
                                 ><label for="library_limitation">Library limitation: </label>
                                     <select id="library_limitation" name="branches" multiple size="10">
-                                        [% PROCESS options_for_libraries libraries => Branches.all( selected => itemtype.get_library_limits, unfiltered => 1, do_not_select_my_library => 1 ) %]
+                                        [% PROCESS options_for_libraries libraries => Branches.all( selected => savedreport.savedsql.get_library_limits, unfiltered => 1, do_not_select_my_library => 1 ) %]
                                     </select>
                                     <div class="hint">Limits the use of this report to the selected libraries.</div>
                                 </div>
-- 
2.39.5