Bug 23049: Add debit_type
authorMartin Renvoize <martin.renvoize@ptfs-europe.com>
Thu, 28 Feb 2019 16:58:06 +0000 (16:58 +0000)
committerMartin Renvoize <martin.renvoize@ptfs-europe.com>
Thu, 24 Oct 2019 16:23:48 +0000 (17:23 +0100)
* Add account_debit_types table
* Add ac_debit_types_branches table
* Add account_debit_types defaults
* Add Koha::Account::DebitType and Koha::Account::DebitTypes
* Prevent deletion of defaults
* Migrate MANUAL_INV values
* Remove MANUAL_INV references
* Migrate accounttype values

Signed-off-by: Séverine QUEUNE <severine.queune@bulac.fr>
Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>

16 files changed:
C4/Installer.pm
Koha/Account.pm
Koha/Account/DebitType.pm [new file with mode: 0644]
Koha/Account/DebitTypes.pm [new file with mode: 0644]
Koha/Schema/Result/Accountline.pm
Koha/Schema/Result/Branch.pm
installer/data/mysql/account_debit_types.sql [new file with mode: 0644]
installer/data/mysql/atomicupdate/bug_23049_debit.perl [new file with mode: 0644]
installer/data/mysql/en/mandatory/account_debit_types.sql [new file with mode: 0644]
installer/data/mysql/en/optional/auth_val.sql
installer/data/mysql/kohastructure.sql
installer/data/mysql/mandatory/auth_val_cat.sql
koha-tmpl/intranet-tmpl/prog/en/modules/admin/authorised_values.tt
koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/circulation.pref
misc/devel/populate_db.pl
t/db_dependent/Accounts.t

index 9b24ff3..e4cae05 100644 (file)
@@ -332,6 +332,7 @@ sub load_sql_in_order {
     push @fnames, C4::Context->config('intranetdir') . "/installer/data/mysql/userpermissions.sql";
     push @fnames, C4::Context->config('intranetdir') . "/installer/data/mysql/audio_alerts.sql";
     push @fnames, C4::Context->config('intranetdir') . "/installer/data/mysql/account_offset_types.sql";
+    push @fnames, C4::Context->config('intranetdir') . "/installer/data/mysql/account_debit_types.sql";
     foreach my $file (@fnames) {
         #      warn $file;
         undef $/;
index afff235..743b4b7 100644 (file)
@@ -628,28 +628,21 @@ Charges exempt from non-issue are:
 sub non_issues_charges {
     my ($self) = @_;
 
-    # FIXME REMOVE And add a warning in the about page + update DB if length(MANUAL_INV) > 5
-    my $ACCOUNT_TYPE_LENGTH = 5;    # this is plain ridiculous...
-
+    #NOTE: With bug 23049 these preferences could be moved to being attached
+    #to individual debit types to give more flexability and specificity.
     my @not_fines;
     push @not_fines, 'Res'
       unless C4::Context->preference('HoldsInNoissuesCharge');
-    push @not_fines, 'Rent'
+    push @not_fines, ( 'RENT', 'RENT_DAILY', 'RENT_RENEW', 'RENT_DAILY_RENEW' )
       unless C4::Context->preference('RentalsInNoissuesCharge');
     unless ( C4::Context->preference('ManInvInNoissuesCharge') ) {
-        my $dbh = C4::Context->dbh;
-        push @not_fines,
-          @{
-            $dbh->selectcol_arrayref(q|
-                SELECT authorised_value FROM authorised_values WHERE category = 'MANUAL_INV'
-            |)
-          };
+        my @man_inv = Koha::Account::DebitTypes->search({ system => 0 })->get_column('code');
+        push @not_fines, @man_inv;
     }
-    @not_fines = map { substr( $_, 0, $ACCOUNT_TYPE_LENGTH ) } uniq(@not_fines);
 
     return $self->lines->search(
         {
-            accounttype    => { -not_in => \@not_fines }
+            debit_type => { -not_in => \@not_fines }
         },
     )->total_outstanding;
 }
diff --git a/Koha/Account/DebitType.pm b/Koha/Account/DebitType.pm
new file mode 100644 (file)
index 0000000..59bb5c1
--- /dev/null
@@ -0,0 +1,60 @@
+package Koha::Account::DebitType;
+
+# Copyright PTFS Europe 2019
+#
+# This file is part of Koha.
+#
+# Koha is free software; you can redistribute it and/or modify it under the
+# terms of the GNU General Public License as published by the Free Software
+# Foundation; either version 3 of the License, or (at your option) any later
+# version.
+#
+# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
+# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License along
+# with Koha; if not, write to the Free Software Foundation, Inc.,
+# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+
+use Modern::Perl;
+use List::Util qw/any/;
+
+use Koha::Database;
+use Koha::Exceptions;
+
+use base qw(Koha::Object);
+
+=head1 NAME
+
+Koha::Account::DebitType - Koha Account debit type Object class
+
+=head1 API
+
+=head2 Class Methods
+
+=cut
+
+=head3 delete
+
+Overridden delete method to prevent system default deletions
+
+=cut
+
+sub delete {
+    my ($self) = @_;
+
+    Koha::Exceptions::CannotDeleteDefault->throw if $self->is_system;
+
+    return $self->SUPER::delete;
+}
+
+=head3 type
+
+=cut
+
+sub _type {
+    return 'AccountDebitType';
+}
+
+1;
diff --git a/Koha/Account/DebitTypes.pm b/Koha/Account/DebitTypes.pm
new file mode 100644 (file)
index 0000000..2e6eb2c
--- /dev/null
@@ -0,0 +1,70 @@
+package Koha::Account::DebitTypes;
+
+# Copyright PTFS Europe 2019
+#
+# This file is part of Koha.
+#
+# Koha is free software; you can redistribute it and/or modify it under the
+# terms of the GNU General Public License as published by the Free Software
+# Foundation; either version 3 of the License, or (at your option) any later
+# version.
+#
+# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
+# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License along
+# with Koha; if not, write to the Free Software Foundation, Inc.,
+# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+
+use Modern::Perl;
+use List::Util qw/any/;
+
+use Koha::Database;
+
+use base qw(Koha::Objects);
+
+=head1 NAME
+
+Koha::Account::DebitTypes - Koha Account debit types Object set class
+
+=head1 API
+
+=head2 Class Methods
+
+=head3 delete
+
+Overridden delete method to prevent system default deletions
+
+=cut
+
+sub delete {
+    my ($self) = @_;
+
+    my @set = $self->as_list;
+    for my $type (@set) {
+        if ( $type->is_system ) {
+            Koha::Exceptions::CannotDeleteDefault->throw;
+        }
+    }
+
+    return $self->SUPER::delete;
+}
+
+=head3 type
+
+=cut
+
+sub _type {
+    return 'AccountDebitType';
+}
+
+=head3 object_class
+
+=cut
+
+sub object_class {
+    return 'Koha::Account::DebitType';
+}
+
+1;
index c2ae858..5082443 100644 (file)
@@ -69,6 +69,13 @@ __PACKAGE__->table("accountlines");
   is_nullable: 1
   size: 80
 
+=head2 debit_type
+
+  data_type: 'varchar'
+  is_foreign_key: 1
+  is_nullable: 1
+  size: 16
+
 =head2 status
 
   data_type: 'varchar'
@@ -143,6 +150,8 @@ __PACKAGE__->add_columns(
   { data_type => "longtext", is_nullable => 1 },
   "accounttype",
   { data_type => "varchar", is_nullable => 1, size => 80 },
+  "debit_type",
+  { data_type => "varchar", is_foreign_key => 1, is_nullable => 1, size => 16 },
   "status",
   { data_type => "varchar", is_nullable => 1, size => 16 },
   "payment_type",
@@ -252,6 +261,26 @@ __PACKAGE__->belongs_to(
   },
 );
 
+=head2 debit_type
+
+Type: belongs_to
+
+Related object: L<Koha::Schema::Result::AccountDebitType>
+
+=cut
+
+__PACKAGE__->belongs_to(
+  "debit_type",
+  "Koha::Schema::Result::AccountDebitType",
+  { code => "debit_type" },
+  {
+    is_deferrable => 1,
+    join_type     => "LEFT",
+    on_delete     => "SET NULL",
+    on_update     => "CASCADE",
+  },
+);
+
 =head2 itemnumber
 
 Type: belongs_to
@@ -313,8 +342,8 @@ __PACKAGE__->belongs_to(
 );
 
 
-# Created by DBIx::Class::Schema::Loader v0.07046 @ 2019-09-23 10:45:21
-# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:L+QlTTT+MdGoA3shpyaBgQ
+# Created by DBIx::Class::Schema::Loader v0.07046 @ 2019-10-11 10:47:58
+# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:RKg4gDSu0WwJ1C9YmDv3pw
 
 sub koha_objects_class {
     'Koha::Account::Lines';
index 6191b31..fa9679e 100644 (file)
@@ -211,6 +211,21 @@ __PACKAGE__->set_primary_key("branchcode");
 
 =head1 RELATIONS
 
+=head2 ac_debit_types_branches
+
+Type: has_many
+
+Related object: L<Koha::Schema::Result::AcDebitTypesBranch>
+
+=cut
+
+__PACKAGE__->has_many(
+  "ac_debit_types_branches",
+  "Koha::Schema::Result::AcDebitTypesBranch",
+  { "foreign.branchcode" => "self.branchcode" },
+  { cascade_copy => 0, cascade_delete => 0 },
+);
+
 =head2 accountlines
 
 Type: has_many
@@ -677,8 +692,8 @@ __PACKAGE__->has_many(
 );
 
 
-# Created by DBIx::Class::Schema::Loader v0.07046 @ 2019-09-23 10:45:22
-# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:KDg4i49bpMxXQ1LP6OZFWQ
+# Created by DBIx::Class::Schema::Loader v0.07046 @ 2019-09-26 15:59:23
+# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:IiEBfDpMBAi9cv7OqevVRQ
 
 __PACKAGE__->add_columns(
     '+pickup_location' => { is_boolean => 1 }
diff --git a/installer/data/mysql/account_debit_types.sql b/installer/data/mysql/account_debit_types.sql
new file mode 100644 (file)
index 0000000..db76963
--- /dev/null
@@ -0,0 +1,14 @@
+INSERT INTO account_debit_types ( code, description, can_be_added_manually, default_amount, is_system ) VALUES
+('ACCOUNT', 'Account creation fee', 0, NULL, 1),
+('ACCOUNT_RENEW', 'Account renewal fee', 0, NULL, 1),
+('HE', 'Hold waiting too long', 0, NULL, 1),
+('LOST', 'Lost item', 1, NULL, 1),
+('M', 'Manual fee', 1, NULL, 0),
+('N', 'New card fee', 1, NULL, 1),
+('OVERDUE', 'Overdue fine', 0, NULL, 1),
+('PF', 'Lost item processing fee', 0, NULL, 1),
+('RENT', 'Rental fee', 0, NULL, 1),
+('RENT_DAILY', 'Daily rental fee', 0, NULL, 1),
+('RENT_RENEW', 'Renewal of rental item', 0, NULL, 1),
+('RENT_DAILY_RENEW', 'Rewewal of daily rental item', 0, NULL, 1),
+('Res', 'Hold fee', 0, NULL, 1);
diff --git a/installer/data/mysql/atomicupdate/bug_23049_debit.perl b/installer/data/mysql/atomicupdate/bug_23049_debit.perl
new file mode 100644 (file)
index 0000000..f5fa7c2
--- /dev/null
@@ -0,0 +1,125 @@
+$DBversion = 'XXX';    # will be replaced by the RM
+if ( CheckVersion($DBversion) ) {
+
+    $dbh->do(
+        qq{
+            CREATE TABLE IF NOT EXISTS account_debit_types (
+              code varchar(64) NOT NULL,
+              description varchar(200) NULL,
+              can_be_added_manually tinyint(4) NOT NULL DEFAULT 1,
+              default_amount decimal(28, 6) NULL,
+              is_system tinyint(1) NOT NULL DEFAULT 0,
+              PRIMARY KEY (code)
+            ) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4 COLLATE = utf8mb4_unicode_ci
+          }
+    );
+
+    $dbh->do(
+        qq{
+            CREATE TABLE IF NOT EXISTS ac_debit_types_branches (
+                debit_type_code VARCHAR(64),
+                branchcode VARCHAR(10),
+                FOREIGN KEY (debit_type_code) REFERENCES account_debit_types(code) ON DELETE CASCADE,
+                FOREIGN KEY (branchcode) REFERENCES branches(branchcode) ON DELETE CASCADE
+            ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci
+        }
+    );
+
+    $dbh->do(
+        qq{
+            INSERT IGNORE INTO account_debit_types (
+              code,
+              description,
+              can_be_added_manually,
+              default_amount,
+              is_system
+            )
+            VALUES
+              ('ACCOUNT', 'Account creation fee', 0, NULL, 1),
+              ('ACCOUNT_RENEW', 'Account renewal fee', 0, NULL, 1),
+              ('HE', 'Hold waiting too long', 0, NULL, 1),
+              ('LOST', 'Lost item', 1, NULL, 1),
+              ('M', 'Manual fee', 1, NULL, 0),
+              ('N', 'New card fee', 1, NULL, 1),
+              ('OVERDUE', 'Overdue fine', 0, NULL, 1),
+              ('PF', 'Lost item processing fee', 0, NULL, 1),
+              ('RENT', 'Rental fee', 0, NULL, 1),
+              ('RENT_DAILY', 'Daily rental fee', 0, NULL, 1),
+              ('RENT_RENEW', 'Renewal of rental item', 0, NULL, 1),
+              ('RENT_DAILY_RENEW', 'Rewewal of daily rental item', 0, NULL, 1),
+              ('Res', 'Hold fee', 0, NULL, 1)
+        }
+    );
+
+    $dbh->do(
+        qq{
+            INSERT IGNORE INTO account_debit_types (
+              code,
+              default_amount,
+              description,
+              can_be_added_manually,
+              is_system
+            )
+            SELECT
+              SUBSTR(authorised_value, 1, 64),
+              lib,
+              authorised_value,
+              1,
+              0
+            FROM
+              authorised_values
+            WHERE
+              category = 'MANUAL_INV'
+          }
+    );
+
+    $dbh->do(
+        qq{
+            ALTER IGNORE TABLE accountlines
+            ADD
+              debit_type varchar(64) DEFAULT NULL
+            AFTER
+              accounttype
+          }
+    );
+
+    $dbh->do(
+        qq{
+        ALTER TABLE accountlines ADD CONSTRAINT `accountlines_ibfk_debit_type` FOREIGN KEY (`debit_type`) REFERENCES `account_debit_types` (`code`) ON DELETE SET NULL ON UPDATE CASCADE
+          }
+    );
+
+    $dbh->do(
+        qq{
+        UPDATE accountlines SET debit_type = accounttype, accounttype = NULL WHERE accounttype IN (SELECT code from account_debit_types)
+        }
+    );
+
+    # Clean up MANUAL_INV
+    $dbh->do(
+        qq{
+        DELETE FROM authorised_values WHERE category = 'MANUAL_INV'
+        }
+    );
+    $dbh->do(
+        qq{
+        DELETE FROM authorised_value_categories WHERE category_name = 'MANUAL_INV'
+        }
+    );
+
+    # Add new permission
+    $dbh->do(
+        q{
+            INSERT IGNORE INTO permissions (module_bit, code, description)
+            VALUES
+              (
+                3,
+                'manage_accounts',
+                'Manage Account Debit and Credit Types'
+              )
+        }
+    );
+
+    SetVersion($DBversion);
+    print "Upgrade to $DBversion done (Bug 23049 - Add account debit_types)\n";
+}
diff --git a/installer/data/mysql/en/mandatory/account_debit_types.sql b/installer/data/mysql/en/mandatory/account_debit_types.sql
new file mode 100644 (file)
index 0000000..db76963
--- /dev/null
@@ -0,0 +1,14 @@
+INSERT INTO account_debit_types ( code, description, can_be_added_manually, default_amount, is_system ) VALUES
+('ACCOUNT', 'Account creation fee', 0, NULL, 1),
+('ACCOUNT_RENEW', 'Account renewal fee', 0, NULL, 1),
+('HE', 'Hold waiting too long', 0, NULL, 1),
+('LOST', 'Lost item', 1, NULL, 1),
+('M', 'Manual fee', 1, NULL, 0),
+('N', 'New card fee', 1, NULL, 1),
+('OVERDUE', 'Overdue fine', 0, NULL, 1),
+('PF', 'Lost item processing fee', 0, NULL, 1),
+('RENT', 'Rental fee', 0, NULL, 1),
+('RENT_DAILY', 'Daily rental fee', 0, NULL, 1),
+('RENT_RENEW', 'Renewal of rental item', 0, NULL, 1),
+('RENT_DAILY_RENEW', 'Rewewal of daily rental item', 0, NULL, 1),
+('Res', 'Hold fee', 0, NULL, 1);
index 24f036b..b4e00fd 100644 (file)
@@ -48,9 +48,6 @@ INSERT INTO `authorised_values` (category, authorised_value, lib) VALUES ('NOT_L
 -- restricted status of an item, linked to items.restricted
 INSERT INTO `authorised_values` (category, authorised_value, lib) VALUES ('RESTRICTED','1','Restricted Access');
 
--- manual invoice types
-INSERT INTO `authorised_values` (category, authorised_value, lib) VALUES ('MANUAL_INV','Copier Fees','.25');
-
 -- custom borrower notes
 INSERT INTO `authorised_values` (category, authorised_value, lib) VALUES ('BOR_NOTES','ADDR','Address Notes');
 
index 7073c9a..87d219a 100644 (file)
@@ -2622,6 +2622,32 @@ CREATE TABLE `cash_registers` (
 ) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4 COLLATE = utf8mb4_unicode_ci;
 
 --
+-- Table structure for table `account_debit_types`
+--
+
+DROP TABLE IF EXISTS `account_debit_types`;
+CREATE TABLE `account_debit_types` (
+  `code` varchar(64) NOT NULL,
+  `description` varchar(200) DEFAULT NULL,
+  `can_be_added_manually` tinyint(4) NOT NULL DEFAULT 1,
+  `default_amount` decimal(28,6) DEFAULT NULL,
+  `is_system` tinyint(1) NOT NULL DEFAULT 0,
+  PRIMARY KEY (`code`)
+) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
+
+--
+-- Table structure for table `ac_debit_types_branches`
+--
+
+DROP TABLE IF EXISTS `ac_debit_types_branches`;
+CREATE TABLE `ac_debit_types_branches` (
+    `debit_type_code` VARCHAR(64),
+    `branchcode` VARCHAR(10),
+    FOREIGN KEY (`debit_type_code`) REFERENCES `account_debit_types` (`code`) ON DELETE CASCADE,
+    FOREIGN KEY (`branchcode`) REFERENCES `branches` (`branchcode`) ON DELETE CASCADE
+) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
+
+--
 -- Table structure for table `accountlines`
 --
 
@@ -2635,6 +2661,7 @@ CREATE TABLE `accountlines` (
   `amount` decimal(28,6) default NULL,
   `description` LONGTEXT,
   `accounttype` varchar(80) default NULL,
+  `debit_type` varchar(64) default NULL,
   `status` varchar(16) default NULL,
   `payment_type` varchar(80) default NULL, -- optional authorised value PAYMENT_TYPE
   `amountoutstanding` decimal(28,6) default NULL,
@@ -2647,6 +2674,7 @@ CREATE TABLE `accountlines` (
   PRIMARY KEY (`accountlines_id`),
   KEY `acctsborridx` (`borrowernumber`),
   KEY `timeidx` (`timestamp`),
+  KEY `debit_type` (`debit_type`),
   KEY `itemnumber` (`itemnumber`),
   KEY `branchcode` (`branchcode`),
   KEY `manager_id` (`manager_id`),
@@ -2654,7 +2682,8 @@ CREATE TABLE `accountlines` (
   CONSTRAINT `accountlines_ibfk_items` FOREIGN KEY (`itemnumber`) REFERENCES `items` (`itemnumber`) ON DELETE SET NULL ON UPDATE CASCADE,
   CONSTRAINT `accountlines_ibfk_borrowers_2` FOREIGN KEY (`manager_id`) REFERENCES `borrowers` (`borrowernumber`) ON DELETE SET NULL ON UPDATE CASCADE,
   CONSTRAINT `accountlines_ibfk_branches` FOREIGN KEY (`branchcode`) REFERENCES `branches` (`branchcode`) ON DELETE SET NULL ON UPDATE CASCADE,
-  CONSTRAINT `accountlines_ibfk_registers` FOREIGN KEY (`register_id`) REFERENCES `cash_registers` (`id`) ON DELETE SET NULL ON UPDATE CASCADE
+  CONSTRAINT `accountlines_ibfk_registers` FOREIGN KEY (`register_id`) REFERENCES `cash_registers` (`id`) ON DELETE SET NULL ON UPDATE CASCADE,
+  CONSTRAINT `accountlines_ibfk_debit_type` FOREIGN KEY (`debit_type`) REFERENCES `account_debit_types` (`code`) ON DELETE SET NULL ON UPDATE CASCADE
 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
 
 --
index 70e7d19..f39bf93 100644 (file)
@@ -32,7 +32,6 @@ INSERT IGNORE INTO authorised_value_categories( category_name )
     ('NOT_LOAN'),
     ('CCODE'),
     ('LOC'),
-    ('MANUAL_INV'),
     ('BOR_NOTES'),
     ('OPAC_SUG'),
     ('SIP_MEDIA_TYPE'),
index 7715e0b..0c8e1fc 100644 (file)
             <p>Shelving location (usually appears when adding or editing an item). LOC maps to items.location in the Koha database.</p>
         [% CASE 'LOST' %]
             <p>Descriptions for the items marked as lost (appears when adding or editing an item)</p>
-        [% CASE 'MANUAL_INV' %]
-            <p>Values for manual invoicing types</p>
         [% CASE 'NOT_LOAN' %]
             <p>Reasons why a title is not for loan</p>
         [% CASE 'OPAC_SUG' %]
index 9f7c0dc..3c24d51 100644 (file)
@@ -352,7 +352,7 @@ Circulation:
               choices:
                   yes: Include
                   no: "Don't include"
-            - MANUAL_INV charges when summing up charges for noissuescharge.
+            - custom debit type charges when summing up charges for noissuescharge.
         -
             - pref: HoldsInNoissuesCharge
               choices:
index f2cb974..341c530 100755 (executable)
@@ -108,6 +108,7 @@ my @sample_files_mandatory = (
     "$data_dir/userflags.sql",
     "$data_dir/userpermissions.sql",
     "$data_dir/account_offset_types.sql",
+    "$data_dir/account_debit_types.sql",
 );
 my @sample_lang_files_mandatory    = ( glob $root . "/installer/data/mysql/$lang/mandatory/*.sql" );
 my @sample_lang_files_optional     = ( glob $root . "/installer/data/mysql/$lang/optional/*.sql" );
index 4a45063..d6fd475 100644 (file)
@@ -786,23 +786,23 @@ subtest "Koha::Account::non_issues_charges tests" => sub {
             interface   => 'commandline'
         }
     );
+    Koha::Account::DebitTypes->new(
+        {
+            code        => 'Copie',
+            description => 'Fee for copie',
+            is_system   => 0
+        }
+    )->store;
     Koha::Account::Line->new(
         {
             borrowernumber    => $patron->borrowernumber,
             date              => $today,
             description       => 'a Manual invoice fee',
-            accounttype       => 'Copie',
+            debit_type        => 'Copie',
             amountoutstanding => $manual,
             interface         => 'commandline'
         }
     )->store;
-    Koha::AuthorisedValue->new(
-        {
-            category         => 'MANUAL_INV',
-            authorised_value => 'Copie',
-            lib              => 'Fee for copie',
-        }
-    )->store;
 
 
     t::lib::Mocks::mock_preference( 'HoldsInNoissuesCharge',   0 );