[freeside-commits] branch master updated. 974347d88d264c60e65cbd22ac52553931b25ab8

Mark Wells mark at 420.am
Thu Nov 26 12:08:30 PST 2015


The branch, master has been updated
       via  974347d88d264c60e65cbd22ac52553931b25ab8 (commit)
      from  d5f8aa5cf1787238224add1a836f0d7577f3b9b7 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit 974347d88d264c60e65cbd22ac52553931b25ab8
Author: Mark Wells <mark at freeside.biz>
Date:   Wed Nov 25 15:08:05 2015 -0800

    add service location to RT ticket search, #19154

diff --git a/rt/lib/RT/URI/freeside/Internal.pm b/rt/lib/RT/URI/freeside/Internal.pm
index 33831bc..2b09c87 100644
--- a/rt/lib/RT/URI/freeside/Internal.pm
+++ b/rt/lib/RT/URI/freeside/Internal.pm
@@ -210,8 +210,8 @@ sub CustomerResolver {
 
 sub CustomerInfo {
   my $self = shift;
-  $self = $self->CustomerResolver;
   return $self->{CustomerInfo} if $self->{CustomerInfo};
+  $self = $self->CustomerResolver;
 
   my $rec = $self->_FreesideGetRecord() if $self;
   if (!$rec) {
@@ -261,23 +261,33 @@ sub CustomerInfo {
   $info->{"bill_location"} = $bill_location->location_label(no_prefix => 1);
   $info->{"ship_location"} = $ship_location->location_label(no_prefix => 1);
 
-
   return $self->{CustomerInfo} = $info;
 }
 
 sub ServiceInfo {
   my $self = shift;
   $self->{fstable} eq 'cust_svc' or return;
+  return $self->{ServiceInfo} if $self->{ServiceInfo};
+
   my $rec = $self->_FreesideGetRecord() or return;
   my $cust_svc = $rec->{'_object'};
   my $svc_x = $cust_svc->svc_x;
   my $part_svc = $cust_svc->part_svc;
-  return $self->{ServiceInfo} ||= {
+  my $locationnum = $cust_svc->cust_pkg->locationnum;
+  my $cust_location = qsearchs('cust_location', { locationnum => $locationnum});
+  my @lf = FS::cust_main->location_fields;
+
+  # location fields are not prefixed
+  my $info = {
     $cust_svc->hash,
     $svc_x->hash,
+    $cust_location->hash,
     ServiceType => $part_svc->svc,
     Label => $self->AsString,
-  }
+  };
+  $info->{'location'} = $cust_location->location_label(no_prefix => 1);
+
+  return $self->{ServiceInfo} = $info;
 }
 
 1;
diff --git a/rt/share/html/Elements/ServiceFields b/rt/share/html/Elements/ServiceFields
index 9c9a248..70eea23 100644
--- a/rt/share/html/Elements/ServiceFields
+++ b/rt/share/html/Elements/ServiceFields
@@ -43,6 +43,11 @@ my @service_fields = ( # ordered
     OrderBy => 'Service.svcpart',
   },
   {
+    Name    => 'ServiceLocation',
+    Label   => 'Service Location',
+    Display => svc_location_attribute('location'),
+  },
+  {
     Name    => 'ServiceKey', # loosely corresponds to smartsearch/label field
     Label   => '',
     # not displayable
@@ -118,6 +123,37 @@ sub svc_info_attribute {
     };
 }
 
+sub svc_location_attribute {
+    # Tricky: if the ticket is linked to a service, we want to return the
+    # service's location, but if it's not, we want to return the customer's
+    # default service location.
+    # If it's linked to Customer A and also to Service A, it should return
+    # Service A's location (and not Customer A's default service location).
+    # But if it's linked to Service A and also to Customer B, then what? We
+    # can't satisfy all the constraints here.
+    my $attribute = shift;
+    sub {
+        my @return;
+        my $Ticket = shift;
+        my @svc_resolvers = ticket_svc_resolvers($Ticket);
+        if (@svc_resolvers) {
+          warn '#' . $Ticket->id . ", service attribute $attribute\n";
+            foreach my $s (@svc_resolvers) {
+                push @return, $s->ServiceInfo->{$attribute}, '<BR>';
+            }
+        } else {
+          warn '#' . $Ticket->id . ", customer attribute ship_$attribute\n";
+            my @cust_resolvers = map $_->TargetURI->Resolver,
+                                 @{ $Ticket->Customers->ItemsArrayRef };
+            foreach my $c (@cust_resolvers) {
+                push @return, $c->CustomerInfo->{"ship_$attribute"}, '<BR>';
+            }
+        }
+        pop @return; #trailing <BR>
+        @return;
+    };
+}
+
 </%once>
 <%init>
 use Data::Dumper;

-----------------------------------------------------------------------

Summary of changes:
 rt/lib/RT/URI/freeside/Internal.pm   |   18 +++++++++++++----
 rt/share/html/Elements/ServiceFields |   36 ++++++++++++++++++++++++++++++++++
 2 files changed, 50 insertions(+), 4 deletions(-)




More information about the freeside-commits mailing list