summaryrefslogtreecommitdiff
path: root/FS/FS/cust_refund.pm
diff options
context:
space:
mode:
Diffstat (limited to 'FS/FS/cust_refund.pm')
-rw-r--r--FS/FS/cust_refund.pm24
1 files changed, 16 insertions, 8 deletions
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;