set a default location for quotation_pkg records, #32340
authorMark Wells <mark@freeside.biz>
Tue, 10 Mar 2015 19:40:05 +0000 (12:40 -0700)
committerMark Wells <mark@freeside.biz>
Tue, 10 Mar 2015 19:40:05 +0000 (12:40 -0700)
FS/FS/Upgrade.pm
FS/FS/quotation_pkg.pm

index 6333a83..d4ba7b8 100644 (file)
@@ -430,6 +430,9 @@ sub upgrade_data {
     #populate state FIPS codes if not already done
     'state' => [],
 
+    #set default locations on quoted packages
+    'quotation_pkg' => [],
+
     #populate tax statuses
     'tax_status' => [],
   ;
index 1c4766e..dae459e 100644 (file)
@@ -193,6 +193,16 @@ sub check {
     || $self->ut_enum('waive_setup', [ '', 'Y'] )
   ;
 
+  if ($self->locationnum eq '') {
+    # use the customer default
+    my $quotation = $self->quotation;
+    if ($quotation->custnum) {
+      $self->set('locationnum', $quotation->cust_main->ship_locationnum);
+    } elsif ($quotation->prospectnum) {
+      $self->set('locationnum', $quotation->prospect_main->locationnum);
+    } # else the quotation is invalid
+  }
+
   return $error if $error;
 
   $self->SUPER::check;
@@ -458,6 +468,24 @@ sub prospect_main {
   $quotation->prospect_main;
 }
 
+
+sub _upgrade_data {
+  my $class = shift;
+  my @quotation_pkg_without_location =
+    qsearch( 'quotation_pkg', { locationnum => '' } );
+  if (@quotation_pkg_without_location) {
+    warn "setting default location on quotation_pkg records\n";
+    foreach my $quotation_pkg (@quotation_pkg_without_location) {
+      # check() will fix this
+      my $error = $quotation_pkg->replace;
+      if ($error) {
+        die "quotation #".$quotation_pkg->quotationnum.": $error\n";
+      }
+    }
+  }
+  '';
+}
+
 =back
 
 =head1 BUGS