5 use FS::UID qw(adminsuidsetup);
6 use FS::Record qw(qsearch dbh);
13 my $user = shift or die &usage;
14 adminsuidsetup($user);
15 $FS::UID::AutoCommit = 0;
18 my $engine = FS::TaxEngine->new;
19 my %hash = ( 'geocode' => '',
21 $hash{'disabled'} = '' unless $opt{d};
22 my @locations = qsearch('cust_location', \%hash);
23 foreach my $location (@locations) {
24 print $location->location_label . "...";
25 # only take the first one (the 'default')
26 my ($cust_tax_location) = $engine->cust_tax_locations($location);
27 if ($cust_tax_location) {
28 print $cust_tax_location->geocode;
29 $location->set('geocode', $cust_tax_location->geocode);
30 # geocode is not an immutable location field, so this is safe
31 my $error = $location->replace;
44 "Usage:\n\n freeside-tax-location-update [ -d ] user\n\n"
49 freeside-tax-location-update - Update service locations with tax data vendor
54 freeside-tax-location-update [ -d ] user
58 When using tax tables from an external vendor, there's a table of tax
59 jurisdiction codes that act as a foreign key to the tax rate definitions.
60 The jurisdiction is usually chosen based on the customer's postal code.
62 This script finds all non-disabled customer locations that don't have a
63 value in the 'geocode' field, finds the most likely matching geocode in the
64 cust_tax_location table, and stores that geocode in the cust_location record.
65 This is not guaranteed to be accurate. There may be multiple correct
66 geocodes for a given zip code; the script chooses the one that's marked
69 The -d option tells the script to work on disabled location records as well,
70 which is not likely to be necessary.
72 Updating the geocode this way is not a location change and does not trigger
73 a cancel/reorder of the customer's packages.