View | Details | Raw Unified | Return to bug 33176
Collapse All | Expand All

(-)a/Koha/Account.pm (-4 / +12 lines)
Lines 87-92 sub pay { Link Here
87
87
88
    my $userenv = C4::Context->userenv;
88
    my $userenv = C4::Context->userenv;
89
89
90
    Koha::Exceptions::Account::PaymentTypeRequired->throw()
91
      if ( C4::Context->preference("RequirePaymentType")
92
        && !defined($payment_type) );
93
94
    my $av = Koha::AuthorisedValues->search_with_library_limits({ category => 'PAYMENT_TYPE', authorised_value => $payment_type });
95
96
    if ( !$av->count && C4::Context->preference("RequirePaymentType")) {
97
        Koha::Exceptions::Account::InvalidPaymentType->throw(
98
            error => 'Invalid payment type'
99
        );
100
    }
101
90
    my $manager_id = $userenv ? $userenv->{number} : undef;
102
    my $manager_id = $userenv ? $userenv->{number} : undef;
91
    my $interface = $params ? ( $params->{interface} || C4::Context->interface ) : C4::Context->interface;
103
    my $interface = $params ? ( $params->{interface} || C4::Context->interface ) : C4::Context->interface;
92
    my $payment = $self->payin_amount(
104
    my $payment = $self->payin_amount(
Lines 105-114 sub pay { Link Here
105
        }
117
        }
106
    );
118
    );
107
119
108
    Koha::Exceptions::Account::PaymentTypeRequired->throw()
109
      if ( C4::Context->preference("RequirePaymentType")
110
        && !defined($payment_type) );
111
112
    # NOTE: Pay historically always applied as much credit as it could to all
120
    # NOTE: Pay historically always applied as much credit as it could to all
113
    # existing outstanding debits, whether passed specific debits or otherwise.
121
    # existing outstanding debits, whether passed specific debits or otherwise.
114
    if ( $payment->amountoutstanding ) {
122
    if ( $payment->amountoutstanding ) {
(-)a/Koha/Exceptions/Account.pm (+4 lines)
Lines 51-56 use Exception::Class ( Link Here
51
    'Koha::Exceptions::Account::PaymentTypeRequired' => {
51
    'Koha::Exceptions::Account::PaymentTypeRequired' => {
52
        isa         => 'Koha::Exceptions::Account',
52
        isa         => 'Koha::Exceptions::Account',
53
        description => 'Account transaction requires a payment type'
53
        description => 'Account transaction requires a payment type'
54
    },
55
    'Koha::Exceptions::Account::InvalidPaymentType' => {
56
        isa         => 'Koha::Exceptions::Account',
57
        description => 'Invalid payment type'
54
    }
58
    }
55
);
59
);
56
60
(-)a/t/db_dependent/Koha/Account.t (-4 / +15 lines)
Lines 691-697 subtest 'reconcile_balance' => sub { Link Here
691
691
692
subtest 'pay() tests' => sub {
692
subtest 'pay() tests' => sub {
693
693
694
    plan tests => 7;
694
    plan tests => 8;
695
695
696
    $schema->storage->txn_begin;
696
    $schema->storage->txn_begin;
697
697
Lines 708-720 subtest 'pay() tests' => sub { Link Here
708
        $account->pay(
708
        $account->pay(
709
            {
709
            {
710
                amount       => 5,
710
                amount       => 5,
711
                interface    => 'intranet'
711
                interface    => 'intranet',
712
            }
712
            }
713
        );
713
        );
714
    }
714
    }
715
    'Koha::Exceptions::Account::PaymentTypeRequired',
715
    'Koha::Exceptions::Account::PaymentTypeRequired',
716
      'Exception thrown for RequirePaymentType:1 + payment_type:undef';
716
      'Exception thrown for RequirePaymentType:1 + payment_type:undef';
717
717
718
    throws_ok {
719
        $account->pay(
720
            {
721
                amount       => 5,
722
                interface    => 'intranet',
723
                payment_type => 'FOOBAR'
724
            }
725
        );
726
    }
727
    'Koha::Exceptions::Account::InvalidPaymentType',
728
      'Exception thrown for InvalidPaymentType:1 + payment_type:FOOBAR';
729
718
    t::lib::Mocks::mock_preference( 'RequirePaymentType', 0 );
730
    t::lib::Mocks::mock_preference( 'RequirePaymentType', 0 );
719
    my $context = Test::MockModule->new('C4::Context');
731
    my $context = Test::MockModule->new('C4::Context');
720
    $context->mock( 'userenv', { branch => $library->id } );
732
    $context->mock( 'userenv', { branch => $library->id } );
Lines 750-756 subtest 'pay() tests' => sub { Link Here
750
    my $result = $account->pay(
762
    my $result = $account->pay(
751
        {
763
        {
752
            amount => 20,
764
            amount => 20,
753
            payment_Type => 'CASH',
765
            payment_type => 'CASH',
754
            interface => 'intranet'
766
            interface => 'intranet'
755
        }
767
        }
756
    );
768
    );
757
- 

Return to bug 33176