[freeside-commits] freeside/FS/FS phone_avail.pm, 1.14, 1.15 did_order_item.pm, 1.2, 1.3 did_order.pm, 1.5, 1.6 Schema.pm, 1.302, 1.303
Erik Levinson
levinse at wavetail.420.am
Tue Jun 7 22:37:40 PDT 2011
Update of /home/cvs/cvsroot/freeside/FS/FS
In directory wavetail.420.am:/tmp/cvs-serv9780/FS/FS
Modified Files:
phone_avail.pm did_order_item.pm did_order.pm Schema.pm
Log Message:
DID inventory/import / bulk DID orders - phase 2, RT12754
Index: Schema.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/Schema.pm,v
retrieving revision 1.302
retrieving revision 1.303
diff -u -w -d -r1.302 -r1.303
--- Schema.pm 6 Jun 2011 23:44:26 -0000 1.302
+++ Schema.pm 8 Jun 2011 05:37:38 -0000 1.303
@@ -3184,6 +3184,7 @@
'ratecenternum', 'int', 'NULL', '', '', '',
'state', 'char', 'NULL', 2, '', '',
'quantity', 'int', '', '', '', '',
+ 'custnum', 'int', 'NULL', '', '', '',
],
'primary_key' => 'orderitemnum',
'unique' => [],
Index: did_order_item.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/did_order_item.pm,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -w -d -r1.2 -r1.3
--- did_order_item.pm 15 Apr 2011 03:04:12 -0000 1.2
+++ did_order_item.pm 8 Jun 2011 05:37:38 -0000 1.3
@@ -49,6 +49,8 @@
=item quantity
+=item custnum - foreign key to cust_main table, optional
+
=back
=head1 METHODS
@@ -117,6 +119,7 @@
|| $self->ut_foreign_keyn('ratecenternum', 'rate_center', 'ratecenternum')
|| $self->ut_textn('state')
|| $self->ut_number('quantity')
+ || $self->ut_foreign_keyn('custnum', 'cust_main', 'custnum')
;
return $error if $error;
@@ -127,7 +130,7 @@
=head1 SEE ALSO
-L<FS::Record>, schema.html from the base documentation.
+L<FS::did_order>, <FS::Record>, schema.html from the base documentation.
=cut
Index: did_order.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/did_order.pm,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -w -d -r1.5 -r1.6
--- did_order.pm 17 Apr 2011 03:27:41 -0000 1.5
+++ did_order.pm 8 Jun 2011 05:37:38 -0000 1.6
@@ -126,6 +126,59 @@
$dbh->commit or die $dbh->errstr if $oldAutoCommit;
}
+=item merge SOURCE_ORDER
+
+Merges the DID order given by SOURCE_ORDER into THIS order.
+
+The following fields from the source order are transferred, only if they aren't
+set in this order:
+-vendor order #
+-submitted
+-confirmed
+-customer
+
+DID order items are transferred into this order.
+
+The source order is deleted.
+
+The operation fails if:
+-either order has a received time; or
+-the DID vendors do not match between the orders
+
+=cut
+
+sub merge {
+ my $self = shift;
+ my $src = shift;
+ return "invalid source order" unless $src;
+
+ return "DIDs received for either order"
+ if $src->received || $self->received;
+
+ return "DID vendors do not match"
+ if $src->vendornum != $self->vendornum;
+
+ my @move_if_unset = qw( vendor_order_id submitted confirmed custnum );
+ foreach my $f ( @move_if_unset ) {
+ $self->$f($src->$f) if !$self->$f;
+ }
+
+ my $error = '';
+ my @did_order_items = qsearch('did_order_item', { 'ordernum' => $src->ordernum });
+ foreach my $did_order_item ( @did_order_items ) {
+ $did_order_item->ordernum($self->ordernum);
+ $error = $did_order_item->replace;
+ return $error if $error;
+ }
+
+ $error = $src->delete;
+ return $error if !$error;
+
+ $error = $self->replace;
+ return $error if !$error;
+
+ '';
+}
=item replace OLD_RECORD
@@ -176,16 +229,48 @@
=item cust_main
-Returns the cust_main (see L<FS::cust_main>), if any, associated with this bulk DID order.
+Returns all cust_main (see L<FS::cust_main>), if any, associated with this
+bulk DID order.
=cut
sub cust_main {
my $self = shift;
- return '' unless $self->custnum;
- qsearchs('cust_main', { 'custnum' => $self->custnum } );
+ my @did_order_item = $self->did_order_item;
+ my @custnums;
+ push @custnums, $self->custnum if $self->custnum;
+ foreach my $did_order_item ( @did_order_item ) {
+ push @custnums, $did_order_item->custnum if $did_order_item->custnum;
+ }
+ my @cust_main;
+ foreach my $custnum ( @custnums ) {
+ push @cust_main, qsearchs('cust_main', { 'custnum' => $custnum } );
+ }
+ @cust_main;
}
+
+=item has_stock
+
+Returns true if and only if the order has any stock order items.
+
+=cut
+
+sub has_stock {
+ my $self = shift;
+ my $items_with_custnum = 0;
+ my @did_order_item = $self->did_order_item;
+ foreach my $did_order_item ( @did_order_item ) {
+ $items_with_custnum++ if $did_order_item->custnum;
+ }
+
+ return 0 if ($items_with_custnum == scalar(@did_order_item)
+ && $items_with_custnum != 0 && !$self->custnum)
+ || $self->custnum;
+ 1;
+}
+
+
=item provisioned
Returns the provisioned DIDs, if any, as phone_avail (see L<FS::phone_avail>) objects.
Index: phone_avail.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/phone_avail.pm,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -w -d -r1.14 -r1.15
More information about the freeside-commits
mailing list