[freeside-commits] branch FREESIDE_3_BRANCH updated. a541a59a156998b7d0c310fc74f7e528431a6716

Jonathan Prykop jonathan at 420.am
Mon Apr 25 14:49:13 PDT 2016


The branch, FREESIDE_3_BRANCH has been updated
       via  a541a59a156998b7d0c310fc74f7e528431a6716 (commit)
       via  ef9b6c8513a4af438139f4992b42b9285f64ab1d (commit)
       via  5422bc1098d49e736caa9c61b3eb941060920d5e (commit)
       via  9ceca59afe85c259399f77df6f07003f6966b9b9 (commit)
      from  f3e8bf05d7781fcaf22ea28d92be236e3f794034 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit a541a59a156998b7d0c310fc74f7e528431a6716
Merge: ef9b6c8 f3e8bf0
Author: Jonathan Prykop <jonathan at freeside.biz>
Date:   Mon Apr 25 16:48:58 2016 -0500

    Merge branch 'FREESIDE_3_BRANCH' of git.freeside.biz:/home/git/freeside into FREESIDE_3_BRANCH


commit ef9b6c8513a4af438139f4992b42b9285f64ab1d
Author: Jonathan Prykop <jonathan at freeside.biz>
Date:   Mon Apr 25 16:41:38 2016 -0500

    RT#41866: Punctuation prevented package from billing [disallow negative]

diff --git a/FS/FS/part_pkg/global_Mixin.pm b/FS/FS/part_pkg/global_Mixin.pm
index 31d178d..0281a51 100644
--- a/FS/FS/part_pkg/global_Mixin.pm
+++ b/FS/FS/part_pkg/global_Mixin.pm
@@ -19,10 +19,10 @@ sub validate_moneyn {
   my ($option, $valref) = @_;
   if ( $$valref eq '' ) {
     return '';
-  } elsif ( $$valref =~ /^\s*(\-)?\s*(\d*)(\.\d{1})\s*$/ ) {
+  } elsif ( $$valref =~ /^\s*(\d*)(\.\d{1})\s*$/ ) {
     #handle one decimal place without barfing out
     $$valref = ( ($1||''). ($2||''). ($3.'0') ) || 0;
-  } elsif ( $$valref =~ /^\s*(\-)?\s*(\d*)(\.\d{2})?\s*$/ ) {
+  } elsif ( $$valref =~ /^\s*(\d*)(\.\d{2})?\s*$/ ) {
     $$valref = ( ($1||''). ($2||''). ($3||'') ) || 0;
   } else {
     return "Illegal (money) $option: ". $$valref;

commit 5422bc1098d49e736caa9c61b3eb941060920d5e
Merge: 9ceca59 055f426
Author: Jonathan Prykop <jonathan at freeside.biz>
Date:   Mon Apr 25 16:45:43 2016 -0500

    Merge branch 'FREESIDE_3_BRANCH' of git.freeside.biz:/home/git/freeside into FREESIDE_3_BRANCH


commit 9ceca59afe85c259399f77df6f07003f6966b9b9
Author: Jonathan Prykop <jonathan at freeside.biz>
Date:   Mon Apr 25 16:18:10 2016 -0500

    RT#41866: Punctuation prevented package from billing [v3 reconcile]

diff --git a/FS/FS/part_pkg.pm b/FS/FS/part_pkg.pm
index 238c64c..915634b 100644
--- a/FS/FS/part_pkg.pm
+++ b/FS/FS/part_pkg.pm
@@ -669,6 +669,32 @@ sub check {
   '';
 }
 
+=item check_options
+
+For a passed I<$options> hashref, validates any options that
+have 'validate' subroutines defined (I<$options> values might
+be altered.)  Returns error message, or empty string if valid.
+
+Invoked by L</insert> and L</replace> via the equivalent
+methods in L<FS::option_Common>.
+
+=cut
+
+sub check_options {
+  my ($self,$options) = @_;
+  foreach my $option (keys %$options) {
+    if (exists $plans{ $self->plan }->{fields}->{$option}) {
+      if (exists($plans{$self->plan}->{fields}->{$option}->{'validate'})) {
+        # pass option name for use in error message
+        # pass a reference to the $options value, so it can be cleaned up
+        my $error = &{$plans{$self->plan}->{fields}->{$option}->{'validate'}}($option,\($options->{$option}));
+        return $error if $error;
+      }
+    } # else "option does not exist" error?
+  }
+  return '';
+}
+
 =item supersede OLD [, OPTION => VALUE ... ]
 
 Inserts this package as a successor to the package OLD.  All options are as
diff --git a/FS/FS/part_pkg/global_Mixin.pm b/FS/FS/part_pkg/global_Mixin.pm
index 9faddf0..31d178d 100644
--- a/FS/FS/part_pkg/global_Mixin.pm
+++ b/FS/FS/part_pkg/global_Mixin.pm
@@ -14,16 +14,35 @@ tie my %a2billing_simultaccess, 'Tie::IxHash', (
   1 => 'Enabled',
 );
 
+# much false laziness with FS::Record::ut_money
+sub validate_moneyn {
+  my ($option, $valref) = @_;
+  if ( $$valref eq '' ) {
+    return '';
+  } elsif ( $$valref =~ /^\s*(\-)?\s*(\d*)(\.\d{1})\s*$/ ) {
+    #handle one decimal place without barfing out
+    $$valref = ( ($1||''). ($2||''). ($3.'0') ) || 0;
+  } elsif ( $$valref =~ /^\s*(\-)?\s*(\d*)(\.\d{2})?\s*$/ ) {
+    $$valref = ( ($1||''). ($2||''). ($3||'') ) || 0;
+  } else {
+    return "Illegal (money) $option: ". $$valref;
+  }
+  return '';
+}
+
+
 %info = (
   'disabled' => 1,
   'fields' => {
     'setup_fee' => { 
       'name' => 'Setup fee for this package',
       'default' => 0,
+      'validate' => \&validate_moneyn,
     },
     'recur_fee' => { 
       'name' => 'Recurring fee for this package',
       'default' => 0,
+      'validate' => \&validate_moneyn,
     },
     'unused_credit_cancel' => {
       'name' => 'Credit the customer for the unused portion of service at '.

-----------------------------------------------------------------------

Summary of changes:
 FS/FS/part_pkg.pm              |   26 ++++++++++++++++++++++++++
 FS/FS/part_pkg/global_Mixin.pm |   19 +++++++++++++++++++
 2 files changed, 45 insertions(+)




More information about the freeside-commits mailing list