Bug 15084: Make sure the previous active currency is marked as inactive
authorJonathan Druart <jonathan.druart@bugs.koha-community.org>
Thu, 29 Oct 2015 15:31:39 +0000 (15:31 +0000)
committerBrendan A Gallagher <brendan@bywatersolutions.com>
Thu, 3 Mar 2016 20:39:00 +0000 (20:39 +0000)
On inserting an active currency, others should be marked as inactive.
We can only have 1 active currency at the same time.

Signed-off-by: Josef Moravec <josef.moravec@gmail.com>
Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Signed-off-by: Brendan A Gallagher <brendan@bywatersolutions.com>
Koha/Acquisition/Currency.pm

index dd34cc2..da0bcd2 100644 (file)
@@ -33,6 +33,26 @@ Koha::Acquisition::Currency - Koha Acquisition Currency Object class
 
 =cut
 
+=head3 store
+
+=cut
+
+sub store {
+    my ( $self ) = @_;
+    my $result;
+    $self->_result->result_source->schema->txn_do( sub {
+        if ( $self->active ) {
+            my @currencies = Koha::Acquisition::Currencies->search;
+            for my $currency ( @currencies ) {
+                $currency->active(0);
+                $currency->store;
+            }
+        }
+        $result = $self->SUPER::store;
+    });
+    return $result;
+}
+
 =head3 type
 
 =cut