use base qw( FS::TemplateItem_Mixin FS::Record );
use strict;
-use FS::Record qw( qsearchs dbh ); #qsearch
+use FS::Record qw( qsearchs qsearch dbh );
use FS::part_pkg;
use FS::quotation_pkg_discount; #so its loaded when TemplateItem_Mixin needs it
use List::Util qw(sum);
|| $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) {
+ # use the first non-disabled location for that prospect
+ my $cust_location = qsearchs('cust_location',
+ { prospectnum => $quotation->prospectnum,
+ disabled => '' });
+ $self->set('locationnum', $cust_location->locationnum) if $cust_location;
+ } # else the quotation is invalid
+ }
+
return $error if $error;
$self->SUPER::check;
$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