Revision 61e8db07
Von Jan Büren vor mehr als 6 Jahren hinzugefügt
SL/Controller/BankTransaction.pm | ||
---|---|---|
618 | 618 |
|
619 | 619 |
$n_invoices++ ; |
620 | 620 |
|
621 |
# Check if bank_transaction already has a link to the invoice, may only be linked once per invoice |
|
622 |
# This might be caused by the user reloading a page and resending the form |
|
623 |
if (_existing_record_link($bank_transaction, $invoice)) { |
|
624 |
return { |
|
625 |
%data, |
|
626 |
result => 'error', |
|
627 |
message => $::locale->text("Bank transaction with id #1 has already been linked to #2.", $bank_transaction->id, $invoice->displayable_name), |
|
628 |
}; |
|
629 |
} |
|
630 | 621 |
|
631 | 622 |
if (!$amount_of_transaction && $invoice->open_amount) { |
632 | 623 |
return { |
... | ... | |
842 | 833 |
); |
843 | 834 |
} |
844 | 835 |
|
845 |
sub _existing_record_link { |
|
846 |
my ($bt, $invoice) = @_; |
|
847 |
|
|
848 |
# check whether a record link from banktransaction $bt already exists to |
|
849 |
# invoice $invoice, returns 1 if that is the case |
|
850 |
|
|
851 |
die unless $bt->isa("SL::DB::BankTransaction") && ( $invoice->isa("SL::DB::Invoice") || $invoice->isa("SL::DB::PurchaseInvoice") ); |
|
852 |
|
|
853 |
my $linked_record_to_table = $invoice->is_sales ? 'Invoice' : 'PurchaseInvoice'; |
|
854 |
my $linked_records = $bt->linked_records( direction => 'to', to => $linked_record_to_table, query => [ id => $invoice->id ] ); |
|
855 |
|
|
856 |
return @$linked_records ? 1 : 0; |
|
857 |
}; |
|
858 |
|
|
859 | 836 |
sub init_problems { [] } |
860 | 837 |
|
861 | 838 |
sub init_models { |
Auch abrufbar als: Unified diff
BankTransaction weniger Code ist mehr Wert
Aufgrund des klarer formulierten PODs kann eine Routine und
eine weitere zu "schwache" Bedingung entfernt werden.
Fast alle kivi-Testfälle inkl. adaptierter odyn-Testfälle laufen sauber durch.