[freeside-commits] freeside/FS/FS did_order.pm,1.6,1.7
Erik Levinson
levinse at wavetail.420.am
Wed Jun 8 10:09:45 PDT 2011
Update of /home/cvs/cvsroot/freeside/FS/FS
In directory wavetail.420.am:/tmp/cvs-serv10765/FS/FS
Modified Files:
did_order.pm
Log Message:
DID inventory/import / bulk DID orders - phase 2, RT12754
Index: did_order.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/did_order.pm,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -w -d -r1.6 -r1.7
--- did_order.pm 8 Jun 2011 05:37:38 -0000 1.6
+++ did_order.pm 8 Jun 2011 17:09:43 -0000 1.7
@@ -124,6 +124,8 @@
}
$dbh->commit or die $dbh->errstr if $oldAutoCommit;
+
+ '';
}
=item merge SOURCE_ORDER
@@ -133,11 +135,11 @@
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.
+DID order items are transferred into this order. Per-order customer is cleared
+if any order items are assigned to a customer.
The source order is deleted.
@@ -158,24 +160,56 @@
return "DID vendors do not match"
if $src->vendornum != $self->vendornum;
- my @move_if_unset = qw( vendor_order_id submitted confirmed custnum );
+ 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;
+
+ my @move_if_unset = qw( vendor_order_id 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 ) {
+ my $item_has_cust = 0;
+ my @did_order_item = $src->did_order_item;
+ foreach my $did_order_item ( @did_order_item ) {
$did_order_item->ordernum($self->ordernum);
+ $item_has_cust = 1 if $did_order_item->custnum;
$error = $did_order_item->replace;
- return $error if $error;
+ if ( $error ) {
+ $dbh->rollback if $oldAutoCommit;
+ return "can't replace did order item "
+ . $did_order_item->orderitemnum . ": $error";
+ }
}
+ @did_order_item = $self->did_order_item;
+ foreach my $did_order_item ( @did_order_item ) {
+ $item_has_cust = 1 if $did_order_item->custnum;
+ }
+
+ $self->custnum('') if $item_has_cust;
+
$error = $src->delete;
- return $error if !$error;
+ if ( $error ) {
+ $dbh->rollback if $oldAutoCommit;
+ return "can't delete source order: $error";
+ }
$error = $self->replace;
- return $error if !$error;
+ if ( $error ) {
+ $dbh->rollback if $oldAutoCommit;
+ return "can't replace target order: $error";
+ }
+
+ $dbh->commit or die $dbh->errstr if $oldAutoCommit;
'';
}
More information about the freeside-commits
mailing list