Revision 871e4fc0
Von Enrique Morales vor mehr als 1 Jahr hinzugefügt
t/bank/bank_transactions.t | ||
---|---|---|
1 |
use Test::More tests =>402;
|
|
1 |
use Test::More tests => 411;
|
|
2 | 2 |
|
3 | 3 |
use strict; |
4 | 4 |
|
... | ... | |
84 | 84 |
test_negative_ar_transaction_fx_loss(); |
85 | 85 |
test_ar_transaction_fx_loss(); |
86 | 86 |
test_ar_transaction_fx_gain(); |
87 |
test_ar_transaction_fx_partial_payment(); |
|
87 | 88 |
#test_neg_sales_invoice_fx(); |
88 | 89 |
negative_ap_transaction_fx_gain_fees_error(); |
89 | 90 |
|
... | ... | |
1793 | 1794 |
is($bt->invoice_amount , '-297.38000' , "$testname: bt invoice amount was assigned"); |
1794 | 1795 |
} |
1795 | 1796 |
|
1797 |
sub test_ar_transaction_fx_partial_payment { |
|
1798 |
my (%params) = @_; |
|
1799 |
my $netamount = $::form->round_amount($params{amount}, 2) || 3674580*0.08613; |
|
1800 |
# set exchangerate |
|
1801 |
my $ex = SL::DB::Manager::Exchangerate->find_by(currency_id => $currency_usd->id, |
|
1802 |
transdate => $dt) |
|
1803 |
|| SL::DB::Exchangerate->new(currency_id => $currency_usd->id, |
|
1804 |
transdate => $dt); |
|
1805 |
$ex->update_attributes(buy => 0.08613); |
|
1806 |
|
|
1807 |
my $testname = 'test_ar_transaction_fx_partial_payment'; |
|
1808 |
|
|
1809 |
my $invoice = SL::DB::Invoice->new( |
|
1810 |
invoice => 0, |
|
1811 |
invnumber => $params{invnumber} || undef, # let it use its own invnumber |
|
1812 |
amount => $netamount, |
|
1813 |
netamount => $netamount, |
|
1814 |
transdate => $dt, |
|
1815 |
taxincluded => $params{taxincluded } || 0, |
|
1816 |
customer_id => $customer->id, |
|
1817 |
taxzone_id => $customer->taxzone_id, |
|
1818 |
currency_id => $currency_usd->id, |
|
1819 |
transactions => [], |
|
1820 |
payment_id => $params{payment_id} || undef, |
|
1821 |
notes => 'test_ar_transaction_fx_partial_payment', |
|
1822 |
); |
|
1823 |
my $acno_8100 = SL::DB::Manager::Chart->find_by( accno => '8100' ); |
|
1824 |
$invoice->add_ar_amount_row( |
|
1825 |
amount => $invoice->netamount, |
|
1826 |
chart => $acno_8100, # Erlöse steuerfrei |
|
1827 |
tax_id => 0, |
|
1828 |
); |
|
1829 |
$invoice->create_ar_row(chart => $ar_chart); |
|
1830 |
$invoice->save; |
|
1831 |
|
|
1832 |
is($invoice->currency_id , $currency_usd->id , 'currency_id has been saved'); |
|
1833 |
is($invoice->netamount , '316491.5754' , 'fx ar amount has been converted'); |
|
1834 |
is($invoice->taxincluded , 0 , 'fx ar transaction doesn\'t have taxincluded'); |
|
1835 |
|
|
1836 |
my $bt = create_bank_transaction(record => $invoice, |
|
1837 |
bank_chart_id => $bank->id, |
|
1838 |
transdate => $dt, |
|
1839 |
valutadate => $dt, |
|
1840 |
amount => 315636.49, |
|
1841 |
) or die "Couldn't create bank_transaction"; |
|
1796 | 1842 |
|
1843 |
is($bt->amount , '315636.49' , "$testname: positive bt amount"); |
|
1844 |
$::form->{invoice_ids} = { |
|
1845 |
$bt->id => [ $invoice->id ] |
|
1846 |
}; |
|
1847 |
$::form->{"exchangerate_" . $bt->id . "_" . $invoice->id} = "0,08726"; # will be parsed |
|
1848 |
$::form->{"currency_id_" . $bt->id . "_" . $invoice->id} = $currency_usd->id; |
|
1849 |
|
|
1850 |
|
|
1851 |
save_btcontroller_to_string(); |
|
1852 |
|
|
1853 |
$invoice->load; |
|
1854 |
$bt->load; |
|
1855 |
|
|
1856 |
is(scalar @{ SL::DB::Manager::BankTransactionAccTrans->get_all(where => [bank_transaction_id => $bt->id ] )}, |
|
1857 |
3, "$testname 3 acc_trans entries created"); |
|
1858 |
|
|
1859 |
my $gl_fee_booking = SL::DB::Manager::BankTransactionAccTrans->get_all(where => [bank_transaction_id => $bt->id, '!gl_id' => undef ] ); |
|
1860 |
is(scalar @{ $gl_fee_booking }, 0, 'Zero GL acc_trans bookings'); |
|
1861 |
|
|
1862 |
my $fx_gain_transactions = SL::DB::Manager::AccTransaction->get_all(where => |
|
1863 |
[ trans_id => $invoice->id, chart_id => $fxgain_chart->id ], |
|
1864 |
sort_by => ('acc_trans_id')); |
|
1865 |
|
|
1866 |
is($fx_gain_transactions->[0]->amount, '4087.43000', "$testname: fx gain amount ok"); |
|
1867 |
|
|
1868 |
|
|
1869 |
is($invoice->paid , '311549.06000' , "$testname: ar transaction was paid partially"); |
|
1870 |
is($bt->invoice_amount , '315636.49000' , "$testname: bt invoice amount was assigned"); |
|
1871 |
} |
|
1797 | 1872 |
|
1798 | 1873 |
sub test_ar_transaction_fx_gain { |
1799 | 1874 |
my (%params) = @_; |
Auch abrufbar als: Unified diff
Test für Teilzahlung mit Fremdwährung hinzugefügt