From: Mark Wells Date: Tue, 10 Mar 2015 19:40:05 +0000 (-0700) Subject: set a default location for quotation_pkg records, #32340 X-Git-Url: http://git.freeside.biz/gitweb/?p=freeside.git;a=commitdiff_plain;h=a3c90ed7984e1c0ef73cb969183597545113221d set a default location for quotation_pkg records, #32340 --- diff --git a/FS/FS/Upgrade.pm b/FS/FS/Upgrade.pm index 6333a834e..d4ba7b828 100644 --- a/FS/FS/Upgrade.pm +++ b/FS/FS/Upgrade.pm @@ -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' => [], ; diff --git a/FS/FS/quotation_pkg.pm b/FS/FS/quotation_pkg.pm index 1c4766e79..dae459e29 100644 --- a/FS/FS/quotation_pkg.pm +++ b/FS/FS/quotation_pkg.pm @@ -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