Skip to content

Commit

Permalink
[Bexley] Check parent and child UPRN for missed collection reports
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
chrismytton committed Jul 25, 2024
1 parent 8c6ac60 commit 83dc7bb
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 48 deletions.
96 changes: 48 additions & 48 deletions perllib/FixMyStreet/Cobrand/Bexley/Waste.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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});

Check warning on line 440 in perllib/FixMyStreet/Cobrand/Bexley/Waste.pm

View check run for this annotation

Codecov / codecov/patch

perllib/FixMyStreet/Cobrand/Bexley/Waste.pm#L440

Added line #L440 was not covered by tests
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);

Check warning on line 446 in perllib/FixMyStreet/Cobrand/Bexley/Waste.pm

View check run for this annotation

Codecov / codecov/patch

perllib/FixMyStreet/Cobrand/Bexley/Waste.pm#L445-L446

Added lines #L445 - L446 were not covered by tests

for my $ws (@$worksheets) {

Check warning on line 448 in perllib/FixMyStreet/Cobrand/Bexley/Waste.pm

View check run for this annotation

Codecov / codecov/patch

perllib/FixMyStreet/Cobrand/Bexley/Waste.pm#L448

Added line #L448 was not covered by tests
next
unless $ws->{WorksheetStatusName} eq 'Open'
&& $ws->{WorksheetSubject} =~ /^Missed/;

# Check if it exists in our DB
my $external_id = 'Whitespace-' . $ws->{WorksheetID};
my $report

Check warning on line 455 in perllib/FixMyStreet/Cobrand/Bexley/Waste.pm

View check run for this annotation

Codecov / codecov/patch

perllib/FixMyStreet/Cobrand/Bexley/Waste.pm#L454-L455

Added lines #L454 - L455 were not covered by tests
= $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

Check warning on line 463 in perllib/FixMyStreet/Cobrand/Bexley/Waste.pm

View check run for this annotation

Codecov / codecov/patch

perllib/FixMyStreet/Cobrand/Bexley/Waste.pm#L463

Added line #L463 was not covered by tests
= $report->get_extra_field_value('service_item_name') // '';
next if $missed_collection_reports{$service_item_name};

my $latest_comment

Check warning on line 467 in perllib/FixMyStreet/Cobrand/Bexley/Waste.pm

View check run for this annotation

Codecov / codecov/patch

perllib/FixMyStreet/Cobrand/Bexley/Waste.pm#L467

Added line #L467 was not covered by tests
= $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;

Check warning on line 489 in perllib/FixMyStreet/Cobrand/Bexley/Waste.pm

View check run for this annotation

Codecov / codecov/patch

perllib/FixMyStreet/Cobrand/Bexley/Waste.pm#L489

Added line #L489 was not covered by tests
}
}

return \%missed_collection_reports;
Expand Down
2 changes: 2 additions & 0 deletions t/app/controller/waste_bexley.t
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,7 @@ FixMyStreet::override_config {
reported => '',
will_be_completed => '',
latest_comment => '',
uprn => '10001',
},
report_locked_out => 0,
report_locked_out_reason => '',
Expand All @@ -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 => '',
Expand Down

0 comments on commit 83dc7bb

Please sign in to comment.