- my $reason = qsearchs('reason', { reason => $cancel_reason_text });
- if (!$reason) {
- # upgrade/FS::Setup created this one automatically
- my $reason_type = qsearchs('reason_type',
- { type => $cancel_reason_type }
- ) or die "default cancel reason type does not exist";
-
- $reason = FS::reason->new({
- reason_type => $reason_type->typenum,
- reason => $cancel_reason_text,
- disabled => 'Y',
- });
- $error = $reason->insert;
- if ( $error ) {
- return "$error (creating package cancel reason)";
- }
- }
+ my $reason = FS::reason->new_or_existing(
+ class => 'C',
+ type => $cancel_reason_type,
+ reason => $cancel_reason_text
+ );