From 7c520100b4d38bfcb40b0beac04d7a7c020efe48 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Thu, 29 Oct 2015 15:31:39 +0000 Subject: [PATCH] Bug 15084: Make sure the previous active currency is marked as inactive On inserting an active currency, others should be marked as inactive. We can only have 1 active currency at the same time. --- Koha/Acquisition/Currency.pm | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/Koha/Acquisition/Currency.pm b/Koha/Acquisition/Currency.pm index dd34cc2..da0bcd2 100644 --- a/Koha/Acquisition/Currency.pm +++ b/Koha/Acquisition/Currency.pm @@ -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 -- 2.1.0