|
Lines 20-26
Link Here
|
| 20 |
use Modern::Perl; |
20 |
use Modern::Perl; |
| 21 |
|
21 |
|
| 22 |
use Test::NoWarnings; |
22 |
use Test::NoWarnings; |
| 23 |
use Test::More tests => 10; |
23 |
use Test::More tests => 11; |
| 24 |
|
24 |
|
| 25 |
use Test::Exception; |
25 |
use Test::Exception; |
| 26 |
|
26 |
|
|
Lines 29-34
use Koha::Account;
Link Here
|
| 29 |
use Koha::Account::CreditTypes; |
29 |
use Koha::Account::CreditTypes; |
| 30 |
use Koha::Account::DebitTypes; |
30 |
use Koha::Account::DebitTypes; |
| 31 |
|
31 |
|
|
|
32 |
use t::lib::Mocks; |
| 32 |
use t::lib::TestBuilder; |
33 |
use t::lib::TestBuilder; |
| 33 |
|
34 |
|
| 34 |
my $builder = t::lib::TestBuilder->new; |
35 |
my $builder = t::lib::TestBuilder->new; |
|
Lines 1580-1582
subtest 'add_cashup' => sub {
Link Here
|
| 1580 |
|
1581 |
|
| 1581 |
$schema->storage->txn_rollback; |
1582 |
$schema->storage->txn_rollback; |
| 1582 |
}; |
1583 |
}; |
| 1583 |
- |
1584 |
|
|
|
1585 |
subtest 'required_reconciliation_note' => sub { |
| 1586 |
plan tests => 4; |
| 1587 |
|
| 1588 |
$schema->storage->txn_begin; |
| 1589 |
|
| 1590 |
my $register = $builder->build_object( { class => 'Koha::Cash::Registers' } ); |
| 1591 |
my $manager = $builder->build_object( { class => 'Koha::Patrons' } ); |
| 1592 |
my $patron = $builder->build_object( { class => 'Koha::Patrons' } ); |
| 1593 |
my $account = $patron->account; |
| 1594 |
|
| 1595 |
# Create a cash transaction |
| 1596 |
my $fine = $account->add_debit( |
| 1597 |
{ |
| 1598 |
amount => '10.00', |
| 1599 |
type => 'OVERDUE', |
| 1600 |
interface => 'cron' |
| 1601 |
} |
| 1602 |
); |
| 1603 |
|
| 1604 |
my $payment = $account->pay( |
| 1605 |
{ |
| 1606 |
cash_register => $register->id, |
| 1607 |
amount => '10.00', |
| 1608 |
credit_type => 'PAYMENT', |
| 1609 |
payment_type => 'CASH', |
| 1610 |
lines => [$fine] |
| 1611 |
} |
| 1612 |
); |
| 1613 |
|
| 1614 |
# Enable the required note preference |
| 1615 |
t::lib::Mocks::mock_preference( 'CashupReconciliationNoteRequired', 1 ); |
| 1616 |
|
| 1617 |
# Test 1: Missing note with discrepancy throws exception |
| 1618 |
throws_ok { |
| 1619 |
$register->add_cashup( |
| 1620 |
{ |
| 1621 |
manager_id => $manager->id, |
| 1622 |
amount => '15.00' # Creates discrepancy |
| 1623 |
} |
| 1624 |
); |
| 1625 |
} |
| 1626 |
'Koha::Exceptions::MissingParameter', |
| 1627 |
'Missing reconciliation note with discrepancy throws MissingParameter exception when preference enabled'; |
| 1628 |
|
| 1629 |
# Test 2: Note provided with discrepancy succeeds |
| 1630 |
my $cashup1; |
| 1631 |
lives_ok { |
| 1632 |
$cashup1 = $register->add_cashup( |
| 1633 |
{ |
| 1634 |
manager_id => $manager->id, |
| 1635 |
amount => '15.00', |
| 1636 |
reconciliation_note => 'Found extra money' |
| 1637 |
} |
| 1638 |
); |
| 1639 |
} |
| 1640 |
'Cashup with note and discrepancy succeeds when preference enabled'; |
| 1641 |
|
| 1642 |
# Test 3: No note with no discrepancy succeeds (note only required for discrepancies) |
| 1643 |
my $register2 = $builder->build_object( { class => 'Koha::Cash::Registers' } ); |
| 1644 |
my $fine2 = $account->add_debit( |
| 1645 |
{ |
| 1646 |
amount => '20.00', |
| 1647 |
type => 'OVERDUE', |
| 1648 |
interface => 'cron' |
| 1649 |
} |
| 1650 |
); |
| 1651 |
|
| 1652 |
my $payment2 = $account->pay( |
| 1653 |
{ |
| 1654 |
cash_register => $register2->id, |
| 1655 |
amount => '20.00', |
| 1656 |
credit_type => 'PAYMENT', |
| 1657 |
payment_type => 'CASH', |
| 1658 |
lines => [$fine2] |
| 1659 |
} |
| 1660 |
); |
| 1661 |
|
| 1662 |
my $cashup2; |
| 1663 |
lives_ok { |
| 1664 |
$cashup2 = $register2->add_cashup( |
| 1665 |
{ |
| 1666 |
manager_id => $manager->id, |
| 1667 |
amount => '20.00' # Exact amount, no discrepancy |
| 1668 |
} |
| 1669 |
); |
| 1670 |
} |
| 1671 |
'Cashup without note succeeds when there is no discrepancy'; |
| 1672 |
|
| 1673 |
# Test 4: Preference disabled allows missing note even with discrepancy |
| 1674 |
t::lib::Mocks::mock_preference( 'CashupReconciliationNoteRequired', 0 ); |
| 1675 |
|
| 1676 |
my $register3 = $builder->build_object( { class => 'Koha::Cash::Registers' } ); |
| 1677 |
my $fine3 = $account->add_debit( |
| 1678 |
{ |
| 1679 |
amount => '10.00', |
| 1680 |
type => 'OVERDUE', |
| 1681 |
interface => 'cron' |
| 1682 |
} |
| 1683 |
); |
| 1684 |
|
| 1685 |
my $payment3 = $account->pay( |
| 1686 |
{ |
| 1687 |
cash_register => $register3->id, |
| 1688 |
amount => '10.00', |
| 1689 |
credit_type => 'PAYMENT', |
| 1690 |
payment_type => 'CASH', |
| 1691 |
lines => [$fine3] |
| 1692 |
} |
| 1693 |
); |
| 1694 |
|
| 1695 |
my $cashup3; |
| 1696 |
lives_ok { |
| 1697 |
$cashup3 = $register3->add_cashup( |
| 1698 |
{ |
| 1699 |
manager_id => $manager->id, |
| 1700 |
amount => '15.00' # Creates discrepancy |
| 1701 |
} |
| 1702 |
); |
| 1703 |
} |
| 1704 |
'Missing note with discrepancy succeeds when preference disabled'; |
| 1705 |
|
| 1706 |
$schema->storage->txn_rollback; |
| 1707 |
}; |