Bugzilla – Attachment 94005 Details for
Bug 23049
Replace MANUAL_INV authorised value with a dedicated table
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 23049: Drop type lookup as it's now a foreign key
Bug-23049-Drop-type-lookup-as-its-now-a-foreign-ke.patch (text/plain), 7.89 KB, created by
Martin Renvoize (ashimema)
on 2019-10-11 11:43:55 UTC
(
hide
)
Description:
Bug 23049: Drop type lookup as it's now a foreign key
Filename:
MIME Type:
Creator:
Martin Renvoize (ashimema)
Created:
2019-10-11 11:43:55 UTC
Size:
7.89 KB
patch
obsolete
>From 1991d910a23d13a23d9462af9dc15ece3e679e8b Mon Sep 17 00:00:00 2001 >From: Martin Renvoize <martin.renvoize@ptfs-europe.com> >Date: Thu, 10 Oct 2019 16:58:23 +0100 >Subject: [PATCH] Bug 23049: Drop type lookup as it's now a foreign key >MIME-Version: 1.0 >Content-Type: text/plain; charset=UTF-8 >Content-Transfer-Encoding: 8bit > >Signed-off-by: Séverine QUEUNE <severine.queune@bulac.fr> >--- > Koha/Account.pm | 145 ++++++++++++++++------------------ > t/db_dependent/Koha/Account.t | 4 +- > 2 files changed, 71 insertions(+), 78 deletions(-) > >diff --git a/Koha/Account.pm b/Koha/Account.pm >index 48ddd829b7..f63d442d5d 100644 >--- a/Koha/Account.pm >+++ b/Koha/Account.pm >@@ -22,6 +22,7 @@ use Modern::Perl; > use Carp; > use Data::Dumper; > use List::MoreUtils qw( uniq ); >+use Try::Tiny; > > use C4::Circulation qw( ReturnLostItem ); > use C4::Letters; >@@ -477,7 +478,7 @@ sub add_debit { > my $user_id = $params->{user_id}; > my $interface = $params->{interface}; > my $library_id = $params->{library_id}; >- my $type = $params->{type}; >+ my $debit_type = $params->{type}; > my $item_id = $params->{item_id}; > my $issue_id = $params->{issue_id}; > >@@ -488,69 +489,80 @@ sub add_debit { > > my $schema = Koha::Database->new->schema; > >- unless ( exists($Koha::Account::account_type_debit->{$type}) ) { >- Koha::Exceptions::Account::UnrecognisedType->throw( >- error => 'Type of debit not recognised' >- ); >- } >- >- my $debit_type_code = $Koha::Account::account_type_debit->{$type}; >+ my $offset_type = $Koha::Account::offset_type->{$debit_type} // 'Manual Debit'; > > my $line; >- $schema->txn_do( >- sub { >+ try { >+ $schema->txn_do( >+ sub { > >- # Insert the account line >- $line = Koha::Account::Line->new( >- { >- borrowernumber => $self->{patron_id}, >- date => \'NOW()', >- amount => $amount, >- description => $description, >- debit_type_code => $debit_type_code, >- amountoutstanding => $amount, >- payment_type => undef, >- note => $note, >- manager_id => $user_id, >- interface => $interface, >- itemnumber => $item_id, >- issue_id => $issue_id, >- branchcode => $library_id, >- ( $type eq 'OVERDUE' ? ( status => 'UNRETURNED' ) : () ), >- } >- )->store(); >+ # Insert the account line >+ $line = Koha::Account::Line->new( >+ { >+ borrowernumber => $self->{patron_id}, >+ date => \'NOW()', >+ amount => $amount, >+ description => $description, >+ debit_type_code => $debit_type, >+ amountoutstanding => $amount, >+ payment_type => undef, >+ note => $note, >+ manager_id => $user_id, >+ interface => $interface, >+ itemnumber => $item_id, >+ issue_id => $issue_id, >+ branchcode => $library_id, >+ ( >+ $debit_type eq 'OVERDUE' >+ ? ( status => 'UNRETURNED' ) >+ : () >+ ), >+ } >+ )->store(); > >- # Record the account offset >- my $account_offset = Koha::Account::Offset->new( >- { >- debit_id => $line->id, >- type => $Koha::Account::offset_type->{$type}, >- amount => $amount >+ # Record the account offset >+ my $account_offset = Koha::Account::Offset->new( >+ { >+ debit_id => $line->id, >+ type => $offset_type, >+ amount => $amount >+ } >+ )->store(); >+ >+ if ( C4::Context->preference("FinesLog") ) { >+ logaction( >+ "FINES", 'CREATE', >+ $self->{patron_id}, >+ Dumper( >+ { >+ action => "create_$debit_type", >+ borrowernumber => $self->{patron_id}, >+ amount => $amount, >+ description => $description, >+ amountoutstanding => $amount, >+ debit_type_code => $debit_type, >+ note => $note, >+ itemnumber => $item_id, >+ manager_id => $user_id, >+ } >+ ), >+ $interface >+ ); > } >- )->store(); >- >- if ( C4::Context->preference("FinesLog") ) { >- logaction( >- "FINES", 'CREATE', >- $self->{patron_id}, >- Dumper( >- { >- action => "create_$type", >- borrowernumber => $self->{patron_id}, >- amount => $amount, >- description => $description, >- amountoutstanding => $amount, >- debit_type_code => $debit_type_code, >- note => $note, >- itemnumber => $item_id, >- manager_id => $user_id, >- } >- ), >- $interface >- ); >+ } >+ ); >+ } >+ catch { >+ if ( ref($_) eq 'Koha::Exceptions::Object::FKConstraint' ) { >+ if ( $_->broken_fk eq 'debit_type_code' ) { >+ Koha::Exceptions::Account::UnrecognisedType->throw( >+ error => 'Type of debit not recognised' ); >+ } >+ else { >+ $_->rethrow; > } > } >- ); >+ }; > > return $line; > } >@@ -733,25 +745,6 @@ our $account_type_credit = { > 'writeoff' => 'W' > }; > >-=head3 $account_type_debit >- >-=cut >- >-our $account_type_debit = { >- 'ACCOUNT' => 'ACCOUNT', >- 'ACCOUNT_RENEW' => 'ACCOUNT_RENEW', >- 'RESERVE_EXPIRED' => 'RESERVE_EXPIRED', >- 'LOST_ITEM' => 'LOST', >- 'NEW_CARD' => 'NEW_CARD', >- 'OVERDUE' => 'OVERDUE', >- 'PROCESSING' => 'PROCESSING', >- 'RENT' => 'RENT', >- 'RENT_DAILY' => 'RENT_DAILY', >- 'RENT_RENEW' => 'RENT_RENEW', >- 'RENT_DAILY_RENEW' => 'RENT_DAILY_RENEW', >- 'RESERVE' => 'RESERVE', >-}; >- > =head1 AUTHORS > > =encoding utf8 >diff --git a/t/db_dependent/Koha/Account.t b/t/db_dependent/Koha/Account.t >index 02efbd1c04..568cbf283e 100755 >--- a/t/db_dependent/Koha/Account.t >+++ b/t/db_dependent/Koha/Account.t >@@ -344,7 +344,7 @@ subtest 'add_debit() tests' => sub { > ); > is( > $line_1->debit_type_code, >- $Koha::Account::account_type_debit->{'RENT'}, >+ 'RENT', > 'Account type is correctly set' > ); > >@@ -371,7 +371,7 @@ subtest 'add_debit() tests' => sub { > ); > is( > $line_2->debit_type_code, >- $Koha::Account::account_type_debit->{'RENT'}, >+ 'RENT', > 'Account type is correctly set' > ); > >-- >2.20.1
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 23049
:
93513
|
93514
|
93515
|
93516
|
93518
|
93519
|
93520
|
93521
|
93522
|
93523
|
93529
|
93557
|
93564
|
93565
|
93567
|
93568
|
93569
|
93570
|
93571
|
93572
|
93573
|
93574
|
93575
|
93576
|
93577
|
93578
|
93579
|
93960
|
93961
|
93962
|
93963
|
93964
|
93965
|
93966
|
93967
|
93968
|
93969
|
93970
|
93972
|
93973
|
93974
|
93975
|
93976
|
93977
|
93978
|
93979
|
93989
|
93990
|
93991
|
93992
|
93993
|
93994
|
93995
|
93996
|
93997
|
93998
|
93999
|
94000
|
94001
|
94002
|
94003
|
94004
|
94005
|
94006
|
94007
|
94008
|
94073
|
94074
|
94075
|
94076
|
94077
|
94078
|
94079
|
94080
|
94081
|
94082
|
94083
|
94084
|
94085
|
94086
|
94087
|
94088
|
94089
|
94090
|
94091
|
94092
|
94093
|
94111
|
94112
|
94113
|
94114
|
94115
|
94116
|
94117
|
94118
|
94119
|
94120
|
94121
|
94122
|
94123
|
94124
|
94125
|
94126
|
94127
|
94128
|
94129
|
94130
|
94131
|
94132
|
94133
|
94134
|
94135
|
94136
|
94137
|
94138
|
94139
|
94140
|
94141
|
94142
|
94143
|
94144
|
94145
|
94146
|
94147
|
94148
|
94149
|
94150
|
94151
|
94152
|
94165
|
94307
|
94308
|
94309
|
94310
|
94311
|
94312
|
94313
|
94314
|
94315
|
94316
|
94317
|
94318
|
94319
|
94320
|
94321
|
94323
|
94324
|
94325
|
94326
|
94327
|
94328
|
94329
|
94331
|
94332
|
94333
|
94334
|
94335
|
94336
|
94337
|
94338
|
94339
|
94340
|
94341
|
94342
|
94343
|
94344
|
94345
|
94346
|
94347
|
94348
|
94349
|
94350
|
94351
|
94352
|
94648