Skip to content

Commit 8e673f9

Browse files
authored
Merge branch 'master' into 202408-bankconfig
2 parents 00537d4 + b5ac853 commit 8e673f9

File tree

93 files changed

+1336
-642
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

93 files changed

+1336
-642
lines changed

SL/AM.pm

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -565,6 +565,10 @@ sub layout_style {
565565
SL::Helper::UserPreferences::DisplayPreferences->new()->get_layout_style();
566566
}
567567

568+
sub part_picker_search_all_as_list_default {
569+
SL::Helper::UserPreferences::PartPickerSearch->new()->get_all_as_list_default();
570+
}
571+
568572
sub save_preferences {
569573
$main::lxdebug->enter_sub();
570574

@@ -611,6 +615,9 @@ sub save_preferences {
611615
if (exists $form->{layout_style}) {
612616
SL::Helper::UserPreferences::DisplayPreferences->new()->store_layout_style($form->{layout_style})
613617
}
618+
if (exists $form->{part_picker_search_all_as_list_default}) {
619+
SL::Helper::UserPreferences::PartPickerSearch->new()->store_all_as_list_default($form->{part_picker_search_all_as_list_default})
620+
}
614621

615622
$main::lxdebug->leave_sub();
616623

SL/AR.pm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -626,7 +626,7 @@ sub ar_transactions {
626626
}
627627
if ($form->{"project_id"}) {
628628
$where .=
629-
qq|AND ((a.globalproject_id = ?) OR EXISTS | .
629+
qq| AND ((a.globalproject_id = ?) OR EXISTS | .
630630
qq| (SELECT * FROM invoice i | .
631631
qq| WHERE i.project_id = ? AND i.trans_id = a.id) | .
632632
qq| OR EXISTS | .

SL/Controller/BankImport.pm

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,16 +170,18 @@ sub make_transaction_idx {
170170
my ($transaction) = @_;
171171

172172
if (ref($transaction) eq 'SL::DB::BankTransaction') {
173-
$transaction = { map { ($_ => $transaction->$_) } qw(local_bank_account_id transdate valutadate amount purpose) };
173+
$transaction = { map { ($_ => $transaction->$_) } qw(local_bank_account_id remote_account_number transdate valutadate amount purpose end_to_end_id) };
174174
}
175175

176+
my @other_fields = $transaction->{end_to_end_id} && $::instance_conf->get_check_bt_duplicates_endtoend
177+
? qw(end_to_end_id remote_account_number) : qw(purpose);
176178
return normalize_text(join '/',
177179
map { $_ // '' }
178180
($transaction->{local_bank_account_id},
179181
$transaction->{transdate}->ymd,
180182
$transaction->{valutadate}->ymd,
181183
(apply { s{0+$}{} } $transaction->{amount} * 1),
182-
$transaction->{purpose}));
184+
map { $transaction->{$_} } @other_fields));
183185
}
184186
185187
sub init_bank_accounts {

SL/Controller/BankTransaction.pm

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -969,7 +969,7 @@ sub prepare_report {
969969
$report->{title} = t8('Bank transactions');
970970
$self->{report} = $report;
971971

972-
my @columns = qw(ids local_bank_name transdate valudate remote_name remote_account_number remote_bank_code amount invoice_amount invoices currency purpose local_account_number local_bank_code id);
972+
my @columns = qw(ids local_bank_name transdate valudate remote_name remote_account_number remote_bank_code amount invoice_amount invoices currency purpose end_to_end_id local_account_number local_bank_code id);
973973
my @sortable = qw(local_bank_name transdate valudate remote_name remote_account_number remote_bank_code amount purpose local_account_number local_bank_code);
974974

975975
my %column_defs = (
@@ -1007,6 +1007,7 @@ sub prepare_report {
10071007
local_account_number => { sub => sub { $_[0]->local_bank_account->account_number } },
10081008
local_bank_code => { sub => sub { $_[0]->local_bank_account->bank_code } },
10091009
local_bank_name => { sub => sub { $_[0]->local_bank_account->name } },
1010+
end_to_end_id => { sub => sub { $_[0]->end_to_end_id }, text => $::locale->text('End to end ID') },
10101011
id => {},
10111012
);
10121013

SL/Controller/CsvImport/BankTransaction.pm

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,15 @@ sub check_objects {
5050
$self->check_currency($entry, take_default => 1);
5151
$self->join_purposes($entry);
5252
$self->join_remote_names($entry);
53+
$self->extract_end_to_end_id($entry);
5354
$self->check_existing($entry) unless @{ $entry->{errors} };
5455
} continue {
5556
$i++;
5657
}
5758

5859
$self->add_info_columns({ header => $::locale->text('Bank account'), method => 'local_bank_name' });
5960
$self->add_raw_data_columns("currency", "currency_id") if grep { /^currency(?:_id)?$/ } @{ $self->csv->header };
61+
$self->add_info_columns({ header => $::locale->text('End to end ID'), method => 'end_to_end_id' });
6062
}
6163

6264
sub check_existing {
@@ -76,7 +78,16 @@ sub check_existing {
7678
# * amount
7779
# * local_bank_account_id (case flatrate bank charges for two accounts in one bank: same purpose, transdate, remote_account_number(empty), amount. Just different local_bank_account_id)
7880
my $num;
79-
if ( $num = SL::DB::Manager::BankTransaction->get_all_count(query =>[ remote_account_number => $object->remote_account_number, transdate => $object->transdate, purpose => $object->purpose, amount => $object->amount, local_bank_account_id => $object->local_bank_account_id] ) ) {
81+
82+
my @conditions;
83+
84+
if ($object->end_to_end_id && $::instance_conf->get_check_bt_duplicates_endtoend) {
85+
push @conditions, ( end_to_end_id => $object->end_to_end_id );
86+
} else {
87+
push @conditions, ( purpose => $object->purpose );
88+
}
89+
90+
if ( $num = SL::DB::Manager::BankTransaction->get_all_count(query =>[ remote_account_number => $object->remote_account_number, transdate => $object->transdate, amount => $object->amount, local_bank_account_id => $object->local_bank_account_id, @conditions] ) ) {
8091
push(@{$entry->{errors}}, $::locale->text('Skipping due to existing bank transaction in database'));
8192
};
8293
} else {
@@ -203,6 +214,19 @@ sub join_remote_names {
203214
$object->remote_name($remote_name);
204215
}
205216

217+
sub extract_end_to_end_id {
218+
my ($self, $entry) = @_;
219+
220+
my $object = $entry->{object};
221+
222+
return if $object->purpose !~ m{\b(?:end\W?to\W?end:|eref\+) *([^ ]+)}i;
223+
224+
my $id = $1;
225+
226+
$object->end_to_end_id($id) if $id !~ m{notprovided}i;
227+
$entry->{info_data}->{end_to_end_id} = $object->end_to_end_id;
228+
}
229+
206230
sub check_auth {
207231
$::auth->assert('config') if ! $::auth->assert('bank_transaction',1);
208232
}

SL/Controller/CsvImport/Base.pm

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -534,6 +534,33 @@ sub save_objects {
534534
return unless $data->[0];
535535
return unless $data->[0]{object};
536536

537+
# If we store into tables which get numbers from the TransNumberGenerator
538+
# we have to lock all tables referenced by the storage table (or by
539+
# tables stored alongside with the storage table) that are handled by
540+
# the TransNumberGenerator, too.
541+
# Otherwise we can run into a deadlock if someone saves a document via
542+
# the user interface. The exact behavoir depends on timing.
543+
# E.g. we are importing orders and a user want to
544+
# book an invoice:
545+
# web: locks ar (via before-save hook and TNG (or SL::TransNumber))
546+
# importer: locks oe (via before-save hook and TNG) (*)
547+
# importer: locks defaults (via before-save hook and TNG)
548+
# web: wants to lock defaults (via before-save hook and TNG (or SL::TransNumber)) -> is waiting
549+
# importer: wants to save oe and wants to lock referenced tables (here ar) -> is waiting
550+
# --> deadlock
551+
#
552+
# (*) if the importer locks ar here, too, everything is fine, because it will wait here
553+
# before locking the defaults table.
554+
#
555+
# List of referenced tables:
556+
# (Locking is done in the transaction below)
557+
my %referenced_tables_by_type = (
558+
orders => [qw(ar customer vendor)],
559+
delivery_orders => [qw(customer vendor) ],
560+
ar_transactions => [qw(customer) ],
561+
ap_transactions => [qw(vendor) ],
562+
);
563+
537564
$self->controller->track_progress(phase => 'saving data', progress => 0); # scale from 45..95%;
538565

539566
my $last_index = $#$data;
@@ -542,6 +569,11 @@ sub save_objects {
542569
for my $chunk (0 .. $last_index / $chunk_size) {
543570
$self->controller->track_progress(progress => ($chunk_size * $chunk)/scalar(@$data) * 100); # scale from 45..95%;
544571
SL::DB->client->with_transaction(sub {
572+
573+
foreach my $refs (@{ $referenced_tables_by_type{$self->controller->{type}} || [] }) {
574+
SL::DB->client->dbh->do("LOCK " . $refs) || die SL::DB->client->dbh->errstr;
575+
}
576+
545577
foreach my $entry_index ($chunk_size * $chunk .. min( $last_index, $chunk_size * ($chunk + 1) - 1 )) {
546578
my $entry = $data->[$entry_index];
547579

SL/Controller/CustomDataExport.pm

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ sub action_export {
104104

105105
sub check_auth {
106106
my ($self) = @_;
107+
$::auth->assert('custom_data_report');
107108
$::auth->assert($self->query->access_right) if $self->query->access_right;
108109
}
109110

0 commit comments

Comments
 (0)