Skip to content

Commit

Permalink
[Brent] Apply discount to modifications as well.
Browse files Browse the repository at this point in the history
Use normal cost functions.
  • Loading branch information
dracos committed Oct 4, 2024
1 parent 47a4241 commit 1b6535b
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 18 deletions.
11 changes: 2 additions & 9 deletions perllib/FixMyStreet/Cobrand/Brent.pm
Original file line number Diff line number Diff line change
Expand Up @@ -1553,12 +1553,11 @@ sub garden_waste_sacks_cost_pa {

sub garden_waste_cost_pa {
my ($self, $bin_count) = @_;

$bin_count ||= 1;
my $per_bin_cost = $self->_get_cost('ggw_cost');
my $cost = $per_bin_cost * $bin_count;

my $cost = $self->feature('payment_gateway')->{ggw_cost} * $bin_count;
my $now = DateTime->now( time_zone => FixMyStreet->local_time_zone );

if ($now->month =~ /^(10|11|12)$/ ) {
$cost = $cost/2;
}
Expand Down Expand Up @@ -1595,12 +1594,6 @@ sub apply_garden_waste_discount {

sub garden_waste_new_bin_admin_fee { 0 }

sub waste_get_pro_rata_cost {
my $self = shift;

return $self->feature('payment_gateway')->{ggw_cost};
}

sub bulky_collection_time { { hours => 7, minutes => 0 } }
sub bulky_cancellation_cutoff_time { { hours => 23, minutes => 59 } }
sub bulky_cancel_by_update { 1 }
Expand Down
6 changes: 6 additions & 0 deletions perllib/FixMyStreet/Roles/Cobrand/Echo.pm
Original file line number Diff line number Diff line change
Expand Up @@ -971,6 +971,12 @@ sub garden_waste_cost_pa {
return $cost;
}

# Same as full cost
sub waste_get_pro_rata_cost {
my ($self, $bins, $end) = @_;
return $self->garden_waste_cost_pa($bins);
}

=head2 garden_waste_cost_pa_in_one_month
Returns the cost of garden waste in one month, if it differs from the usual
Expand Down
6 changes: 0 additions & 6 deletions perllib/FixMyStreet/Roles/Cobrand/SLWP.pm
Original file line number Diff line number Diff line change
Expand Up @@ -362,12 +362,6 @@ sub garden_container_data_extract {
# We don't have overdue renewals here
sub waste_sub_overdue { 0 }

# Same as full cost
sub waste_get_pro_rata_cost {
my ($self, $bins, $end) = @_;
return $self->garden_waste_cost_pa($bins);
}

sub waste_garden_sub_params {
my ($self, $data, $type) = @_;
my $c = $self->{c};
Expand Down
27 changes: 24 additions & 3 deletions t/app/controller/waste_brent_garden.t
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ create_contact({ category => 'Amend Garden Subscription', email => 'garden@examp
{ code => 'System Notes', required => 0, automated => 'hidden_field' },
{ code => 'Paid_Collection_Container_Quantity', required => 1, automated => 'hidden_field' },
{ code => 'Payment_Value', required => 1, automated => 'hidden_field' },
{ code => 'pro_rata', required => 0, automated => 'hidden_field' },
{ code => 'payment', required => 1, automated => 'hidden_field' },
{ code => 'payment_method', required => 1, automated => 'hidden_field' },
{ code => 'email_renewal_reminders_opt_in', required => 0, automated => 'hidden_field' },
Expand Down Expand Up @@ -663,11 +664,13 @@ FixMyStreet::override_config {
'bins_wanted' => 3,
'container_type' => 1,
'container_quantity' => 1,
cost => 2500,
},
{
'bins_wanted' => 4,
'container_type' => 1,
'container_quantity' => 2,
cost => 5000,
},
{
'bins_wanted' => 1,
Expand All @@ -689,9 +692,26 @@ FixMyStreet::override_config {
email => $user->email
} }, 'Request '. $test->{bins_wanted} . ' bins when currently have 2');
$mech->submit_form_ok({ with_fields => { tandc => 1 }}, 'Submit request');

my $report = FixMyStreet::DB->resultset('Problem')->find({category => 'Amend Garden Subscription'});
is($report->get_extra_field_value('Container_Type'), $test->{container_type}, $test->{container_type} ? "Container Type is set to request delivery" : "Container Type is not set");
is($report->get_extra_field_value('Container_Quantity'), $test->{container_quantity}, "Container Quantity is " . ($test->{container_quantity} ? $test->{container_quantity} : 'not set'));
my %check = (
type => 'Amend',
category => 'Amend Garden Subscription',
quantity => $test->{bins_wanted},
new_quantity => $test->{container_quantity},
new_bin_type => $test->{container_type},
bin_type => undef,
ref_type => 'apn',
);
if ($test->{bins_wanted} > 2) {
is $mech->res->previous->code, 302, 'payments issues a redirect';
is $mech->res->previous->header('Location'), 'http://paye.example.org/faq?apnReference=4ab5f886-de7d-4f5b-bbd8-42151a5deb82', "redirects to payment gateway";
is $sent_params->{items}[0]{amount}, $test->{cost}, 'correct amount used';
check_extra_data_pre_confirm($report, %check);
} else {
check_extra_data_pre_confirm($report, %check, state => 'confirmed', payment_method => 'csc');
}

$report->delete;
};
};
Expand Down Expand Up @@ -871,10 +891,11 @@ sub check_extra_data_pre_confirm {
new_quantity => '',
new_bin_type => '',
ref_type => 'scp',
category => 'Garden Subscription',
@_
);
$report->discard_changes;
is $report->category, 'Garden Subscription', 'correct category on report';
is $report->category, $params{category}, 'correct category on report';
is $report->title, "Garden Subscription - $params{type}", 'correct title on report';
is $report->get_extra_field_value('payment_method'), $params{payment_method}, 'correct payment method on report';
is $report->get_extra_field_value('Paid_Collection_Container_Quantity'), $params{quantity}, 'correct bin count';
Expand Down

0 comments on commit 1b6535b

Please sign in to comment.