pricing: always pass a pricing_date in context (#67675)
to be able to get the correct QF value
This commit is contained in:
parent
bbe4dce2cf
commit
83684c3899
|
@ -436,8 +436,12 @@ class PricingTestToolForm(forms.Form):
|
|||
def compute_for_flat_fee_schedule(self):
|
||||
if self.agenda_pricing.subscription_required and not self.serialized_subscription:
|
||||
return
|
||||
pricing_date = self.agenda_pricing.date_start
|
||||
if self.cleaned_data.get('billing_date'):
|
||||
pricing_date = self.cleaned_data['billing_date'].date_start
|
||||
return self.agenda_pricing.get_pricing_data(
|
||||
request=self.request,
|
||||
pricing_date=pricing_date,
|
||||
subscription=self.serialized_subscription,
|
||||
user_external_id=self.cleaned_data['user_external_id'],
|
||||
adult_external_id=self.cleaned_data['adult_external_id'],
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
|
||||
import copy
|
||||
import dataclasses
|
||||
import datetime
|
||||
import decimal
|
||||
from typing import List
|
||||
|
||||
|
@ -399,10 +400,11 @@ class AgendaPricing(models.Model):
|
|||
|
||||
return created, agenda_pricing
|
||||
|
||||
def get_pricing_data(self, request, user_external_id, adult_external_id, subscription=None):
|
||||
def get_pricing_data(self, request, pricing_date, user_external_id, adult_external_id, subscription=None):
|
||||
# compute pricing for flat_fee_schedule mode
|
||||
# subscription is None if subscription_required is False
|
||||
data = {
|
||||
'pricing_date': pricing_date, # date to use for QF
|
||||
'subscription': subscription,
|
||||
}
|
||||
context = self.get_pricing_context(
|
||||
|
@ -425,7 +427,9 @@ class AgendaPricing(models.Model):
|
|||
self, request, agenda, event, subscription, check_status, booking, user_external_id, adult_external_id
|
||||
):
|
||||
# compute pricing for an event
|
||||
event_date = datetime.datetime.fromisoformat(event['start_datetime']).date()
|
||||
data = {
|
||||
'pricing_date': event_date, # date to use for QF
|
||||
'event': event,
|
||||
'subscription': subscription,
|
||||
'booking': booking,
|
||||
|
|
|
@ -1135,6 +1135,7 @@ def test_detail_agenda_pricing_test_tool_for_flat_fee_schedule(
|
|||
assert mock_pricing_data.call_args_list == [
|
||||
mock.call(
|
||||
request=mock.ANY,
|
||||
pricing_date=datetime.date(2021, 9, 1),
|
||||
subscription={'date_start': '2021-09-02', 'date_end': '2021-09-03'},
|
||||
user_external_id='user:1',
|
||||
adult_external_id='adult:1',
|
||||
|
@ -1169,6 +1170,7 @@ def test_detail_agenda_pricing_test_tool_for_flat_fee_schedule(
|
|||
assert mock_pricing_data.call_args_list == [
|
||||
mock.call(
|
||||
request=mock.ANY,
|
||||
pricing_date=datetime.date(2021, 9, 1),
|
||||
subscription={'date_start': '2021-09-02', 'date_end': '2021-09-03'},
|
||||
user_external_id='user:1',
|
||||
adult_external_id='adult:1',
|
||||
|
@ -1201,6 +1203,7 @@ def test_detail_agenda_pricing_test_tool_for_flat_fee_schedule(
|
|||
assert mock_pricing_data.call_args_list == [
|
||||
mock.call(
|
||||
request=mock.ANY,
|
||||
pricing_date=datetime.date(2021, 9, 15),
|
||||
subscription={'date_start': '2021-09-15', 'date_end': '2021-09-16'},
|
||||
user_external_id='user:1',
|
||||
adult_external_id='adult:1',
|
||||
|
@ -1218,6 +1221,7 @@ def test_detail_agenda_pricing_test_tool_for_flat_fee_schedule(
|
|||
assert mock_pricing_data.call_args_list == [
|
||||
mock.call(
|
||||
request=mock.ANY,
|
||||
pricing_date=datetime.date(2021, 9, 15),
|
||||
subscription={'date_start': '2021-09-30', 'date_end': '2021-10-01'},
|
||||
user_external_id='user:1',
|
||||
adult_external_id='adult:1',
|
||||
|
@ -1239,6 +1243,7 @@ def test_detail_agenda_pricing_test_tool_for_flat_fee_schedule(
|
|||
assert mock_pricing_data.call_args_list == [
|
||||
mock.call(
|
||||
request=mock.ANY,
|
||||
pricing_date=datetime.date(2021, 9, 1),
|
||||
subscription=None,
|
||||
user_external_id='user:1',
|
||||
adult_external_id='adult:1',
|
||||
|
|
|
@ -952,6 +952,7 @@ def test_get_pricing_data(context):
|
|||
for subscription in [None, {'foo': 'bar'}]:
|
||||
assert agenda_pricing.get_pricing_data(
|
||||
request=context['request'],
|
||||
pricing_date=datetime.date(year=2021, month=9, day=1),
|
||||
subscription=subscription,
|
||||
user_external_id='child:42',
|
||||
adult_external_id='parent:35',
|
||||
|
|
Loading…
Reference in New Issue