[freeside-commits] freeside/FS/FS Mason.pm, 1.59, 1.60 Schema.pm, 1.251, 1.252 part_pkg.pm, 1.112, 1.113 part_pkg_vendor.pm, NONE, 1.1 qual.pm, 1.6, 1.7

Erik Levinson levinse at wavetail.420.am
Wed Dec 8 13:37:47 PST 2010


Update of /home/cvs/cvsroot/freeside/FS/FS
In directory wavetail.420.am:/tmp/cvs-serv9662/FS/FS

Modified Files:
	Mason.pm Schema.pm part_pkg.pm qual.pm 
Added Files:
	part_pkg_vendor.pm 
Log Message:
-rename qual export sub to part_export, RT7111
-initial commit of part_pkg_vendor implementation, RT7111



Index: Schema.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/Schema.pm,v
retrieving revision 1.251
retrieving revision 1.252
diff -u -w -d -r1.251 -r1.252
--- Schema.pm	3 Dec 2010 23:38:27 -0000	1.251
+++ Schema.pm	8 Dec 2010 21:37:44 -0000	1.252
@@ -2323,6 +2323,18 @@
       'index'       => [ [ 'pkgpart' ], [ 'optionname' ] ],
     },
 
+    'part_pkg_vendor' => {
+      'columns' => [
+        'num', 'serial', '', '', '', '', 
+        'pkgpart', 'int', '', '', '', '', 
+        'exportnum', 'int', '', '', '', '', 
+        'vendor_pkg_id', 'varchar', '', $char_d, '', '', 
+      ],
+      'primary_key' => 'num',
+      'unique' => [ [ 'pkgpart', 'exportnum' ] ],
+      'index'       => [ [ 'pkgpart' ] ],
+    },
+    
     'part_pkg_report_option' => {
       'columns' => [
         'num',      'serial',   '',      '', '', '', 

Index: qual.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/qual.pm,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -w -d -r1.6 -r1.7
--- qual.pm	7 Dec 2010 19:04:42 -0000	1.6
+++ qual.pm	8 Dec 2010 21:37:45 -0000	1.7
@@ -127,7 +127,7 @@
   $self->SUPER::check;
 }
 
-sub export {
+sub part_export {
     my $self = shift;
     if ( $self->exportnum ) {
 	return qsearchs('part_export', { exportnum => $self->exportnum } )

Index: part_pkg.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/part_pkg.pm,v
retrieving revision 1.112
retrieving revision 1.113
diff -u -w -d -r1.112 -r1.113
--- part_pkg.pm	13 Nov 2010 23:23:47 -0000	1.112
+++ part_pkg.pm	8 Dec 2010 21:37:44 -0000	1.113
@@ -275,6 +275,23 @@
     }
   }
 
+  if ( $options{'part_pkg_vendor'} ) {
+      my($exportnum,$vendor_pkg_id);
+      my %options_part_pkg_vendor = $options{'part_pkg_vendor'};
+      while(($exportnum,$vendor_pkg_id) = each %options_part_pkg_vendor){
+	    my $ppv = new FS::part_pkg_vendor( {
+		    'pkgpart' => $self->pkgpart,
+		    'exportnum' => $exportnum,
+		    'vendor_pkg_id' => $vendor_pkg_id, 
+		} );
+	    my $error = $ppv->insert;
+	    if ( $error ) {
+	      $dbh->rollback if $oldAutoCommit;
+	      return "Error inserting part_pkg_vendor record: $error";
+	    }
+      }
+  }
+
   warn "  commiting transaction" if $DEBUG;
   $dbh->commit or die $dbh->errstr if $oldAutoCommit;
 
@@ -433,6 +450,51 @@
     }
   }
 
+  my @part_pkg_vendor = $old->part_pkg_vendor;
+  my @current_exportnum = ();
+  if ( $options->{'part_pkg_vendor'} ) {
+      my($exportnum,$vendor_pkg_id);
+      while ( ($exportnum,$vendor_pkg_id) 
+				= each %{$options->{'part_pkg_vendor'}} ) {
+	  my $replaced = 0;
+	  foreach my $part_pkg_vendor ( @part_pkg_vendor ) {
+	    if($exportnum == $part_pkg_vendor->exportnum
+		&& $vendor_pkg_id ne $part_pkg_vendor->vendor_pkg_id) {
+		$part_pkg_vendor->vendor_pkg_id($vendor_pkg_id);
+		my $error = $part_pkg_vendor->replace;
+		if ( $error ) {
+		  $dbh->rollback if $oldAutoCommit;
+		  return "Error replacing part_pkg_vendor record: $error";
+		}
+		$replaced = 1;
+		last;
+	    }
+	  }
+	  unless ( $replaced ) {
+	    my $ppv = new FS::part_pkg_vendor( {
+		    'pkgpart' => $new->pkgpart,
+		    'exportnum' => $exportnum,
+		    'vendor_pkg_id' => $vendor_pkg_id, 
+		} );
+	    my $error = $ppv->insert;
+	    if ( $error ) {
+	      $dbh->rollback if $oldAutoCommit;
+	      return "Error inserting part_pkg_vendor record: $error";
+	    }
+	  }
+	  push @current_exportnum, $exportnum;
+      }
+  }
+  foreach my $part_pkg_vendor ( @part_pkg_vendor ) {
+      unless ( grep($_ eq $part_pkg_vendor->exportnum, @current_exportnum) ) {
+	my $error = $part_pkg_vendor->delete;
+	if ( $error ) {
+	  $dbh->rollback if $oldAutoCommit;
+	  return "Error deleting part_pkg_vendor record: $error";
+	}
+      }
+  }
+
   warn "  commiting transaction" if $DEBUG;
   $dbh->commit or die $dbh->errstr if $oldAutoCommit;
   '';
@@ -885,6 +947,29 @@
   }
 }
 
+=item part_pkg_vendor
+
+Returns all vendor/external package ids as FS::part_pkg_vendor objects (see
+L<FS::part_pkg_vendor>).
+
+=cut
+
+sub part_pkg_vendor {
+  my $self = shift;
+  qsearch('part_pkg_vendor', { 'pkgpart' => $self->pkgpart } );
+}
+
+=item vendor_pkg_ids
+
+Returns a list of vendor/external package ids by exportnum
+
+=cut
+
+sub vendor_pkg_ids {
+  my $self = shift;
+  map { $_->exportnum => $_->vendor_pkg_id } $self->part_pkg_vendor;
+}
+
 =item part_pkg_option
 
 Returns all options as FS::part_pkg_option objects (see

Index: Mason.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/Mason.pm,v
retrieving revision 1.59
retrieving revision 1.60
diff -u -w -d -r1.59 -r1.60
--- Mason.pm	29 Nov 2010 02:30:38 -0000	1.59
+++ Mason.pm	8 Dec 2010 21:37:44 -0000	1.60
@@ -262,6 +262,7 @@
   use FS::qual;
   use FS::qual_option;
   use FS::dsl_note;
+  use FS::part_pkg_vendor;
   # Sammath Naur
 
   if ( $FS::Mason::addl_handler_use ) {

--- NEW FILE: part_pkg_vendor.pm ---
package FS::part_pkg_vendor;

use strict;
use base qw( FS::Record );
use FS::Record qw( qsearch qsearchs );

=head1 NAME

FS::part_pkg_vendor - Object methods for part_pkg_vendor records

=head1 SYNOPSIS

  use FS::part_pkg_vendor;

  $record = new FS::part_pkg_vendor \%hash;
  $record = new FS::part_pkg_vendor { 'column' => 'value' };

  $error = $record->insert;

  $error = $new_record->replace($old_record);

  $error = $record->delete;

  $error = $record->check;

=head1 DESCRIPTION

An FS::part_pkg_vendor object represents a mapping of pkgpart numbers to
external package numbers.  FS::part_pkg_vendor inherits from FS::Record. 
The following fields are currently supported:

=over 4

=item num

primary key

=item pkgpart

pkgpart

=item exportnum

exportnum

=item vendor_pkg_id

vendor_pkg_id


=back

=head1 METHODS

=over 4

=item new HASHREF

Creates a new example.  To add the example to the database, see L<"insert">.

Note that this stores the hash reference, not a distinct copy of the hash it
points to.  You can ask the object for a copy with the I<hash> method.

=cut

# the new method can be inherited from FS::Record, if a table method is defined

sub table { 'part_pkg_vendor'; }

=item insert

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 example.  If there is
an error, returns the error, otherwise returns false.  Called by the insert
and replace methods.

=cut

# the check method should currently be supplied - FS::Record contains some
# data checking routines

sub check {
  my $self = shift;

  my $error = 
    $self->ut_numbern('num')
    || $self->ut_foreign_key('pkgpart', 'part_pkg', 'pkgpart')
    || $self->ut_foreign_key('exportnum', 'part_export', 'exportnum')
    || $self->ut_textn('vendor_pkg_id')
  ;
  return $error if $error;

  $self->SUPER::check;
}

=item part_export

Returns the L<FS::part_export> associated with this vendor/external package id.

=cut
sub part_export {
    my $self = shift;
    qsearchs( 'part_export', { 'exportnum' => $self->exportnum } );
}

=back

=head1 SEE ALSO

L<FS::part_pkg>, L<FS::Record>, schema.html from the base documentation.

=cut

1;




More information about the freeside-commits mailing list