X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=FS%2FFS%2Fcust_refund.pm;h=ced9540363b39dc5fe537c6184a9be0c9ca01d53;hb=3cbdd85a96348a287623e3b97c937c7749e99392;hp=efbdceeb0bedb3cd34da21546874faea17fd8fc9;hpb=acfdb8bec93849e35ae5c4abc276d6ca8006f717;p=freeside.git diff --git a/FS/FS/cust_refund.pm b/FS/FS/cust_refund.pm index efbdceeb0..ced954036 100644 --- a/FS/FS/cust_refund.pm +++ b/FS/FS/cust_refund.pm @@ -143,16 +143,23 @@ sub insert { local $FS::UID::AutoCommit = 0; my $dbh = dbh; - unless ($self->reasonnum) { - my $result = $self->reason( $self->getfield('reason'), - exists($options{ 'reason_type' }) - ? ('reason_type' => $options{ 'reason_type' }) - : (), - ); - unless($result) { + if (!$self->reasonnum) { + my $reason_text = $self->get('reason') + or return "reason text or existing reason required"; + my $reason_type = $options{'reason_type'} + or return "reason type required"; + + local $@; + my $reason = FS::reason->new_or_existing( + reason => $reason_text, + type => $reason_type, + class => 'F', + ); + if ($@) { $dbh->rollback if $oldAutoCommit; - return "failed to set reason for $me"; #: ". $dbh->errstr; + return "failed to set refund reason: $@"; } + $self->set('reasonnum', $reason->reasonnum); } $self->setfield('reason', ''); @@ -303,6 +310,7 @@ sub check { || $self->ut_numbern('_date') || $self->ut_textn('paybatch') || $self->ut_enum('closed', [ '', 'Y' ]) + || $self->ut_foreign_keyn('source_paynum', 'cust_pay', 'paynum') ; return $error if $error;