pricing: remove payer variables (#78015)
This commit is contained in:
parent
a19fa51fae
commit
108a341057
|
@ -95,16 +95,6 @@ class PricingVariableForm(forms.Form):
|
|||
PricingVariableFormSet = forms.formset_factory(PricingVariableForm)
|
||||
|
||||
|
||||
class PricingPayerForm(forms.Form):
|
||||
key = forms.CharField(required=True, widget=forms.TextInput(attrs={'readonly': True}))
|
||||
value = forms.CharField(
|
||||
label=_('Value template'), widget=forms.TextInput(attrs={'size': 60}), required=False
|
||||
)
|
||||
|
||||
|
||||
PricingPayerFormSet = forms.formset_factory(PricingPayerForm, extra=0)
|
||||
|
||||
|
||||
class PricingCriteriaCategoryAddForm(forms.Form):
|
||||
category = forms.ModelChoiceField(
|
||||
label=_('Criteria category to add'), queryset=CriteriaCategory.objects.none(), required=True
|
||||
|
|
|
@ -0,0 +1,14 @@
|
|||
from django.db import migrations
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
dependencies = [
|
||||
('pricing', '0011_payer_variables'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.RemoveField(
|
||||
model_name='pricing',
|
||||
name='payer_variables',
|
||||
),
|
||||
]
|
|
@ -194,7 +194,6 @@ class Pricing(models.Model):
|
|||
)
|
||||
criterias = models.ManyToManyField(Criteria)
|
||||
extra_variables = models.JSONField(blank=True, default=dict)
|
||||
payer_variables = models.JSONField(blank=True, default=dict)
|
||||
|
||||
class Meta:
|
||||
ordering = ['label']
|
||||
|
@ -225,16 +224,6 @@ class Pricing(models.Model):
|
|||
def get_extra_variables_keys(self):
|
||||
return sorted((self.extra_variables or {}).keys())
|
||||
|
||||
def get_payer_variables_keys(self):
|
||||
return [
|
||||
'payer_external_id',
|
||||
'payer_external_id_from_nameid',
|
||||
'payer_first_name',
|
||||
'payer_last_name',
|
||||
'payer_demat',
|
||||
'payer_direct_debit',
|
||||
]
|
||||
|
||||
@classmethod
|
||||
def import_json(cls, data):
|
||||
data = data.copy()
|
||||
|
|
|
@ -27,7 +27,6 @@
|
|||
<div class="pk-tabs">
|
||||
<div class="pk-tabs--tab-list" role="tablist">
|
||||
<button aria-controls="panel-variables" aria-selected="true" id="tab-variables" role="tab" tabindex="0">{% trans "Variables" %}</button>
|
||||
<button aria-controls="panel-payer" aria-selected="false" id="tab-payer" role="tab" tabindex="-1">{% trans "Payer" %}</button>
|
||||
<button aria-controls="panel-criterias" aria-selected="false" id="tab-criterias" role="tab" tabindex="-1">{% trans "Criterias" %}</button>
|
||||
<button aria-controls="panel-usage" aria-selected="false" id="tab-usage" role="tab" tabindex="-1">{% trans "Used in agendas" %}</button>
|
||||
</div>
|
||||
|
@ -48,19 +47,6 @@
|
|||
</div>
|
||||
</div>
|
||||
|
||||
<div aria-labelledby="tab-payer" hidden="" id="panel-payer" role="tabpanel" tabindex="0">
|
||||
<label>{% trans 'Payer variables:' %}</label>
|
||||
<dl>
|
||||
{% for key in object.get_payer_variables_keys %}
|
||||
<dt><b>{% blocktrans %}{{ key }}:{% endblocktrans %}</b></dt>
|
||||
<dd><pre>{{ object.payer_variables|get:key|default:'' }}</pre></dd>
|
||||
{% endfor %}
|
||||
</dl>
|
||||
<div class="panel--buttons">
|
||||
<a class="pk-button" rel="popup" href="{% url 'lingo-manager-pricing-payer-edit' pk=object.pk %}">{% trans 'Define payer variables' %}</a>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div aria-labelledby="tab-criterias" hidden="" id="panel-criterias" role="tabpanel" tabindex="0">
|
||||
{% with criterias=object.criterias.all categories=object.categories.all %}
|
||||
{% if categories %}
|
||||
|
|
|
@ -1,38 +0,0 @@
|
|||
{% extends "lingo/pricing/manager_pricing_detail.html" %}
|
||||
{% load i18n %}
|
||||
|
||||
{% block breadcrumb %}
|
||||
{{ block.super }}
|
||||
<a href="{% url 'lingo-manager-pricing-payer-edit' object.pk %}">{% trans "Payer variables definition" %}</a>
|
||||
{% endblock %}
|
||||
|
||||
{% block appbar %}
|
||||
<h2>{% trans "Payer variables definition" %}</h2>
|
||||
{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<form method="post" enctype="multipart/form-data">
|
||||
{% csrf_token %}
|
||||
{{ form.management_form }}
|
||||
<table>
|
||||
<tbody>
|
||||
{% for sub_form in form %}
|
||||
<tr>
|
||||
{% for field in sub_form %}
|
||||
<td>
|
||||
{{ field.errors.as_ul }}
|
||||
{{ field }}
|
||||
{% if forloop.first %}
|
||||
{% endif %}
|
||||
</td>
|
||||
{% endfor %}
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
<div class="buttons">
|
||||
<button class="submit-button">{% trans "Save" %}</button>
|
||||
<a class="cancel" href="{% url 'lingo-manager-pricing-detail' object.pk %}">{% trans 'Cancel' %}</a>
|
||||
</div>
|
||||
</form>
|
||||
{% endblock %}
|
|
@ -58,11 +58,6 @@ urlpatterns = [
|
|||
views.pricing_variable_edit,
|
||||
name='lingo-manager-pricing-variable-edit',
|
||||
),
|
||||
path(
|
||||
'model/<int:pk>/payer/',
|
||||
views.pricing_payer_edit,
|
||||
name='lingo-manager-pricing-payer-edit',
|
||||
),
|
||||
path(
|
||||
'model/<int:pk>/category/add/',
|
||||
views.pricing_criteria_category_add,
|
||||
|
|
|
@ -58,7 +58,6 @@ from lingo.pricing.forms import (
|
|||
PricingCriteriaCategoryEditForm,
|
||||
PricingDuplicateForm,
|
||||
PricingMatrixForm,
|
||||
PricingPayerFormSet,
|
||||
PricingTestToolForm,
|
||||
PricingVariableFormSet,
|
||||
)
|
||||
|
@ -411,43 +410,6 @@ class PricingVariableEdit(FormView):
|
|||
pricing_variable_edit = PricingVariableEdit.as_view()
|
||||
|
||||
|
||||
class PricingPayerEdit(FormView):
|
||||
template_name = 'lingo/pricing/manager_pricing_payer_form.html'
|
||||
model = Pricing
|
||||
form_class = PricingPayerFormSet
|
||||
|
||||
def dispatch(self, request, *args, **kwargs):
|
||||
self.object = get_object_or_404(Pricing, pk=kwargs['pk'])
|
||||
return super().dispatch(request, *args, **kwargs)
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
kwargs['object'] = self.object
|
||||
return super().get_context_data(**kwargs)
|
||||
|
||||
def get_initial(self):
|
||||
return list(
|
||||
{'key': k, 'value': self.object.payer_variables.get(k) or ''}
|
||||
for k in self.object.get_payer_variables_keys()
|
||||
)
|
||||
|
||||
def form_valid(self, form):
|
||||
self.object.payer_variables = {k: '' for k in self.object.get_payer_variables_keys()}
|
||||
for sub_data in form.cleaned_data:
|
||||
if not sub_data.get('key'):
|
||||
continue
|
||||
if sub_data['key'] not in self.object.payer_variables:
|
||||
continue
|
||||
self.object.payer_variables[sub_data['key']] = sub_data['value']
|
||||
self.object.save()
|
||||
return HttpResponseRedirect(self.get_success_url())
|
||||
|
||||
def get_success_url(self):
|
||||
return '%s#open:payer' % reverse('lingo-manager-pricing-detail', args=[self.object.pk])
|
||||
|
||||
|
||||
pricing_payer_edit = PricingPayerEdit.as_view()
|
||||
|
||||
|
||||
class PricingCriteriaCategoryAddView(FormView):
|
||||
template_name = 'lingo/pricing/manager_pricing_criteria_category_form.html'
|
||||
model = Pricing
|
||||
|
|
|
@ -167,47 +167,6 @@ def test_pricing_edit_extra_variables(app, admin_user):
|
|||
assert '<dd><pre>bar</pre></dd>' in resp
|
||||
|
||||
|
||||
def test_pricing_edit_payer_variables(app, admin_user):
|
||||
pricing = Pricing.objects.create(label='Model')
|
||||
assert pricing.payer_variables == {}
|
||||
|
||||
app = login(app)
|
||||
resp = app.get('/manage/pricing/model/%s/' % pricing.pk)
|
||||
assert '<label>Payer variables:</label>' in resp.text
|
||||
assert '<dt><b>payer_external_id:</b></dt>' in resp
|
||||
assert '<dt><b>payer_external_id_from_nameid:</b></dt>' in resp
|
||||
assert '<dt><b>payer_first_name:</b></dt>' in resp
|
||||
assert '<dt><b>payer_last_name:</b></dt>' in resp
|
||||
assert '<dt><b>payer_demat:</b></dt>' in resp
|
||||
assert '<dt><b>payer_direct_debit:</b></dt>' in resp
|
||||
assert resp.text.count('<dd><pre></pre></dd>') == 6
|
||||
resp = resp.click(href='/manage/pricing/model/%s/payer/' % pricing.pk)
|
||||
assert resp.form['form-TOTAL_FORMS'].value == '6'
|
||||
assert resp.form['form-0-key'].value == 'payer_external_id'
|
||||
assert resp.form['form-0-value'].value == ''
|
||||
assert resp.form['form-1-key'].value == 'payer_external_id_from_nameid'
|
||||
assert resp.form['form-1-value'].value == ''
|
||||
assert resp.form['form-2-key'].value == 'payer_first_name'
|
||||
assert resp.form['form-2-value'].value == ''
|
||||
assert resp.form['form-3-key'].value == 'payer_last_name'
|
||||
assert resp.form['form-3-value'].value == ''
|
||||
assert resp.form['form-4-key'].value == 'payer_demat'
|
||||
assert resp.form['form-4-value'].value == ''
|
||||
assert resp.form['form-5-key'].value == 'payer_direct_debit'
|
||||
assert resp.form['form-5-value'].value == ''
|
||||
resp.form['form-0-value'] = 'payer:42'
|
||||
resp = resp.form.submit().follow()
|
||||
pricing.refresh_from_db()
|
||||
assert pricing.payer_variables == {
|
||||
'payer_external_id': 'payer:42',
|
||||
'payer_external_id_from_nameid': '',
|
||||
'payer_first_name': '',
|
||||
'payer_last_name': '',
|
||||
'payer_demat': '',
|
||||
'payer_direct_debit': '',
|
||||
}
|
||||
|
||||
|
||||
def test_pricing_add_category(app, admin_user):
|
||||
pricing = Pricing.objects.create(label='Model')
|
||||
category1 = CriteriaCategory.objects.create(label='Cat 1')
|
||||
|
|
Loading…
Reference in New Issue