fix 'Can't call method "setup" on an undefined value' error when using into rates...
[freeside.git] / FS / FS / location_Mixin.pm
1 package FS::location_Mixin;
2
3 use strict;
4 use FS::Record qw( qsearchs );
5 use FS::cust_location;
6
7 =item cust_location
8
9 Returns the location object, if any (see L<FS::cust_location>).
10
11 =cut
12
13 sub cust_location {
14   my $self = shift;
15   return '' unless $self->locationnum;
16   qsearchs( 'cust_location', { 'locationnum' => $self->locationnum } );
17 }
18
19 =item cust_location_or_main
20
21 If this package is associated with a location, returns the locaiton (see
22 L<FS::cust_location>), otherwise returns the customer (see L<FS::cust_main>).
23
24 =cut
25
26 sub cust_location_or_main {
27   my $self = shift;
28   $self->cust_location || $self->cust_main;
29 }
30
31 =item location_label [ OPTION => VALUE ... ]
32
33 Returns the label of the location object (see L<FS::cust_location>).
34
35 =cut
36
37 sub location_label {
38   my $self = shift;
39   my $object = $self->cust_location_or_main;
40   $object->location_label(@_);
41 }
42
43 =item location_hash
44
45 Returns a hash of values for the location, either from the location object,
46 the cust_main shipping address, or the cust_main address, whichever is present
47 first.
48
49 =cut
50
51 sub location_hash {
52   my $self = shift;
53   my $object = $self->cust_location_or_main;
54   $object->location_hash(@_);
55 }
56
57 1;