[freeside-commits] branch FREESIDE_3_BRANCH updated. c6df7ad114570d49e51ef1f806b83bb7e1a1bca8

Mark Wells mark at 420.am
Thu Feb 5 16:23:23 PST 2015


The branch, FREESIDE_3_BRANCH has been updated
       via  c6df7ad114570d49e51ef1f806b83bb7e1a1bca8 (commit)
      from  4792471dbc3eb9e05f03bbff17b100ea89486d07 (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 c6df7ad114570d49e51ef1f806b83bb7e1a1bca8
Author: Mark Wells <mark at freeside.biz>
Date:   Thu Feb 5 16:23:10 2015 -0800

    fix creation of custom discounts on quotations, and ordering of discounted quoted packages, #33099

diff --git a/FS/FS/cust_pkg_discount.pm b/FS/FS/cust_pkg_discount.pm
index d82d949..5a4cee4 100644
--- a/FS/FS/cust_pkg_discount.pm
+++ b/FS/FS/cust_pkg_discount.pm
@@ -1,7 +1,10 @@
 package FS::cust_pkg_discount;
 
 use strict;
-use base qw( FS::otaker_Mixin FS::cust_main_Mixin FS::Record );
+use base qw( FS::otaker_Mixin
+             FS::cust_main_Mixin
+             FS::pkg_discount_Mixin
+             FS::Record );
 use FS::Record qw( dbh qsearchs ); # qsearch );
 use FS::cust_pkg;
 use FS::discount;
@@ -83,52 +86,6 @@ sub table { 'cust_pkg_discount'; }
 Adds this record to the database.  If there is an error, returns the error,
 otherwise returns false.
 
-=cut
-
-sub insert {
-  #my( $self, %options ) = @_;
-  my $self = shift;
-
-  local $SIG{HUP} = 'IGNORE';
-  local $SIG{INT} = 'IGNORE';
-  local $SIG{QUIT} = 'IGNORE';
-  local $SIG{TERM} = 'IGNORE';
-  local $SIG{TSTP} = 'IGNORE';
-  local $SIG{PIPE} = 'IGNORE';
-
-  my $oldAutoCommit = $FS::UID::AutoCommit;
-  local $FS::UID::AutoCommit = 0;
-  my $dbh = dbh;
-
-  if ( $self->discountnum == -1 ) {
-    my $discount = new FS::discount {
-      '_type'    => $self->_type,
-      'amount'   => $self->amount,
-      'percent'  => $self->percent,
-      'months'   => $self->months,
-      'setup'    => $self->setup,
-      #'linked'   => $self->linked,
-      'disabled' => 'Y',
-    };
-    my $error = $discount->insert;
-    if ( $error ) {
-      $dbh->rollback if $oldAutoCommit;
-      return $error;
-    }
-    $self->discountnum($discount->discountnum);
-  }
-
-  my $error = $self->SUPER::insert; #(@_); #(%options);
-  if ( $error ) {
-    $dbh->rollback if $oldAutoCommit;
-    return $error;
-  }
-
-  $dbh->commit or die $dbh->errstr if $oldAutoCommit;
-  '';
-
-}
-
 =item delete
 
 Delete this record from the database.
diff --git a/FS/FS/pkg_discount_Mixin.pm b/FS/FS/pkg_discount_Mixin.pm
new file mode 100644
index 0000000..c6fe008
--- /dev/null
+++ b/FS/FS/pkg_discount_Mixin.pm
@@ -0,0 +1,69 @@
+package FS::pkg_discount_Mixin;
+
+use strict;
+use NEXT;
+use FS::Record qw(dbh);
+
+=head1 NAME
+
+FS::pkg_discount_Mixin - mixin class for package-discount link objects.
+
+=head1 DESCRIPTION
+
+Implements some behavior that's common to cust_pkg_discount and 
+quotation_pkg_discount objects. The only required field is "discountnum",
+a foreign key to L<FS::discount>.
+
+=head1 METHODS
+
+=over 4
+
+=item insert
+
+Inserts the record. If the 'discountnum' field is -1, this will first create
+a discount using the contents of the '_type', 'amount', 'percent', 'months',
+and 'setup' field. The new discount will be disabled, since it's a one-off
+discount.
+
+=cut
+
+sub insert {
+  my $self = shift;
+  my $oldAutoCommit = $FS::UID::AutoCommit;
+  local $FS::UID::AutoCommit = 0;
+  my $dbh = dbh;
+  
+  if ( $self->discountnum == -1 ) {
+    my $discount = new FS::discount {
+      '_type'    => $self->_type,
+      'amount'   => $self->amount,
+      'percent'  => $self->percent,
+      'months'   => $self->months,
+      'setup'    => $self->setup,
+      #'linked'   => $self->linked,
+      'disabled' => 'Y',
+    };
+    my $error = $discount->insert;
+    if ( $error ) {
+      $dbh->rollback if $oldAutoCommit;
+      return $error; 
+    } 
+    $self->set('discountnum', $discount->discountnum);
+  }
+
+  my $error = $self->NEXT::insert;
+  if ( $error ) {
+    $dbh->rollback if $oldAutoCommit;
+    return $error;
+  }
+
+  $dbh->commit or die $dbh->errstr if $oldAutoCommit;
+  '';
+  
+} 
+
+=back
+
+=cut
+
+1;
diff --git a/FS/FS/quotation.pm b/FS/FS/quotation.pm
index 1c9d2c4..0350047 100644
--- a/FS/FS/quotation.pm
+++ b/FS/FS/quotation.pm
@@ -356,15 +356,23 @@ If there is an error, returns an error message, otherwise returns false.
 sub order {
   my $self = shift;
 
-  tie my %cust_pkg, 'Tie::RefHash',
-    map { FS::cust_pkg->new({ pkgpart  => $_->pkgpart,
-                              quantity => $_->quantity,
-                           })
-            => [] #services
-        }
-      $self->quotation_pkg ;
-
-  $self->cust_main->order_pkgs( \%cust_pkg );
+  tie my %all_cust_pkg, 'Tie::RefHash';
+  foreach my $quotation_pkg ($self->quotation_pkg) {
+    my $cust_pkg = FS::cust_pkg->new;
+    foreach (qw(pkgpart locationnum start_date contract_end quantity waive_setup)) {
+      $cust_pkg->set( $_, $quotation_pkg->get($_) );
+    }
+
+    # currently only one discount each
+    my ($pkg_discount) = $quotation_pkg->quotation_pkg_discount;
+    if ( $pkg_discount ) {
+      $cust_pkg->set('discountnum', $pkg_discount->discountnum);
+    }
+
+    $all_cust_pkg{$cust_pkg} = []; # no services
+  }
+
+  $self->cust_main->order_pkgs( \%all_cust_pkg );
 
 }
 
diff --git a/FS/FS/quotation_pkg.pm b/FS/FS/quotation_pkg.pm
index 914e1ce..88147bc 100644
--- a/FS/FS/quotation_pkg.pm
+++ b/FS/FS/quotation_pkg.pm
@@ -105,8 +105,11 @@ otherwise returns false.
 
 =cut
 
+use Data::Dumper; #XXX DEBUG
 sub insert {
   my ($self, %options) = @_;
+  warn Dumper($self);
+  warn Dumper(\%options);
 
   my $dbh = dbh;
   my $oldAutoCommit = $FS::UID::AutoCommit;
@@ -251,6 +254,9 @@ sub estimate {
 
   # XXX the order of applying discounts is ill-defined, which matters
   # if there are percentage and amount discounts on the same package.
+  #
+  # but right now there can only be one discount on any package, so 
+  # it doesn't matter
   foreach my $pkg_discount ($self->quotation_pkg_discount) {
 
     my $discount = $pkg_discount->discount;
diff --git a/FS/FS/quotation_pkg_discount.pm b/FS/FS/quotation_pkg_discount.pm
index 24cb204..19a7bce 100644
--- a/FS/FS/quotation_pkg_discount.pm
+++ b/FS/FS/quotation_pkg_discount.pm
@@ -1,7 +1,7 @@
 package FS::quotation_pkg_discount;
 
 use strict;
-use base qw( FS::Record );
+use base qw( FS::pkg_discount_Mixin FS::Record );
 use FS::Record qw( qsearch qsearchs );
 use FS::quotation_pkg;
 use FS::discount;
@@ -81,27 +81,15 @@ sub table { 'quotation_pkg_discount'; }
 Adds this record to the database.  If there is an error, returns the error,
 otherwise returns false.
 
-=cut
-
-# the insert method can be inherited from FS::Record
-
 =item delete
 
 Delete this record from the database.
 
-=cut
-
-# the delete method can be inherited from FS::Record
-
 =item replace OLD_RECORD
 
 Replaces the OLD_RECORD with this one in the database.  If there is an error,
 returns the error, otherwise returns false.
 
-=cut
-
-# the replace method can be inherited from FS::Record
-
 =item check
 
 Checks all fields to make sure this is a valid quotation package discount.
diff --git a/FS/MANIFEST b/FS/MANIFEST
index 75c755a..78d5b7e 100644
--- a/FS/MANIFEST
+++ b/FS/MANIFEST
@@ -785,3 +785,5 @@ FS/circuit_termination.pm
 t/circuit_termination.t
 FS/svc_circuit.pm
 t/svc_circuit.t
+FS/pkg_discount_Mixin.pm
+t/pkg_discount_Mixin.t
diff --git a/FS/t/pkg_discount_Mixin.t b/FS/t/pkg_discount_Mixin.t
new file mode 100644
index 0000000..d811a92
--- /dev/null
+++ b/FS/t/pkg_discount_Mixin.t
@@ -0,0 +1,5 @@
+BEGIN { $| = 1; print "1..1\n" }
+END {print "not ok 1\n" unless $loaded;}
+use FS::pkg_discount_Mixin;
+$loaded=1;
+print "ok 1\n";

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

Summary of changes:
 FS/FS/cust_pkg_discount.pm                   |   51 ++-----------------
 FS/FS/pkg_discount_Mixin.pm                  |   69 ++++++++++++++++++++++++++
 FS/FS/quotation.pm                           |   26 ++++++----
 FS/FS/quotation_pkg.pm                       |    6 +++
 FS/FS/quotation_pkg_discount.pm              |   14 +-----
 FS/MANIFEST                                  |    2 +
 FS/t/{AccessRight.t => pkg_discount_Mixin.t} |    2 +-
 7 files changed, 100 insertions(+), 70 deletions(-)
 create mode 100644 FS/FS/pkg_discount_Mixin.pm
 copy FS/t/{AccessRight.t => pkg_discount_Mixin.t} (78%)




More information about the freeside-commits mailing list