pricing: flat fee schedule configuration (#67675)
This commit is contained in:
parent
fd54026499
commit
caa584d998
|
@ -125,7 +125,7 @@ class PricingCriteriaCategoryEditForm(forms.Form):
|
|||
class NewAgendaPricingForm(forms.ModelForm):
|
||||
class Meta:
|
||||
model = AgendaPricing
|
||||
fields = ['label', 'pricing', 'date_start', 'date_end']
|
||||
fields = ['label', 'pricing', 'date_start', 'date_end', 'flat_fee_schedule', 'subscription_required']
|
||||
widgets = {
|
||||
'date_start': forms.DateInput(attrs={'type': 'date'}, format='%Y-%m-%d'),
|
||||
'date_end': forms.DateInput(attrs={'type': 'date'}, format='%Y-%m-%d'),
|
||||
|
@ -145,6 +145,9 @@ class NewAgendaPricingForm(forms.ModelForm):
|
|||
if 'date_start' in cleaned_data and 'date_end' in cleaned_data:
|
||||
if cleaned_data['date_end'] <= cleaned_data['date_start']:
|
||||
self.add_error('date_end', _('End date must be greater than start date.'))
|
||||
if 'flat_fee_schedule' in cleaned_data and 'subscription_required' in cleaned_data:
|
||||
if not cleaned_data['flat_fee_schedule']:
|
||||
cleaned_data['subscription_required'] = True
|
||||
|
||||
return cleaned_data
|
||||
|
||||
|
@ -152,7 +155,15 @@ class NewAgendaPricingForm(forms.ModelForm):
|
|||
class AgendaPricingForm(NewAgendaPricingForm):
|
||||
class Meta:
|
||||
model = AgendaPricing
|
||||
fields = ['label', 'slug', 'pricing', 'date_start', 'date_end']
|
||||
fields = [
|
||||
'label',
|
||||
'slug',
|
||||
'pricing',
|
||||
'date_start',
|
||||
'date_end',
|
||||
'flat_fee_schedule',
|
||||
'subscription_required',
|
||||
]
|
||||
widgets = {
|
||||
'date_start': forms.DateInput(attrs={'type': 'date'}, format='%Y-%m-%d'),
|
||||
'date_end': forms.DateInput(attrs={'type': 'date'}, format='%Y-%m-%d'),
|
||||
|
|
|
@ -41,6 +41,10 @@
|
|||
<ul>
|
||||
<li>{% trans "Pricing model:" %} <a href="{% url 'lingo-manager-pricing-detail' object.pricing.pk %}">{{ object.pricing }}</a></li>
|
||||
<li>{% blocktrans with start=object.date_start|date:'d/m/Y' end=object.date_end|date:'d/m/Y' %}From {{ start }} to {{ end }}{% endblocktrans %}</li>
|
||||
<li>{% trans "Flat fee schedule:" %} {{ object.flat_fee_schedule|yesno }}</li>
|
||||
{% if object.flat_fee_schedule %}
|
||||
<li>{% trans "Subscription required:" %} {{ object.subscription_required|yesno }}</li>
|
||||
{% endif %}
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
|
|
|
@ -23,6 +23,18 @@
|
|||
<form method="post" enctype="multipart/form-data">
|
||||
{% csrf_token %}
|
||||
{{ form.as_p }}
|
||||
<script>
|
||||
$(function() {
|
||||
$('#id_flat_fee_schedule').on('change', function() {
|
||||
if ($(this).is(':checked')) {
|
||||
$('#id_subscription_required').parent().show();
|
||||
} else {
|
||||
$('#id_subscription_required').parent().hide();
|
||||
}
|
||||
});
|
||||
$('#id_flat_fee_schedule').trigger('change');
|
||||
});
|
||||
</script>
|
||||
<div class="buttons">
|
||||
<button class="submit-button">{% trans "Save" %}</button>
|
||||
{% if object.pk %}
|
||||
|
|
|
@ -26,6 +26,8 @@ def test_add_agenda_pricing(app, admin_user):
|
|||
resp.form['pricing'] = pricing.pk
|
||||
resp.form['date_start'] = '2021-09-01'
|
||||
resp.form['date_end'] = '2021-09-01'
|
||||
resp.form['flat_fee_schedule'] = False
|
||||
resp.form['subscription_required'] = False
|
||||
resp = resp.form.submit()
|
||||
assert resp.context['form'].errors['date_end'] == ['End date must be greater than start date.']
|
||||
resp.form['date_end'] = '2022-09-01'
|
||||
|
@ -38,10 +40,21 @@ def test_add_agenda_pricing(app, admin_user):
|
|||
assert list(agenda_pricing.agendas.all()) == []
|
||||
assert agenda_pricing.date_start == datetime.date(2021, 9, 1)
|
||||
assert agenda_pricing.date_end == datetime.date(2022, 9, 1)
|
||||
assert agenda_pricing.flat_fee_schedule is False
|
||||
assert agenda_pricing.subscription_required is True
|
||||
|
||||
resp = app.get('/manage/pricing/agenda-pricing/add/')
|
||||
# starts on last date_end
|
||||
assert resp.form['date_start'].value == '2022-09-01'
|
||||
resp.form['label'] = 'Pricing for lunch'
|
||||
resp.form['pricing'] = pricing.pk
|
||||
resp.form['date_end'] = '2023-09-01'
|
||||
resp.form['flat_fee_schedule'] = True
|
||||
resp.form['subscription_required'] = False
|
||||
resp.form.submit()
|
||||
agenda_pricing = AgendaPricing.objects.latest('pk')
|
||||
assert agenda_pricing.flat_fee_schedule is True
|
||||
assert agenda_pricing.subscription_required is False
|
||||
|
||||
|
||||
def test_edit_agenda_pricing(app, admin_user):
|
||||
|
@ -69,6 +82,8 @@ def test_edit_agenda_pricing(app, admin_user):
|
|||
resp.form['pricing'] = pricing2.pk
|
||||
resp.form['date_start'] = '2021-09-01'
|
||||
resp.form['date_end'] = '2021-09-01'
|
||||
resp.form['flat_fee_schedule'] = False
|
||||
resp.form['subscription_required'] = False
|
||||
resp = resp.form.submit()
|
||||
assert resp.context['form'].errors['slug'] == ['Another pricing exists with the same identifier.']
|
||||
assert resp.context['form'].errors['date_end'] == ['End date must be greater than start date.']
|
||||
|
@ -82,6 +97,16 @@ def test_edit_agenda_pricing(app, admin_user):
|
|||
assert agenda_pricing.pricing == pricing2
|
||||
assert agenda_pricing.date_start == datetime.date(2021, 8, 1)
|
||||
assert agenda_pricing.date_end == datetime.date(2022, 9, 1)
|
||||
assert agenda_pricing.flat_fee_schedule is False
|
||||
assert agenda_pricing.subscription_required is True
|
||||
|
||||
resp = app.get('/manage/pricing/agenda-pricing/%s/edit/' % agenda_pricing.pk)
|
||||
resp.form['flat_fee_schedule'] = True
|
||||
resp.form['subscription_required'] = False
|
||||
resp.form.submit()
|
||||
agenda_pricing.refresh_from_db()
|
||||
assert agenda_pricing.flat_fee_schedule is True
|
||||
assert agenda_pricing.subscription_required is False
|
||||
|
||||
|
||||
def test_detail_agenda_pricing(app, admin_user):
|
||||
|
|
Loading…
Reference in New Issue