diff options
-rwxr-xr-x | bin/oxfordshire/send-rdi-emails | 1 | ||||
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Admin/ExorDefects.pm | 1 | ||||
-rw-r--r-- | perllib/FixMyStreet/Integrations/ExorRDI.pm | 28 | ||||
-rw-r--r-- | t/cobrand/oxfordshire.t | 33 | ||||
-rw-r--r-- | templates/web/base/report/_inspect.html | 1 | ||||
-rw-r--r-- | templates/web/oxfordshire/report/_inspect_extra_info.html | 8 |
6 files changed, 67 insertions, 5 deletions
diff --git a/bin/oxfordshire/send-rdi-emails b/bin/oxfordshire/send-rdi-emails index 9eff02715..ab58ff525 100755 --- a/bin/oxfordshire/send-rdi-emails +++ b/bin/oxfordshire/send-rdi-emails @@ -38,6 +38,7 @@ foreach my $inspector (@inspectors) { end_date => $end_date, inspection_date => $inspection_date, user => $inspector, + mark_as_processed => 1, }; my $rdi = FixMyStreet::Integrations::ExorRDI->new($params); try { diff --git a/perllib/FixMyStreet/App/Controller/Admin/ExorDefects.pm b/perllib/FixMyStreet/App/Controller/Admin/ExorDefects.pm index b03a2ab98..0fd9fe023 100644 --- a/perllib/FixMyStreet/App/Controller/Admin/ExorDefects.pm +++ b/perllib/FixMyStreet/App/Controller/Admin/ExorDefects.pm @@ -59,6 +59,7 @@ sub download : Path('download') : Args(0) { inspection_date => $start_date, end_date => $end_date + $one_day, user => $c->get_param('user_id'), + mark_as_processed => 0, }; my $rdi = FixMyStreet::Integrations::ExorRDI->new($params); diff --git a/perllib/FixMyStreet/Integrations/ExorRDI.pm b/perllib/FixMyStreet/Integrations/ExorRDI.pm index 4ce888cff..fc7e9d673 100644 --- a/perllib/FixMyStreet/Integrations/ExorRDI.pm +++ b/perllib/FixMyStreet/Integrations/ExorRDI.pm @@ -23,7 +23,7 @@ use Scalar::Util 'blessed'; use FixMyStreet::DB; use namespace::clean; -has [qw(start_date end_date inspection_date)] => ( +has [qw(start_date end_date inspection_date mark_as_processed)] => ( is => 'ro', required => 1, ); @@ -43,13 +43,23 @@ sub construct { my $cobrand = FixMyStreet::Cobrand->get_class_for_moniker('oxfordshire')->new; my $dtf = $cobrand->problems->result_source->storage->datetime_parser; + my $missed_cutoff = DateTime->now - DateTime::Duration->new( hours => 24 ); my %params = ( -and => [ state => [ 'action scheduled' ], external_id => { '!=' => undef }, - 'admin_log_entries.action' => 'inspected', - 'admin_log_entries.whenedited' => { '>=', $dtf->format_datetime($self->start_date) }, - 'admin_log_entries.whenedited' => { '<=', $dtf->format_datetime($self->end_date) }, + -or => [ + -and => [ + 'admin_log_entries.action' => 'inspected', + 'admin_log_entries.whenedited' => { '>=', $dtf->format_datetime($self->start_date) }, + 'admin_log_entries.whenedited' => { '<=', $dtf->format_datetime($self->end_date) }, + ], + -and => [ + extra => { -not_like => '%rdi_processed%' }, + 'admin_log_entries.action' => 'inspected', + 'admin_log_entries.whenedited' => { '<=', $dtf->format_datetime($missed_cutoff) }, + ] + ] ] ); @@ -198,6 +208,16 @@ sub construct { 0, 0, 0 # error counts, always zero ); + if ($self->mark_as_processed) { + # Mark all these problems are having been included in an RDI + my $now = DateTime->now->strftime( '%Y-%m-%d %H:%M' ); + $problems->reset; + while ( my $report = $problems->next ) { + $report->set_extra_metadata('rdi_processed' => $now); + $report->update; + } + } + # The RDI format is very weird CSV - each line must be wrapped in # double quotes. return join "", map { "\"$_\"\r\n" } @$body; diff --git a/t/cobrand/oxfordshire.t b/t/cobrand/oxfordshire.t index 90fa8ccbf..e6c16950c 100644 --- a/t/cobrand/oxfordshire.t +++ b/t/cobrand/oxfordshire.t @@ -1,3 +1,5 @@ +use FixMyStreet::Integrations::ExorRDI; + use FixMyStreet::TestMech; my $mech = FixMyStreet::TestMech->new; @@ -47,6 +49,8 @@ my $superuser = $mech->create_user_ok('superuser@example.com', name => 'Super Us my $inspector = $mech->create_user_ok('inspector@example.com', name => 'Inspector'); $inspector->user_body_permissions->create({ body => $oxon, permission_type => 'report_inspect' }); +my @problems = FixMyStreet::DB->resultset('Problem')->search({}, { rows => 3 })->all; + subtest 'Exor RDI download appears on Oxfordshire cobrand admin' => sub { FixMyStreet::override_config { ALLOWED_COBRANDS => [ { 'oxfordshire' => '.' } ], @@ -97,7 +101,6 @@ subtest 'Exor file looks okay' => sub { $dt2->set_extra_metadata(activity_code => 'S'); $dt2->set_extra_metadata(defect_code => 'ACC2'); $dt2->update; - my @problems = FixMyStreet::DB->resultset('Problem')->search({}, { rows => 3 })->all; my $i = 123; foreach my $problem (@problems) { $problem->update({ state => 'action scheduled', external_id => $i }); @@ -142,9 +145,37 @@ subtest 'Exor file looks okay' => sub { "P,0,999999" "X,3,3,3,3,0,0,0,3,0,3,0,0,0" EOF + foreach my $problem (@problems) { + $problem->discard_changes; + is $problem->get_extra_metadata('rdi_processed'), undef, "Problem was not logged as sent in RDI"; + } + } }; +subtest 'Reports are marked as inspected correctly' => sub { + FixMyStreet::override_config { + ALLOWED_COBRANDS => [ 'oxfordshire' ], + }, sub { + my $date = DateTime->new(year => 2017, month => 5, day => 5, hour => 12); + my $params = { + start_date => $date, + end_date => $date, + inspection_date => $date, + user => $inspector, + mark_as_processed => 1, + }; + my $rdi = FixMyStreet::Integrations::ExorRDI->new($params); + $rdi->construct; + + my $now = DateTime->now->strftime( '%Y-%m-%d %H:%M' ); + foreach my $problem (@problems) { + $problem->discard_changes; + is $problem->get_extra_metadata('rdi_processed'), $now, "Problem was logged as sent in RDI"; + } + }; +}; + subtest 'response times messages displayed' => sub { my $oxfordshire = $mech->create_body_ok( 2237, 'Oxfordshire County Council' diff --git a/templates/web/base/report/_inspect.html b/templates/web/base/report/_inspect.html index 59806dc66..561be30d1 100644 --- a/templates/web/base/report/_inspect.html +++ b/templates/web/base/report/_inspect.html @@ -171,6 +171,7 @@ [% ELSE %] <p>[% loc("<strong>Note:</strong> This report hasn't yet been sent onwards for action. Any changes made may not be passed on.") %]</p> [% END %] + [% TRY %][% INCLUDE 'report/_inspect_extra_info.html' %][% CATCH file %][% END %] [% END %] <p> diff --git a/templates/web/oxfordshire/report/_inspect_extra_info.html b/templates/web/oxfordshire/report/_inspect_extra_info.html new file mode 100644 index 000000000..6151d79ae --- /dev/null +++ b/templates/web/oxfordshire/report/_inspect_extra_info.html @@ -0,0 +1,8 @@ +<p><small> +RDI sent: +[% IF problem.get_extra_metadata('rdi_processed') %] + [% problem.get_extra_metadata('rdi_processed') %] +[% ELSE %] + <strong>not yet sent</strong> +[% END %] +</small></p> |