From 83dc7bbfbe25bcbd2c7c631eee95554c7be1440c Mon Sep 17 00:00:00 2001 From: Chris Mytton Date: Wed, 24 Jul 2024 10:19:36 +0100 Subject: [PATCH] [Bexley] Check parent and child UPRN for missed collection reports Some parent properties have children with collections that can have their own missed reports associated with them, so we need to check both the parent and child's missed collection reports. --- perllib/FixMyStreet/Cobrand/Bexley/Waste.pm | 96 ++++++++++----------- t/app/controller/waste_bexley.t | 2 + 2 files changed, 50 insertions(+), 48 deletions(-) diff --git a/perllib/FixMyStreet/Cobrand/Bexley/Waste.pm b/perllib/FixMyStreet/Cobrand/Bexley/Waste.pm index c996d93cf0..08ed745717 100644 --- a/perllib/FixMyStreet/Cobrand/Bexley/Waste.pm +++ b/perllib/FixMyStreet/Cobrand/Bexley/Waste.pm @@ -437,57 +437,57 @@ sub _remove_service_if_assisted_exists { sub _missed_collection_reports { my ( $self, $property ) = @_; - # If property has parent, use that instead - my $uprn - = $property->{parent_property} - ? $property->{parent_property}{uprn} - : $property->{uprn}; - - my $worksheets = $self->whitespace->GetSiteWorksheets($uprn); + my @uprns = ($property->{uprn}); + push @uprns, $property->{parent_property}{uprn} if $property->{parent_property}; my %missed_collection_reports; - for my $ws (@$worksheets) { - next - unless $ws->{WorksheetStatusName} eq 'Open' - && $ws->{WorksheetSubject} =~ /^Missed/; - - # Check if it exists in our DB - my $external_id = 'Whitespace-' . $ws->{WorksheetID}; - my $report - = $self->problems->search( { external_id => $external_id } ) - ->first; - - next unless $report; - - # Skip if there is already a report stashed against the service item - # name - my $service_item_name - = $report->get_extra_field_value('service_item_name') // ''; - next if $missed_collection_reports{$service_item_name}; - - my $latest_comment - = $report->comments->search( - {}, - { order_by => { -desc => 'id' } }, - )->first; - - my $report_details = { - id => $report->id, - external_id => $report->external_id, - open => $report->is_open, - reported => ( - $ws->{WorksheetStartDate} eq WHITESPACE_UNDEF_DATE ? - '' : $ws->{WorksheetStartDate} - ), - will_be_completed => ( - $ws->{WorksheetEscallatedDate} eq WHITESPACE_UNDEF_DATE ? - '' : $ws->{WorksheetEscallatedDate} - ), - latest_comment => - ( $latest_comment ? $latest_comment->text : '' ), - }; - $missed_collection_reports{$service_item_name} = $report_details; + foreach my $uprn (@uprns) { + my $worksheets = $self->whitespace->GetSiteWorksheets($uprn); + + for my $ws (@$worksheets) { + next + unless $ws->{WorksheetStatusName} eq 'Open' + && $ws->{WorksheetSubject} =~ /^Missed/; + + # Check if it exists in our DB + my $external_id = 'Whitespace-' . $ws->{WorksheetID}; + my $report + = $self->problems->search( { external_id => $external_id } ) + ->first; + + next unless $report; + + # Skip if there is already a report stashed against the service item + # name + my $service_item_name + = $report->get_extra_field_value('service_item_name') // ''; + next if $missed_collection_reports{$service_item_name}; + + my $latest_comment + = $report->comments->search( + {}, + { order_by => { -desc => 'id' } }, + )->first; + + my $report_details = { + id => $report->id, + external_id => $report->external_id, + open => $report->is_open, + reported => ( + $ws->{WorksheetStartDate} eq WHITESPACE_UNDEF_DATE ? + '' : $ws->{WorksheetStartDate} + ), + will_be_completed => ( + $ws->{WorksheetEscallatedDate} eq WHITESPACE_UNDEF_DATE ? + '' : $ws->{WorksheetEscallatedDate} + ), + latest_comment => + ( $latest_comment ? $latest_comment->text : '' ), + }; + + $missed_collection_reports{$service_item_name} = $report_details; + } } return \%missed_collection_reports; diff --git a/t/app/controller/waste_bexley.t b/t/app/controller/waste_bexley.t index 4d12ff9a51..8f3f287ee5 100644 --- a/t/app/controller/waste_bexley.t +++ b/t/app/controller/waste_bexley.t @@ -357,6 +357,7 @@ FixMyStreet::override_config { reported => '', will_be_completed => '', latest_comment => '', + uprn => '10001', }, report_locked_out => 0, report_locked_out_reason => '', @@ -379,6 +380,7 @@ FixMyStreet::override_config { reported => '2024-03-31T01:00:00', will_be_completed => '2024-04-02T01:00:00', latest_comment => 'Preexisting comment', + uprn => '10001', }, report_locked_out => 0, report_locked_out_reason => '',