Lines 20-26
Link Here
|
20 |
use Modern::Perl; |
20 |
use Modern::Perl; |
21 |
use FindBin qw( $Bin ); |
21 |
use FindBin qw( $Bin ); |
22 |
|
22 |
|
23 |
use Test::More tests => 2; |
23 |
use Test::More tests => 3; |
24 |
use Test::Warn; |
24 |
use Test::Warn; |
25 |
use Test::MockModule; |
25 |
use Test::MockModule; |
26 |
|
26 |
|
Lines 815-817
subtest 'process_invoice' => sub {
Link Here
|
815 |
|
815 |
|
816 |
$schema->storage->txn_rollback; |
816 |
$schema->storage->txn_rollback; |
817 |
}; |
817 |
}; |
818 |
- |
818 |
|
|
|
819 |
subtest 'process_invoice_without_tax_rate' => sub { |
820 |
plan tests => 4; |
821 |
|
822 |
$schema->storage->txn_begin; |
823 |
|
824 |
# Add test EDI account and vendor |
825 |
my $account = $builder->build( |
826 |
{ |
827 |
source => 'VendorEdiAccount', |
828 |
value => { |
829 |
description => 'Test account for tax rate handling', |
830 |
plugin => q{}, |
831 |
} |
832 |
} |
833 |
); |
834 |
|
835 |
# Add test order to match with invoice |
836 |
my $order = $builder->build( |
837 |
{ |
838 |
source => 'Aqorder', |
839 |
value => { |
840 |
quantity => 1, |
841 |
listprice => 10.00, |
842 |
unitprice => 10.00, |
843 |
quantityreceived => 0, |
844 |
orderstatus => 'ordered', |
845 |
biblionumber => $builder->build_sample_biblio->biblionumber, |
846 |
basketno => |
847 |
$builder->build( { source => 'Aqbasket', value => { booksellerid => $account->{vendor_id} } } ) |
848 |
->{basketno}, |
849 |
} |
850 |
} |
851 |
); |
852 |
|
853 |
# Create a minimal EDI invoice without TAX segments |
854 |
my $edi_invoice = |
855 |
qq{UNA:+.? 'UNB+UNOC:3+TEST+KOHA+200101:0000+1'UNH+1+INVOIC:D:96A:UN'BGM+380+TEST001+9'DTM+137:20200101:102'NAD+BY+12345::9'NAD+SU+$account->{san}::9'LIN+1++123456789:EN'QTY+47:1'GIR+001+TEST:LLO+12345678901234:LAC+TEST001:LCO+TESTATB:LFN'PRI+AAA:10.00'PRI+AAB:10.00'MOA+203:10.00'RFF+LI:$order->{ordernumber}'UNS+S'CNT+1:1'MOA+79:10.00'MOA+129:10.00'MOA+122:10.00'UNT+15+1'UNZ+1+1'}; |
856 |
|
857 |
# Create EDI message in database |
858 |
my $edi_message = $builder->build( |
859 |
{ |
860 |
source => 'EdifactMessage', |
861 |
value => { |
862 |
message_type => 'INVOICE', |
863 |
filename => 'TEST_NO_TAX.CEI', |
864 |
raw_msg => $edi_invoice, |
865 |
status => 'new', |
866 |
vendor_id => $account->{vendor_id}, |
867 |
edi_acct => $account->{id}, |
868 |
} |
869 |
} |
870 |
); |
871 |
|
872 |
my $invoice_message = $schema->resultset('EdifactMessage')->find( $edi_message->{id} ); |
873 |
|
874 |
# Process the invoice - this should not generate warnings about undefined tax rates |
875 |
my $error; |
876 |
my $warnings = []; |
877 |
{ |
878 |
local $SIG{__WARN__} = sub { push @$warnings, $_[0] }; |
879 |
eval { |
880 |
process_invoice($invoice_message); |
881 |
1; |
882 |
} or do { |
883 |
$error = $@; |
884 |
}; |
885 |
} |
886 |
|
887 |
ok( !$error, 'process_invoice completed without dying when no tax rate present' ); |
888 |
|
889 |
# Check that no warnings about uninitialized values in multiplication were generated |
890 |
my $tax_warnings = grep { /Use of uninitialized value.*multiplication/ } @$warnings; |
891 |
is( $tax_warnings, 0, 'No warnings about uninitialized values in multiplication' ); |
892 |
|
893 |
# Verify that orders with tax data exist (means processing completed) |
894 |
my $orders = $schema->resultset('Aqorder')->search( |
895 |
{ |
896 |
basketno => $order->{basketno}, |
897 |
tax_rate_on_receiving => { '>=', 0 } |
898 |
} |
899 |
); |
900 |
|
901 |
ok( $orders->count > 0, 'Order processing completed successfully' ); |
902 |
|
903 |
# Check that tax values were set correctly (should be 0 for no tax) |
904 |
my $order_with_tax = $orders->first; |
905 |
is( $order_with_tax->tax_rate_on_receiving + 0, 0, 'Tax rate set to 0 when no tax rate in EDI message' ); |
906 |
|
907 |
$schema->storage->txn_rollback; |
908 |
}; |