1 package FS::cust_pkg::API;
5 use FS::cust_location::API;
10 +{ ( map { $_=>$self->$_ } $self->fields ),
15 # currently only handles location change...
16 # eventually have it handle all sorts of package changes
21 return { 'error' => 'Cannot change canceled package' }
22 if $self->get('cancel');
26 # update location--accepts raw fields OR location
28 foreach my $field (FS::cust_location::API::API_editable_fields()) {
29 $location_hash{$field} = $opt{$field} if $opt{$field};
31 return { 'error' => 'Cannot pass both locationnum and location fields' }
32 if $opt{'locationnum'} && %location_hash;
35 my $cust_location = FS::cust_location->new({
36 'custnum' => $self->custnum,
39 $changeopt{'cust_location'} = $cust_location;
40 } elsif ($opt{'locationnum'}) {
41 $changeopt{'locationnum'} = $opt{'locationnum'};
44 # not quite "nothing changed" because passed changes might be identical to current record,
45 # we don't currently check for that, don't want to imply that we do...but maybe we should?
46 return { 'error' => 'No changes passed to method' }
47 unless $changeopt{'cust_location'} || $changeopt{'locationnum'};
49 $changeopt{'keep_dates'} = 1;
51 my $pkg_or_error = $self->change( \%changeopt );
52 my $error = ref($pkg_or_error) ? '' : $pkg_or_error;
54 return { 'error' => $error } if $error;
56 # return all fields? we don't yet expose them through FS::API
57 return { map { $_ => $pkg_or_error->get($_) } qw( pkgnum locationnum ) };