From 2fb76ca759582aeabab8c69602aa7409935a158d Mon Sep 17 00:00:00 2001 From: titima15 Date: Tue, 10 Oct 2023 11:12:23 -0400 Subject: [PATCH 1/8] fixed transcription description --- lib/SGN/Controller/AJAX/Seedlot.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/SGN/Controller/AJAX/Seedlot.pm b/lib/SGN/Controller/AJAX/Seedlot.pm index 68aa650f75..4e5b4b89c7 100644 --- a/lib/SGN/Controller/AJAX/Seedlot.pm +++ b/lib/SGN/Controller/AJAX/Seedlot.pm @@ -1129,7 +1129,7 @@ sub add_seedlot_transaction :Chained('seedlot_base') :PathPart('transaction/add' my $amount = $c->req->param("amount"); my $weight = $c->req->param("weight"); my $timestamp = $c->req->param("timestamp"); - my $description = $c->req->param("description"); + my $description = $c->req->param("transaction_description"); my $factor = $c->req->param("factor"); my $transaction = CXGN::Stock::Seedlot::Transaction->new(schema => $c->stash->{schema}); $transaction->factor($factor); From 6d890df23bc86010d54289cc161664a93a6c5096 Mon Sep 17 00:00:00 2001 From: titima15 Date: Tue, 10 Oct 2023 14:44:07 -0400 Subject: [PATCH 2/8] added factor for transaction obj --- lib/CXGN/Stock/Seedlot/Transaction.pm | 38 +++++++++++++--------- lib/SGN/Controller/AJAX/Seedlot.pm | 15 +++++++-- mason/breeders_toolbox/seedlot_details.mas | 2 +- 3 files changed, 37 insertions(+), 18 deletions(-) diff --git a/lib/CXGN/Stock/Seedlot/Transaction.pm b/lib/CXGN/Stock/Seedlot/Transaction.pm index 3f87a1b455..2b3f8d2b3b 100644 --- a/lib/CXGN/Stock/Seedlot/Transaction.pm +++ b/lib/CXGN/Stock/Seedlot/Transaction.pm @@ -51,9 +51,15 @@ has 'description' => ( isa => 'Maybe[Str]', is => 'rw', ); -sub BUILD { - my $self = shift; +has 'seedlot_id' => ( + isa => 'Int', + is => 'rw', +); + +sub BUILD { + my $self = shift; + my $seedlot_id = $self->seedlot_id(); if ($self->transaction_id()) { my $row = $self->schema()->resultset("Stock::StockRelationship")->find( { stock_relationship_id => $self->transaction_id() }, { join => ['subject', 'object'], '+select' => ['subject.uniquename', 'subject.type_id', 'object.uniquename', 'object.type_id'], '+as' => ['subject_uniquename', 'subject_type_id', 'object_uniquename', 'object_type_id'] } ); @@ -69,11 +75,16 @@ sub BUILD { $self->timestamp($data->{timestamp}); $self->operator($data->{operator}); $self->description($data->{description}); + if ($row->subject_id == $seedlot_id){ + $self->factor(1); + } elsif ($row->object_id == $seedlot_id){ + $self->factor(-1); + } } } # class method -sub get_transactions_by_seedlot_id { +sub get_transactions_by_seedlot_id { my $class = shift; my $schema = shift; my $seedlot_id = shift; @@ -81,7 +92,7 @@ sub get_transactions_by_seedlot_id { print STDERR "Get transactions by seedlot...$seedlot_id\n"; my $type_id = SGN::Model::Cvterm->get_cvterm_row($schema, "seed transaction", "stock_relationship")->cvterm_id(); my $rs = $schema->resultset("Stock::StockRelationship")->search( - { '-or' => + { '-or' => [ subject_id => $seedlot_id, object_id => $seedlot_id @@ -133,7 +144,7 @@ sub get_transactions_by_seedlot_id { return \@transactions; } -sub get_transactions { +sub get_transactions { my $class = shift; my $schema = shift; my $seedlot_id = shift; @@ -163,14 +174,14 @@ sub get_transactions { } } } - + if (@ids){ $filter{"-or"} = [ subject_id => { -in => \@ids }, object_id => { -in => \@ids }, ]; } - + my $type_id = SGN::Model::Cvterm->get_cvterm_row($schema, "seed transaction", "stock_relationship")->cvterm_id(); $filter{'me.type_id'} = { '-in' => $type_id }; @@ -215,8 +226,8 @@ sub get_transactions { return \@transactions, $total_count; } -sub store { - my $self = shift; +sub store { + my $self = shift; my $transaction_type_id = SGN::Model::Cvterm->get_cvterm_row($self->schema(), "seed transaction", "stock_relationship")->cvterm_id(); my $amount = defined($self->amount()) ? $self->amount() : 'NA'; @@ -245,7 +256,7 @@ sub store { }, {order_by => { -desc => 'rank'} }); my $new_rank = 0; - if ($row_rs->first) { + if ($row_rs->first) { $new_rank = $row_rs->first->rank()+1; } #print STDERR Dumper $new_rank; @@ -261,7 +272,7 @@ sub store { return $row->stock_relationship_id(); } - else { + else { my $row = $self->schema()->resultset("Stock::StockRelationship")->find({ stock_relationship_id => $self->transaction_id }); $row->update({ value => $json_value @@ -291,11 +302,8 @@ sub update_transaction_object_id { } sub delete { - + } 1; - - - diff --git a/lib/SGN/Controller/AJAX/Seedlot.pm b/lib/SGN/Controller/AJAX/Seedlot.pm index 4e5b4b89c7..9ce5f3569b 100644 --- a/lib/SGN/Controller/AJAX/Seedlot.pm +++ b/lib/SGN/Controller/AJAX/Seedlot.pm @@ -880,8 +880,9 @@ sub seedlot_transaction_base :Chained('seedlot_base') PathPart('transaction') Ca my $self = shift; my $c = shift; my $schema = $c->dbic_schema("Bio::Chado::Schema"); + my $seedlot_id = $c->stash->{seedlot}->seedlot_id(); my $transaction_id = shift; - my $t_obj = CXGN::Stock::Seedlot::Transaction->new(schema=>$schema, transaction_id=>$transaction_id); + my $t_obj = CXGN::Stock::Seedlot::Transaction->new(schema=>$schema, transaction_id=>$transaction_id, seedlot_id=>$seedlot_id); $c->stash->{transaction_id} = $transaction_id; $c->stash->{transaction_object} = $t_obj; } @@ -890,6 +891,14 @@ sub seedlot_transaction_details :Chained('seedlot_transaction_base') PathPart('' my $self = shift; my $c = shift; my $t = $c->stash->{transaction_object}; + my $factor = $t->factor; + my $action; + if ($factor == 1) { + $action = 'add'; + } elsif ($factor == -1) { + $action = 'remove'; + } + $c->stash->{rest} = { success => 1, transaction_id => $t->transaction_id, @@ -897,7 +906,9 @@ sub seedlot_transaction_details :Chained('seedlot_transaction_base') PathPart('' amount=>$t->amount, weight_gram=>$t->weight_gram, operator=>$t->operator, - timestamp=>$t->timestamp + timestamp=>$t->timestamp, + factor=>$t->factor, + action=>$action }; } diff --git a/mason/breeders_toolbox/seedlot_details.mas b/mason/breeders_toolbox/seedlot_details.mas index 7a4b56ff1e..d5e4e47d2b 100644 --- a/mason/breeders_toolbox/seedlot_details.mas +++ b/mason/breeders_toolbox/seedlot_details.mas @@ -743,7 +743,7 @@ function editSeedlotTransaction(transaction_id){ success: function(response) { jQuery('#working_modal').modal('hide'); if (response.success == 1) { - html = '
'; + html = '
'; jQuery('#edit_seedlot_transaction_div').html(html); jQuery('#edit_seedlot_transaction_dialog').modal('show'); } From 896fc7a88729d6a7ddf192474c5b2de3721e60f4 Mon Sep 17 00:00:00 2001 From: titima15 Date: Tue, 10 Oct 2023 17:27:24 -0400 Subject: [PATCH 3/8] update current count for both from_stock and to_stock seedlots --- lib/SGN/Controller/AJAX/Seedlot.pm | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/lib/SGN/Controller/AJAX/Seedlot.pm b/lib/SGN/Controller/AJAX/Seedlot.pm index 9ce5f3569b..8dd1b84255 100644 --- a/lib/SGN/Controller/AJAX/Seedlot.pm +++ b/lib/SGN/Controller/AJAX/Seedlot.pm @@ -915,6 +915,7 @@ sub seedlot_transaction_details :Chained('seedlot_transaction_base') PathPart('' sub edit_seedlot_transaction :Chained('seedlot_transaction_base') PathPart('edit') Args(0) { my $self = shift; my $c = shift; + my $schema = $c->dbic_schema("Bio::Chado::Schema"); if (!$c->user()){ $c->stash->{rest} = { error => "You must be logged in to edit seedlot transactions" }; @@ -926,6 +927,13 @@ sub edit_seedlot_transaction :Chained('seedlot_transaction_base') PathPart('edit } my $t = $c->stash->{transaction_object}; + my $from_stock = $t->from_stock(); + my $from_stock_id = $from_stock->[0]; + my $from_stock_type = $from_stock->[2]; + my $to_stock = $t->to_stock(); + my $to_stock_id = $to_stock->[0]; + my $to_stock_type = $to_stock->[2]; + my $edit_operator = $c->req->param('operator'); my $edit_amount = $c->req->param('amount'); my $edit_weight = $c->req->param('weight_gram'); @@ -937,8 +945,21 @@ sub edit_seedlot_transaction :Chained('seedlot_transaction_base') PathPart('edit $t->description($edit_desc); $t->timestamp($edit_timestamp); my $transaction_id = $t->store(); - $c->stash->{seedlot}->set_current_count_property(); - $c->stash->{seedlot}->set_current_weight_property(); + + my $seedlot_cvterm_id = SGN::Model::Cvterm->get_cvterm_row($schema, 'seedlot', 'stock_type')->cvterm_id(); + + if ($from_stock_type == $seedlot_cvterm_id) { + my $from_stock_update = CXGN::Stock::Seedlot->new(schema => $schema, seedlot_id => $from_stock_id); + $from_stock_update->set_current_count_property(); + $from_stock_update->set_current_weight_property(); + } + + if ($to_stock_type == $seedlot_cvterm_id) { + my $to_stock_update = CXGN::Stock::Seedlot->new(schema => $schema, seedlot_id => $to_stock_id); + $to_stock_update->set_current_count_property(); + $to_stock_update->set_current_weight_property(); + } + if ($transaction_id){ my $dbh = $c->dbc->dbh(); my $bs = CXGN::BreederSearch->new( { dbh=>$dbh, dbname=>$c->config->{dbname}, } ); From 53d1a26ecb9715b5813edb33d427415eb6fd810d Mon Sep 17 00:00:00 2001 From: titima15 Date: Tue, 10 Oct 2023 17:34:27 -0400 Subject: [PATCH 4/8] hide dialog after success response --- mason/breeders_toolbox/seedlot_details.mas | 1 + 1 file changed, 1 insertion(+) diff --git a/mason/breeders_toolbox/seedlot_details.mas b/mason/breeders_toolbox/seedlot_details.mas index d5e4e47d2b..4c2f6f4dde 100644 --- a/mason/breeders_toolbox/seedlot_details.mas +++ b/mason/breeders_toolbox/seedlot_details.mas @@ -654,6 +654,7 @@ $maintenance_enabled => undef success: function(response) { jQuery('#working_modal').modal('hide'); if (response.success == 1) { + jQuery('#edit_seedlot_transaction_dialog').modal('hide'); alert('Transaction updated!'); seedlot_transactions_table.ajax.reload(); } From 6013ea22b5ef92c77701055e0680d37cb9e690cf Mon Sep 17 00:00:00 2001 From: titima15 Date: Wed, 11 Oct 2023 09:20:17 -0400 Subject: [PATCH 5/8] modified transaction type --- lib/SGN/Controller/AJAX/Seedlot.pm | 8 ++++---- mason/breeders_toolbox/seedlot_details.mas | 6 +++--- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/SGN/Controller/AJAX/Seedlot.pm b/lib/SGN/Controller/AJAX/Seedlot.pm index 8dd1b84255..5e594d6b82 100644 --- a/lib/SGN/Controller/AJAX/Seedlot.pm +++ b/lib/SGN/Controller/AJAX/Seedlot.pm @@ -892,11 +892,11 @@ sub seedlot_transaction_details :Chained('seedlot_transaction_base') PathPart('' my $c = shift; my $t = $c->stash->{transaction_object}; my $factor = $t->factor; - my $action; + my $transaction_type; if ($factor == 1) { - $action = 'add'; + $transaction_type = 'added to this seedlot'; } elsif ($factor == -1) { - $action = 'remove'; + $transaction_type = 'removed from this seedlot'; } $c->stash->{rest} = { @@ -908,7 +908,7 @@ sub seedlot_transaction_details :Chained('seedlot_transaction_base') PathPart('' operator=>$t->operator, timestamp=>$t->timestamp, factor=>$t->factor, - action=>$action + transaction_type=>$transaction_type }; } diff --git a/mason/breeders_toolbox/seedlot_details.mas b/mason/breeders_toolbox/seedlot_details.mas index 4c2f6f4dde..86d842f694 100644 --- a/mason/breeders_toolbox/seedlot_details.mas +++ b/mason/breeders_toolbox/seedlot_details.mas @@ -238,7 +238,7 @@ $maintenance_enabled => undef
- +
@@ -654,7 +654,7 @@ $maintenance_enabled => undef success: function(response) { jQuery('#working_modal').modal('hide'); if (response.success == 1) { - jQuery('#edit_seedlot_transaction_dialog').modal('hide'); + jQuery('#edit_seedlot_transaction_dialog').modal('hide'); alert('Transaction updated!'); seedlot_transactions_table.ajax.reload(); } @@ -744,7 +744,7 @@ function editSeedlotTransaction(transaction_id){ success: function(response) { jQuery('#working_modal').modal('hide'); if (response.success == 1) { - html = '
'; + html = '
'; jQuery('#edit_seedlot_transaction_div').html(html); jQuery('#edit_seedlot_transaction_dialog').modal('show'); } From c4535eacfa59c5c0fa5aceda434390350d22f0ad Mon Sep 17 00:00:00 2001 From: titima15 Date: Wed, 11 Oct 2023 10:19:11 -0400 Subject: [PATCH 6/8] added test --- .../CXGN/Stock/Seedlot/Transaction.t | 34 ++++++++++++++++--- 1 file changed, 29 insertions(+), 5 deletions(-) diff --git a/t/unit_fixture/CXGN/Stock/Seedlot/Transaction.t b/t/unit_fixture/CXGN/Stock/Seedlot/Transaction.t index aeb47c5f18..d03790dc56 100644 --- a/t/unit_fixture/CXGN/Stock/Seedlot/Transaction.t +++ b/t/unit_fixture/CXGN/Stock/Seedlot/Transaction.t @@ -51,7 +51,7 @@ $source_seedlot->organization_name('bti'); $source_seedlot->population_name('test seedlot pop'); $source_seedlot->breeding_program_id($seedlot_breeding_program_id); my $return = $source_seedlot->store(); -print STDERR Dumper $return; +#print STDERR Dumper $return; my $source_seedlot_id = $return->{seedlot_id}; print STDERR "Creating transaction 1...\n"; @@ -113,7 +113,7 @@ $trans2->timestamp(localtime); $trans2->description('Moving 7 seed from seedlot 2 to seedlot 1'); $trans2->operator('janedoe'); -$trans2->store(); +my $trans_id_2 =$trans2->store(); print STDERR "Creating transaction 3...\n"; my $trans3 = CXGN::Stock::Seedlot::Transaction->new( @@ -126,7 +126,7 @@ $trans3->description('Moving 3 seed from seedlot 1 to seedlot 2'); $trans3->operator('janedoe'); $trans3->amount(3); -$trans3->store(); +my $trans_id_3 = $trans3->store(); #checking seedlots after transaction my $source_seedlot_after_trans3 = CXGN::Stock::Seedlot->new( @@ -148,7 +148,7 @@ foreach my $t (@{$source_seedlot_after_trans3->transactions()}) { ok($t->transaction_id, "check transcation ids"); push @transactions, [ $t->from_stock()->[1], $t->to_stock()->[1], $t->factor()*$t->amount(), $t->operator, $t->description ]; } -print STDERR Dumper \@transactions; +#print STDERR Dumper \@transactions; is_deeply(\@transactions, [ [ 'test seedlot', @@ -192,7 +192,7 @@ foreach my $t (@{$dest_seedlot_after_trans3->transactions()}) { ok($t->transaction_id, "check transcation ids"); push @transactions2, [ $t->from_stock()->[1], $t->to_stock()->[1], $t->factor()*$t->amount(), $t->operator, $t->description ]; } -print STDERR Dumper \@transactions2; +#print STDERR Dumper \@transactions2; is_deeply(\@transactions2, [ [ 'test seedlot', @@ -217,4 +217,28 @@ is_deeply(\@transactions2, [ ] ], 'check transactions of dest_seedlot'); +#test editing transaction 3 from test seedlot page +my $edit_trans3 = CXGN::Stock::Seedlot::Transaction->new( + schema => $f->bcs_schema(), + transaction_id => $trans_id_3, + seedlot_id => $dest_seedlot_id +); +$edit_trans3->to_stock([$source_seedlot_id, $source_seedlot->uniquename, $seedlot_type_id]); +$edit_trans3->from_stock([$dest_seedlot_id, $dest_seedlot->uniquename, $seedlot_type_id]); +$edit_trans3->timestamp(localtime); +$edit_trans3->description('Moving 5 seed from seedlot 1 to seedlot 2'); +$edit_trans3->operator('janedoe'); +$edit_trans3->amount(5); + +my $edit_trans_id = $edit_trans3->store(); +is($edit_trans_id, $trans_id_3); + +my $test_seedlot_after_editing = CXGN::Stock::Seedlot->new( + schema => $schema, + seedlot_id => $dest_seedlot_id +); + +is($test_seedlot_after_editing->current_count, 7); + + done_testing(); From 6bbabaf39fbfb5f2e5f71ff0cb70d37b34b7a4c9 Mon Sep 17 00:00:00 2001 From: titima15 Date: Wed, 11 Oct 2023 10:33:25 -0400 Subject: [PATCH 7/8] added cloase buttons --- mason/breeders_toolbox/seedlot_details.mas | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/mason/breeders_toolbox/seedlot_details.mas b/mason/breeders_toolbox/seedlot_details.mas index 86d842f694..33fd7ddfb4 100644 --- a/mason/breeders_toolbox/seedlot_details.mas +++ b/mason/breeders_toolbox/seedlot_details.mas @@ -265,7 +265,8 @@ $maintenance_enabled => undef
@@ -285,6 +286,7 @@ $maintenance_enabled => undef @@ -390,6 +392,7 @@ $maintenance_enabled => undef From 1889979d5e2fd9916cb3bf28857031e2fe447c92 Mon Sep 17 00:00:00 2001 From: titima15 Date: Wed, 11 Oct 2023 10:54:47 -0400 Subject: [PATCH 8/8] added transaction saved dialog and reload page --- mason/breeders_toolbox/seedlot_details.mas | 30 ++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/mason/breeders_toolbox/seedlot_details.mas b/mason/breeders_toolbox/seedlot_details.mas index 33fd7ddfb4..021769e4c7 100644 --- a/mason/breeders_toolbox/seedlot_details.mas +++ b/mason/breeders_toolbox/seedlot_details.mas @@ -399,6 +399,28 @@ $maintenance_enabled => undef + +