pricing: manager views to see and edit min pricings (#89605)
This commit is contained in:
parent
736136afd0
commit
f07f664e0c
|
@ -18,8 +18,10 @@
|
|||
<div class="pk-tabs">
|
||||
<div class="pk-tabs--tab-list" role="tablist">
|
||||
<button aria-controls="panel-matrix" aria-selected="true" id="tab-matrix" role="tab" tabindex="0">{% trans "Pricings" context 'amount' %}</button>
|
||||
{% if object.kind != 'basic' %}
|
||||
{% if object.kind == 'effort' %}
|
||||
<button aria-controls="panel-pricing-options" aria-selected="false" id="tab-pricing-options" role="tab" tabindex="-1">{% trans "Pricing options" %}</button>
|
||||
{% elif object.kind == 'reduction' %}
|
||||
<button aria-controls="panel-min-matrix" aria-selected="false" id="tab-min-matrix" role="tab" tabindex="-1">{% trans "Minimal pricings" %}</button>
|
||||
{% endif %}
|
||||
</div>
|
||||
<div class="pk-tabs--container">
|
||||
|
@ -69,20 +71,59 @@
|
|||
{% endwith %}
|
||||
</div>
|
||||
|
||||
{% if object.kind != 'basic' %}
|
||||
{% if object.kind == 'effort' %}
|
||||
<div aria-labelledby="tab-pricing-options" hidden="" id="panel-pricing-options" role="tabpanel" tabindex="0">
|
||||
<ul>
|
||||
<li>{% trans "Minimal pricing:" %} {{ object.min_pricing|default_if_none:"" }}</li>
|
||||
</ul>
|
||||
{% if object.kind == 'effort' %}
|
||||
<ul>
|
||||
<li>{% trans "Maximal pricing:" %} {{ object.max_pricing|default_if_none:"" }}</li>
|
||||
</ul>
|
||||
{% endif %}
|
||||
<ul>
|
||||
<li>{% trans "Maximal pricing:" %} {{ object.max_pricing|default_if_none:"" }}</li>
|
||||
</ul>
|
||||
<div class="panel--buttons">
|
||||
<a class="pk-button" rel="popup" href="{% url 'lingo-manager-pricing-pricingoptions-edit' object.pk %}">{% trans "Edit pricing options" %}</a>
|
||||
</div>
|
||||
</div>
|
||||
{% elif object.kind == 'reduction' %}
|
||||
<div aria-labelledby="tab-min-matrix" hidden="" id="panel-min-matrix" role="tabpanel" tabindex="0">
|
||||
{% with iter_matrix=object.iter_min_pricing_matrix|list %}
|
||||
{% for matrix in iter_matrix %}
|
||||
<div class="section">
|
||||
{% if matrix.criteria %}<h3>{{ matrix.criteria.label }}</h3>{% endif %}
|
||||
<table class="main pricing-min-matrix-{{ matrix.criteria.slug }}">
|
||||
{% if matrix.rows.0.cells.0.criteria %}
|
||||
<thead>
|
||||
<tr>
|
||||
<th></th>
|
||||
{% for cell in matrix.rows.0.cells %}<th scope="col">{{ cell.criteria.label }}</th>{% endfor %}
|
||||
</tr>
|
||||
</thead>
|
||||
{% endif %}
|
||||
<tbody>
|
||||
{% for row in matrix.rows %}
|
||||
<tr class="pricing-row-{{ row.criteria.slug }}">
|
||||
<th scope="row">{{ row.criteria.label }}</th>
|
||||
{% for cell in row.cells %}
|
||||
<td class="pricing-cell-{{ cell.criteria.slug }}">{% spaceless %}
|
||||
{{ cell.value|floatformat:"2"|default_if_none:"" }}
|
||||
{% endspaceless %}</td>
|
||||
{% endfor %}
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
<div class="panel--buttons">
|
||||
<a class="pk-button" href="{% if matrix.criteria %}{% url 'lingo-manager-pricing-min-matrix-slug-edit' object.pk matrix.criteria.slug %}{% else %}{% url 'lingo-manager-pricing-min-matrix-edit' object.pk %}{% endif %}">{% trans "Edit minimal pricing" %}</a>
|
||||
</div>
|
||||
</div>
|
||||
{% empty %}
|
||||
<div class="big-msg-info">
|
||||
{% blocktrans trimmed %}
|
||||
This pricing is misconfigured.
|
||||
{% endblocktrans %}
|
||||
</div>
|
||||
{% endfor %}
|
||||
{% endwith %}
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
</div>
|
||||
|
|
|
@ -4,57 +4,18 @@
|
|||
{% block breadcrumb %}
|
||||
{{ block.super }}
|
||||
{% if matrix.criteria %}
|
||||
<a href="{% url 'lingo-manager-pricing-matrix-slug-edit' object.pk matrix.criteria.slug %}">{% trans "Edit pricing" %}</a>
|
||||
<a href="{% url 'lingo-manager-pricing-matrix-slug-edit' object.pk matrix.criteria.slug %}">{% trans "Edit pricing" context 'matrix' %}</a>
|
||||
{% else %}
|
||||
<a href="{% url 'lingo-manager-pricing-matrix-edit' object.pk %}">{% trans "Edit pricing" %}</a>
|
||||
<a href="{% url 'lingo-manager-pricing-matrix-edit' object.pk %}">{% trans "Edit pricing" context 'matrix' %}</a>
|
||||
{% endif %}
|
||||
{% endblock %}
|
||||
|
||||
{% block appbar %}
|
||||
<h2>{% trans "Edit pricing" %}</h2>
|
||||
<h2>{% trans "Edit pricing" context 'matrix' %}</h2>
|
||||
{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<div class="section">
|
||||
{% if matrix.criteria %}<h3>{{ matrix.criteria.label }}</h3>{% endif %}
|
||||
<div>
|
||||
<form method="post" enctype="multipart/form-data">
|
||||
{% csrf_token %}
|
||||
{{ form.management_form }}
|
||||
<table class="main">
|
||||
{% if matrix.rows.0.cells.0.criteria %}
|
||||
<thead>
|
||||
<tr>
|
||||
<th></th>
|
||||
{% for cell in matrix.rows.0.cells %}
|
||||
<th>{{ cell.criteria.label }}</th>
|
||||
{% endfor %}
|
||||
</tr>
|
||||
</thead>
|
||||
{% endif %}
|
||||
<tbody>
|
||||
{% for sub_form in form %}
|
||||
{% with row=matrix.rows|get:forloop.counter0 %}
|
||||
<tr>
|
||||
<th>{{ row.criteria.label }}</th>
|
||||
{% for field in sub_form %}
|
||||
<td>
|
||||
{{ field.errors.as_ul }}
|
||||
{{ field }}
|
||||
</td>
|
||||
{% endfor %}
|
||||
</tr>
|
||||
{% endwith %}
|
||||
{% 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>
|
||||
</div>
|
||||
</div>
|
||||
{% include 'lingo/pricing/manager_pricing_matrix_form_fragment.html' %}
|
||||
{% endblock %}
|
||||
|
||||
{% block sidebar %}
|
||||
|
|
|
@ -0,0 +1,41 @@
|
|||
{% load i18n %}
|
||||
<div class="section">
|
||||
{% if matrix.criteria %}<h3>{{ matrix.criteria.label }}</h3>{% endif %}
|
||||
<div>
|
||||
<form method="post" enctype="multipart/form-data">
|
||||
{% csrf_token %}
|
||||
{{ form.management_form }}
|
||||
<table class="main">
|
||||
{% if matrix.rows.0.cells.0.criteria %}
|
||||
<thead>
|
||||
<tr>
|
||||
<th></th>
|
||||
{% for cell in matrix.rows.0.cells %}
|
||||
<th>{{ cell.criteria.label }}</th>
|
||||
{% endfor %}
|
||||
</tr>
|
||||
</thead>
|
||||
{% endif %}
|
||||
<tbody>
|
||||
{% for sub_form in form %}
|
||||
{% with row=matrix.rows|get:forloop.counter0 %}
|
||||
<tr>
|
||||
<th>{{ row.criteria.label }}</th>
|
||||
{% for field in sub_form %}
|
||||
<td>
|
||||
{{ field.errors.as_ul }}
|
||||
{{ field }}
|
||||
</td>
|
||||
{% endfor %}
|
||||
</tr>
|
||||
{% endwith %}
|
||||
{% 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>
|
||||
</div>
|
||||
</div>
|
|
@ -0,0 +1,22 @@
|
|||
{% extends "lingo/pricing/manager_pricing_detail.html" %}
|
||||
{% load i18n %}
|
||||
|
||||
{% block breadcrumb %}
|
||||
{{ block.super }}
|
||||
{% if matrix.criteria %}
|
||||
<a href="{% url 'lingo-manager-pricing-min-matrix-slug-edit' object.pk matrix.criteria.slug %}">{% trans "Edit min pricing" %}</a>
|
||||
{% else %}
|
||||
<a href="{% url 'lingo-manager-pricing-min-matrix-edit' object.pk %}">{% trans "Edit min pricing" %}</a>
|
||||
{% endif %}
|
||||
{% endblock %}
|
||||
|
||||
{% block appbar %}
|
||||
<h2>{% trans "Edit min pricing" %}</h2>
|
||||
{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
{% include 'lingo/pricing/manager_pricing_matrix_form_fragment.html' %}
|
||||
{% endblock %}
|
||||
|
||||
{% block sidebar %}
|
||||
{% endblock %}
|
|
@ -211,6 +211,16 @@ urlpatterns = [
|
|||
views.pricing_matrix_edit,
|
||||
name='lingo-manager-pricing-matrix-slug-edit',
|
||||
),
|
||||
path(
|
||||
'<int:pk>/matrix/edit/min/',
|
||||
views.pricing_min_matrix_edit,
|
||||
name='lingo-manager-pricing-min-matrix-edit',
|
||||
),
|
||||
re_path(
|
||||
r'^(?P<pk>\d+)/matrix/(?P<slug>[-_a-zA-Z0-9]+)/edit/min/$',
|
||||
views.pricing_min_matrix_edit,
|
||||
name='lingo-manager-pricing-min-matrix-slug-edit',
|
||||
),
|
||||
path('check-types/', views.check_type_list, name='lingo-manager-check-type-list'),
|
||||
path(
|
||||
'check-type/group/add/',
|
||||
|
|
|
@ -733,7 +733,7 @@ class PricingPricingOptionsEditView(UpdateView):
|
|||
form_class = PricingPricingOptionsForm
|
||||
|
||||
def get_queryset(self):
|
||||
return super().get_queryset().exclude(kind='basic')
|
||||
return super().get_queryset().filter(kind='effort')
|
||||
|
||||
def get_success_url(self):
|
||||
return '%s#open:pricing-options' % reverse('lingo-manager-pricing-detail', args=[self.object.pk])
|
||||
|
@ -931,10 +931,14 @@ pricing_billing_date_delete = PricingBillingDateDeleteView.as_view()
|
|||
|
||||
class PricingMatrixEdit(FormView):
|
||||
template_name = 'lingo/pricing/manager_pricing_matrix_form.html'
|
||||
field = 'pricing'
|
||||
|
||||
def get_pricing(self, request, *args, **kwargs):
|
||||
self.object = get_object_or_404(Pricing, pk=kwargs['pk'])
|
||||
|
||||
def dispatch(self, request, *args, **kwargs):
|
||||
self.object = get_object_or_404(Pricing, pk=kwargs['pk'])
|
||||
matrix_list = list(self.object.iter_pricing_matrix())
|
||||
self.get_pricing(request, *args, **kwargs)
|
||||
matrix_list = list(getattr(self.object, 'iter_%s_matrix' % self.field)())
|
||||
if not matrix_list:
|
||||
raise Http404
|
||||
self.matrix = None
|
||||
|
@ -986,16 +990,18 @@ class PricingMatrixEdit(FormView):
|
|||
value = sub_data['crit_%s' % j]
|
||||
key = cell.criteria.identifier if cell.criteria else None
|
||||
matrix_pricing_data[key][row.criteria.identifier] = float(value)
|
||||
pricing_data = getattr(self.object, '%s_data' % self.field)
|
||||
if self.matrix.criteria:
|
||||
# full pricing model with 3 categories
|
||||
self.object.pricing_data = self.object.pricing_data or {}
|
||||
self.object.pricing_data[self.matrix.criteria.identifier] = matrix_pricing_data
|
||||
pricing_data = pricing_data or {}
|
||||
pricing_data[self.matrix.criteria.identifier] = matrix_pricing_data
|
||||
elif list(matrix_pricing_data.keys()) == [None]:
|
||||
# only one category
|
||||
self.object.pricing_data = matrix_pricing_data[None]
|
||||
pricing_data = matrix_pricing_data[None]
|
||||
else:
|
||||
# 2 categories
|
||||
self.object.pricing_data = matrix_pricing_data
|
||||
pricing_data = matrix_pricing_data
|
||||
setattr(self.object, '%s_data' % self.field, pricing_data)
|
||||
self.object.save()
|
||||
return self.form_valid(form)
|
||||
else:
|
||||
|
@ -1008,6 +1014,20 @@ class PricingMatrixEdit(FormView):
|
|||
pricing_matrix_edit = PricingMatrixEdit.as_view()
|
||||
|
||||
|
||||
class PricingMinMatrixEdit(PricingMatrixEdit):
|
||||
template_name = 'lingo/pricing/manager_pricing_min_matrix_form.html'
|
||||
field = 'min_pricing'
|
||||
|
||||
def get_pricing(self, request, *args, **kwargs):
|
||||
self.object = get_object_or_404(Pricing, pk=kwargs['pk'], kind='reduction')
|
||||
|
||||
def get_success_url(self):
|
||||
return '%s#open:min-matrix' % (reverse('lingo-manager-pricing-detail', args=[self.object.pk]),)
|
||||
|
||||
|
||||
pricing_min_matrix_edit = PricingMinMatrixEdit.as_view()
|
||||
|
||||
|
||||
class CheckTypeListView(WithApplicationsMixin, ListView):
|
||||
template_name = 'lingo/pricing/manager_check_type_list.html'
|
||||
model = CheckTypeGroup
|
||||
|
|
|
@ -381,26 +381,8 @@ def test_edit_pricing_pricingoptions(app, admin_user):
|
|||
pricing.kind = 'reduction'
|
||||
pricing.save()
|
||||
resp = app.get('/manage/pricing/%s/' % pricing.pk)
|
||||
assert 'Pricing options' in resp
|
||||
resp = resp.click(href='/manage/pricing/%s/pricing-options/' % pricing.pk)
|
||||
assert 'min_pricing' in resp.context['form'].fields
|
||||
assert 'max_pricing' not in resp.context['form'].fields
|
||||
resp = resp.form.submit()
|
||||
assert resp.location.endswith('/manage/pricing/%s/#open:pricing-options' % pricing.pk)
|
||||
pricing.refresh_from_db()
|
||||
assert pricing.min_pricing is None
|
||||
|
||||
resp = app.get('/manage/pricing/%s/pricing-options/' % pricing.pk)
|
||||
resp.form['min_pricing'] = 0
|
||||
resp = resp.form.submit()
|
||||
pricing.refresh_from_db()
|
||||
assert pricing.min_pricing == 0
|
||||
|
||||
resp = app.get('/manage/pricing/%s/pricing-options/' % pricing.pk)
|
||||
resp.form['min_pricing'] = 10
|
||||
resp = resp.form.submit()
|
||||
pricing.refresh_from_db()
|
||||
assert pricing.min_pricing == 10
|
||||
assert 'Pricing options' not in resp
|
||||
app.get('/manage/pricing/%s/pricing-options/' % pricing.pk, status=404)
|
||||
|
||||
pricing.kind = 'effort'
|
||||
pricing.save()
|
||||
|
@ -1105,6 +1087,114 @@ def test_detail_pricing_3_categories(app, admin_user):
|
|||
== '223.0000'
|
||||
)
|
||||
|
||||
pricing.kind = 'reduction'
|
||||
pricing.min_pricing_data = {
|
||||
'cat-1:crit-1-1': {
|
||||
'cat-2:crit-2-1': {
|
||||
'cat-3:crit-3-1': 1.11,
|
||||
'cat-3:crit-3-3': 'not-a-decimal',
|
||||
'cat-3:crit-3-4': 1.14,
|
||||
},
|
||||
'cat-2:crit-2-3': {
|
||||
'cat-3:crit-3-2': 1.32,
|
||||
},
|
||||
},
|
||||
'cat-1:crit-1-2': {
|
||||
'cat-2:crit-2-2': {
|
||||
'cat-3:crit-3-3': 2.23,
|
||||
},
|
||||
},
|
||||
}
|
||||
pricing.save()
|
||||
resp = app.get('/manage/pricing/%s/' % pricing.pk)
|
||||
ths = resp.pyquery.find('table.pricing-min-matrix-crit-1-1 thead th')
|
||||
assert len(ths) == 4
|
||||
assert ths[0].text is None
|
||||
assert ths[1].text == 'Crit 2-1'
|
||||
assert ths[2].text == 'Crit 2-2'
|
||||
assert ths[3].text == 'Crit 2-3'
|
||||
assert (
|
||||
resp.pyquery.find('table.pricing-min-matrix-crit-1-1 tr.pricing-row-crit-3-1 th')[0].text
|
||||
== 'Crit 3-1'
|
||||
)
|
||||
assert (
|
||||
resp.pyquery.find('table.pricing-min-matrix-crit-1-1 tr.pricing-row-crit-3-2 th')[0].text
|
||||
== 'Crit 3-2'
|
||||
)
|
||||
assert (
|
||||
resp.pyquery.find('table.pricing-min-matrix-crit-1-1 tr.pricing-row-crit-3-3 th')[0].text
|
||||
== 'Crit 3-3'
|
||||
)
|
||||
assert (
|
||||
resp.pyquery.find('table.pricing-min-matrix-crit-1-1 tr.pricing-row-crit-3-4 th')[0].text
|
||||
== 'Crit 3-4'
|
||||
)
|
||||
assert (
|
||||
resp.pyquery.find(
|
||||
'table.pricing-min-matrix-crit-1-1 tr.pricing-row-crit-3-1 td.pricing-cell-crit-2-1'
|
||||
)[0].text
|
||||
== '1.11'
|
||||
)
|
||||
assert (
|
||||
resp.pyquery.find(
|
||||
'table.pricing-min-matrix-crit-1-1 tr.pricing-row-crit-3-2 td.pricing-cell-crit-2-1'
|
||||
)[0].text
|
||||
is None
|
||||
) # not defined
|
||||
assert (
|
||||
resp.pyquery.find(
|
||||
'table.pricing-min-matrix-crit-1-1 tr.pricing-row-crit-3-3 td.pricing-cell-crit-2-1'
|
||||
)[0].text
|
||||
is None
|
||||
) # wrong value
|
||||
assert (
|
||||
resp.pyquery.find(
|
||||
'table.pricing-min-matrix-crit-1-1 tr.pricing-row-crit-3-4 td.pricing-cell-crit-2-1'
|
||||
)[0].text
|
||||
== '1.14'
|
||||
)
|
||||
assert (
|
||||
resp.pyquery.find(
|
||||
'table.pricing-min-matrix-crit-1-1 tr.pricing-row-crit-3-2 td.pricing-cell-crit-2-3'
|
||||
)[0].text
|
||||
== '1.32'
|
||||
)
|
||||
assert '<h3>Crit 1-2</h3>' in resp
|
||||
ths = resp.pyquery.find('table.pricing-min-matrix-crit-1-2 thead th')
|
||||
assert len(ths) == 4
|
||||
assert ths[0].text is None
|
||||
assert ths[1].text == 'Crit 2-1'
|
||||
assert ths[2].text == 'Crit 2-2'
|
||||
assert ths[3].text == 'Crit 2-3'
|
||||
assert (
|
||||
resp.pyquery.find('table.pricing-min-matrix-crit-1-2 tr.pricing-row-crit-3-1 th')[0].text
|
||||
== 'Crit 3-1'
|
||||
)
|
||||
assert (
|
||||
resp.pyquery.find('table.pricing-min-matrix-crit-1-2 tr.pricing-row-crit-3-2 th')[0].text
|
||||
== 'Crit 3-2'
|
||||
)
|
||||
assert (
|
||||
resp.pyquery.find('table.pricing-min-matrix-crit-1-2 tr.pricing-row-crit-3-3 th')[0].text
|
||||
== 'Crit 3-3'
|
||||
)
|
||||
assert (
|
||||
resp.pyquery.find('table.pricing-min-matrix-crit-1-2 tr.pricing-row-crit-3-4 th')[0].text
|
||||
== 'Crit 3-4'
|
||||
)
|
||||
assert (
|
||||
resp.pyquery.find(
|
||||
'table.pricing-min-matrix-crit-1-2 tr.pricing-row-crit-3-2 td.pricing-cell-crit-2-2'
|
||||
)[0].text
|
||||
is None
|
||||
) # not defined
|
||||
assert (
|
||||
resp.pyquery.find(
|
||||
'table.pricing-min-matrix-crit-1-2 tr.pricing-row-crit-3-3 td.pricing-cell-crit-2-2'
|
||||
)[0].text
|
||||
== '2.23'
|
||||
)
|
||||
|
||||
|
||||
def test_detail_pricing_2_categories(app, admin_user):
|
||||
category2 = CriteriaCategory.objects.create(label='Cat 2')
|
||||
|
@ -1139,31 +1229,96 @@ def test_detail_pricing_2_categories(app, admin_user):
|
|||
app = login(app)
|
||||
resp = app.get('/manage/pricing/%s/' % pricing.pk)
|
||||
assert len(resp.pyquery.find('div.section.prixing-matrix h3')) == 0
|
||||
ths = resp.pyquery.find('table thead th')
|
||||
ths = resp.pyquery.find('table.pricing-matrix- thead th')
|
||||
assert len(ths) == 4
|
||||
assert ths[0].text is None
|
||||
assert ths[1].text == 'Crit 2-1'
|
||||
assert ths[2].text == 'Crit 2-2'
|
||||
assert ths[3].text == 'Crit 2-3'
|
||||
assert resp.pyquery.find('table tr.pricing-row-crit-3-1 th')[0].text == 'Crit 3-1'
|
||||
assert resp.pyquery.find('table tr.pricing-row-crit-3-2 th')[0].text == 'Crit 3-2'
|
||||
assert resp.pyquery.find('table tr.pricing-row-crit-3-3 th')[0].text == 'Crit 3-3'
|
||||
assert resp.pyquery.find('table tr.pricing-row-crit-3-4 th')[0].text == 'Crit 3-4'
|
||||
assert resp.pyquery.find('table tr.pricing-row-crit-3-1 td.pricing-cell-crit-2-1')[0].text == '111.00'
|
||||
assert resp.pyquery.find('table.pricing-matrix- tr.pricing-row-crit-3-1 th')[0].text == 'Crit 3-1'
|
||||
assert resp.pyquery.find('table.pricing-matrix- tr.pricing-row-crit-3-2 th')[0].text == 'Crit 3-2'
|
||||
assert resp.pyquery.find('table.pricing-matrix- tr.pricing-row-crit-3-3 th')[0].text == 'Crit 3-3'
|
||||
assert resp.pyquery.find('table.pricing-matrix- tr.pricing-row-crit-3-4 th')[0].text == 'Crit 3-4'
|
||||
assert (
|
||||
resp.pyquery.find('table tr.pricing-row-crit-3-2 td.pricing-cell-crit-2-1')[0].text is None
|
||||
resp.pyquery.find('table.pricing-matrix- tr.pricing-row-crit-3-1 td.pricing-cell-crit-2-1')[0].text
|
||||
== '111.00'
|
||||
)
|
||||
assert (
|
||||
resp.pyquery.find('table.pricing-matrix- tr.pricing-row-crit-3-2 td.pricing-cell-crit-2-1')[0].text
|
||||
is None
|
||||
) # not defined
|
||||
assert (
|
||||
resp.pyquery.find('table tr.pricing-row-crit-3-3 td.pricing-cell-crit-2-1')[0].text is None
|
||||
resp.pyquery.find('table.pricing-matrix- tr.pricing-row-crit-3-3 td.pricing-cell-crit-2-1')[0].text
|
||||
is None
|
||||
) # wrong value
|
||||
assert resp.pyquery.find('table tr.pricing-row-crit-3-4 td.pricing-cell-crit-2-1')[0].text == '114.00'
|
||||
assert resp.pyquery.find('table tr.pricing-row-crit-3-2 td.pricing-cell-crit-2-3')[0].text == '132.00'
|
||||
assert (
|
||||
resp.pyquery.find('table.pricing-matrix- tr.pricing-row-crit-3-4 td.pricing-cell-crit-2-1')[0].text
|
||||
== '114.00'
|
||||
)
|
||||
assert (
|
||||
resp.pyquery.find('table.pricing-matrix- tr.pricing-row-crit-3-2 td.pricing-cell-crit-2-3')[0].text
|
||||
== '132.00'
|
||||
)
|
||||
|
||||
pricing.kind = 'effort'
|
||||
pricing.save()
|
||||
resp = app.get('/manage/pricing/%s/' % pricing.pk)
|
||||
assert resp.pyquery.find('table tr.pricing-row-crit-3-2 td.pricing-cell-crit-2-3')[0].text == '132.0000'
|
||||
|
||||
pricing.kind = 'reduction'
|
||||
pricing.min_pricing_data = {
|
||||
'cat-2:crit-2-1': {
|
||||
'cat-3:crit-3-1': 1.11,
|
||||
'cat-3:crit-3-3': 'not-a-decimal',
|
||||
'cat-3:crit-3-4': 1.14,
|
||||
},
|
||||
'cat-2:crit-2-3': {
|
||||
'cat-3:crit-3-2': 1.32,
|
||||
},
|
||||
}
|
||||
pricing.save()
|
||||
resp = app.get('/manage/pricing/%s/' % pricing.pk)
|
||||
ths = resp.pyquery.find('table.pricing-min-matrix- thead th')
|
||||
assert len(ths) == 4
|
||||
assert ths[0].text is None
|
||||
assert ths[1].text == 'Crit 2-1'
|
||||
assert ths[2].text == 'Crit 2-2'
|
||||
assert ths[3].text == 'Crit 2-3'
|
||||
assert resp.pyquery.find('table.pricing-min-matrix- tr.pricing-row-crit-3-1 th')[0].text == 'Crit 3-1'
|
||||
assert resp.pyquery.find('table.pricing-min-matrix- tr.pricing-row-crit-3-2 th')[0].text == 'Crit 3-2'
|
||||
assert resp.pyquery.find('table.pricing-min-matrix- tr.pricing-row-crit-3-3 th')[0].text == 'Crit 3-3'
|
||||
assert resp.pyquery.find('table.pricing-min-matrix- tr.pricing-row-crit-3-4 th')[0].text == 'Crit 3-4'
|
||||
assert (
|
||||
resp.pyquery.find('table.pricing-min-matrix- tr.pricing-row-crit-3-1 td.pricing-cell-crit-2-1')[
|
||||
0
|
||||
].text
|
||||
== '1.11'
|
||||
)
|
||||
assert (
|
||||
resp.pyquery.find('table.pricing-min-matrix- tr.pricing-row-crit-3-2 td.pricing-cell-crit-2-1')[
|
||||
0
|
||||
].text
|
||||
is None
|
||||
) # not defined
|
||||
assert (
|
||||
resp.pyquery.find('table.pricing-min-matrix- tr.pricing-row-crit-3-3 td.pricing-cell-crit-2-1')[
|
||||
0
|
||||
].text
|
||||
is None
|
||||
) # wrong value
|
||||
assert (
|
||||
resp.pyquery.find('table.pricing-min-matrix- tr.pricing-row-crit-3-4 td.pricing-cell-crit-2-1')[
|
||||
0
|
||||
].text
|
||||
== '1.14'
|
||||
)
|
||||
assert (
|
||||
resp.pyquery.find('table.pricing-min-matrix- tr.pricing-row-crit-3-2 td.pricing-cell-crit-2-3')[
|
||||
0
|
||||
].text
|
||||
== '1.32'
|
||||
)
|
||||
|
||||
|
||||
def test_detail_pricing_1_category(app, admin_user):
|
||||
category3 = CriteriaCategory.objects.create(label='Cat 3')
|
||||
|
@ -1188,21 +1343,48 @@ def test_detail_pricing_1_category(app, admin_user):
|
|||
app = login(app)
|
||||
resp = app.get('/manage/pricing/%s/' % pricing.pk)
|
||||
assert len(resp.pyquery.find('div.section.prixing-matrix h3')) == 0
|
||||
ths = resp.pyquery.find('table thead')
|
||||
ths = resp.pyquery.find('table.pricing-matrix- thead')
|
||||
assert len(ths) == 0
|
||||
assert resp.pyquery.find('table tr.pricing-row-crit-3-1 th')[0].text == 'Crit 3-1'
|
||||
assert resp.pyquery.find('table tr.pricing-row-crit-3-2 th')[0].text == 'Crit 3-2'
|
||||
assert resp.pyquery.find('table tr.pricing-row-crit-3-3 th')[0].text == 'Crit 3-3'
|
||||
assert resp.pyquery.find('table tr.pricing-row-crit-3-4 th')[0].text == 'Crit 3-4'
|
||||
assert resp.pyquery.find('table tr.pricing-row-crit-3-1 td')[0].text == '111.00'
|
||||
assert resp.pyquery.find('table tr.pricing-row-crit-3-2 td')[0].text is None # not defined
|
||||
assert resp.pyquery.find('table tr.pricing-row-crit-3-3 td')[0].text is None # wrong value
|
||||
assert resp.pyquery.find('table tr.pricing-row-crit-3-4 td')[0].text == '114.00'
|
||||
assert resp.pyquery.find('table.pricing-matrix- tr.pricing-row-crit-3-1 th')[0].text == 'Crit 3-1'
|
||||
assert resp.pyquery.find('table.pricing-matrix- tr.pricing-row-crit-3-2 th')[0].text == 'Crit 3-2'
|
||||
assert resp.pyquery.find('table.pricing-matrix- tr.pricing-row-crit-3-3 th')[0].text == 'Crit 3-3'
|
||||
assert resp.pyquery.find('table.pricing-matrix- tr.pricing-row-crit-3-4 th')[0].text == 'Crit 3-4'
|
||||
assert resp.pyquery.find('table.pricing-matrix- tr.pricing-row-crit-3-1 td')[0].text == '111.00'
|
||||
assert (
|
||||
resp.pyquery.find('table.pricing-matrix- tr.pricing-row-crit-3-2 td')[0].text is None
|
||||
) # not defined
|
||||
assert (
|
||||
resp.pyquery.find('table.pricing-matrix- tr.pricing-row-crit-3-3 td')[0].text is None
|
||||
) # wrong value
|
||||
assert resp.pyquery.find('table.pricing-matrix- tr.pricing-row-crit-3-4 td')[0].text == '114.00'
|
||||
|
||||
pricing.kind = 'effort'
|
||||
pricing.save()
|
||||
resp = app.get('/manage/pricing/%s/' % pricing.pk)
|
||||
assert resp.pyquery.find('table tr.pricing-row-crit-3-4 td')[0].text == '114.0000'
|
||||
assert resp.pyquery.find('table.pricing-matrix- tr.pricing-row-crit-3-4 td')[0].text == '114.0000'
|
||||
|
||||
pricing.kind = 'reduction'
|
||||
pricing.min_pricing_data = {
|
||||
'cat-3:crit-3-1': 1.11,
|
||||
'cat-3:crit-3-3': 'not-a-decimal',
|
||||
'cat-3:crit-3-4': 1.14,
|
||||
}
|
||||
pricing.save()
|
||||
resp = app.get('/manage/pricing/%s/' % pricing.pk)
|
||||
ths = resp.pyquery.find('table.pricing-min-matrix- thead')
|
||||
assert len(ths) == 0
|
||||
assert resp.pyquery.find('table.pricing-min-matrix- tr.pricing-row-crit-3-1 th')[0].text == 'Crit 3-1'
|
||||
assert resp.pyquery.find('table.pricing-min-matrix- tr.pricing-row-crit-3-2 th')[0].text == 'Crit 3-2'
|
||||
assert resp.pyquery.find('table.pricing-min-matrix- tr.pricing-row-crit-3-3 th')[0].text == 'Crit 3-3'
|
||||
assert resp.pyquery.find('table.pricing-min-matrix- tr.pricing-row-crit-3-4 th')[0].text == 'Crit 3-4'
|
||||
assert resp.pyquery.find('table.pricing-min-matrix- tr.pricing-row-crit-3-1 td')[0].text == '1.11'
|
||||
assert (
|
||||
resp.pyquery.find('table.pricing-min-matrix- tr.pricing-row-crit-3-2 td')[0].text is None
|
||||
) # not defined
|
||||
assert (
|
||||
resp.pyquery.find('table.pricing-min-matrix- tr.pricing-row-crit-3-3 td')[0].text is None
|
||||
) # wrong value
|
||||
assert resp.pyquery.find('table.pricing-min-matrix- tr.pricing-row-crit-3-4 td')[0].text == '1.14'
|
||||
|
||||
|
||||
@mock.patch('lingo.pricing.forms.get_event')
|
||||
|
@ -1604,6 +1786,11 @@ def test_edit_pricing_matrix_3_categories(app, admin_user):
|
|||
)
|
||||
app.get('/manage/pricing/%s/matrix/edit/' % pricing.pk, status=404)
|
||||
|
||||
app.get(
|
||||
'/manage/pricing/%s/matrix/%s/edit/min/' % (pricing.pk, criteria11.slug),
|
||||
status=404,
|
||||
)
|
||||
|
||||
pricing.kind = 'effort'
|
||||
pricing.save()
|
||||
resp = app.get('/manage/pricing/%s/matrix/%s/edit/' % (pricing.pk, criteria11.slug))
|
||||
|
@ -1611,6 +1798,104 @@ def test_edit_pricing_matrix_3_categories(app, admin_user):
|
|||
resp = resp.form.submit()
|
||||
pricing.refresh_from_db()
|
||||
assert pricing.pricing_data['cat-1:crit-1-1']['cat-2:crit-2-1']['cat-3:crit-3-1'] == 111.9999
|
||||
app.get(
|
||||
'/manage/pricing/%s/matrix/%s/edit/min/' % (pricing.pk, criteria11.slug),
|
||||
status=404,
|
||||
)
|
||||
|
||||
pricing.kind = 'reduction'
|
||||
pricing.min_pricing_data = {
|
||||
'cat-1:crit-1-1': {
|
||||
'cat-2:crit-2-1': {
|
||||
'cat-3:crit-3-1': 1.11,
|
||||
'cat-3:crit-3-3': 'not-a-decimal',
|
||||
'cat-3:crit-3-4': 1.14,
|
||||
},
|
||||
'cat-2:crit-2-3': {
|
||||
'cat-3:crit-3-2': 1.32,
|
||||
},
|
||||
},
|
||||
'cat-1:crit-1-2': {
|
||||
'cat-2:crit-2-2': {
|
||||
'cat-3:crit-3-3': 2.23,
|
||||
},
|
||||
},
|
||||
}
|
||||
pricing.save()
|
||||
resp = app.get('/manage/pricing/%s/' % pricing.pk)
|
||||
resp = resp.click(href='/manage/pricing/%s/matrix/%s/edit/min/' % (pricing.pk, criteria11.slug))
|
||||
assert resp.form['form-0-crit_0'].value == '1.11'
|
||||
assert resp.form['form-0-crit_1'].value == ''
|
||||
assert resp.form['form-0-crit_2'].value == ''
|
||||
assert resp.form['form-1-crit_0'].value == ''
|
||||
assert resp.form['form-1-crit_1'].value == ''
|
||||
assert resp.form['form-1-crit_2'].value == '1.32'
|
||||
assert resp.form['form-2-crit_0'].value == ''
|
||||
assert resp.form['form-2-crit_1'].value == ''
|
||||
assert resp.form['form-2-crit_2'].value == ''
|
||||
assert resp.form['form-3-crit_0'].value == '1.14'
|
||||
assert resp.form['form-3-crit_1'].value == ''
|
||||
assert resp.form['form-3-crit_2'].value == ''
|
||||
resp.form['form-0-crit_1'] = '1.21'
|
||||
resp.form['form-0-crit_2'] = '1.31'
|
||||
resp.form['form-1-crit_0'] = '1.12'
|
||||
resp.form['form-1-crit_1'] = '1.22'
|
||||
resp.form['form-1-crit_2'] = '1.32'
|
||||
resp.form['form-2-crit_0'] = '1.13'
|
||||
resp.form['form-2-crit_1'] = '1.23'
|
||||
resp.form['form-2-crit_2'] = '1.33'
|
||||
resp.form['form-3-crit_0'] = '9.14'
|
||||
resp.form['form-3-crit_1'] = '1.24'
|
||||
resp.form['form-3-crit_2'] = '1.34'
|
||||
resp = resp.form.submit()
|
||||
assert resp.location.endswith('/manage/pricing/%s/#open:min-matrix' % pricing.pk)
|
||||
pricing.refresh_from_db()
|
||||
assert pricing.min_pricing_data == {
|
||||
'cat-1:crit-1-1': {
|
||||
'cat-2:crit-2-1': {
|
||||
'cat-3:crit-3-1': 1.11,
|
||||
'cat-3:crit-3-2': 1.12,
|
||||
'cat-3:crit-3-3': 1.13,
|
||||
'cat-3:crit-3-4': 9.14,
|
||||
},
|
||||
'cat-2:crit-2-2': {
|
||||
'cat-3:crit-3-1': 1.21,
|
||||
'cat-3:crit-3-2': 1.22,
|
||||
'cat-3:crit-3-3': 1.23,
|
||||
'cat-3:crit-3-4': 1.24,
|
||||
},
|
||||
'cat-2:crit-2-3': {
|
||||
'cat-3:crit-3-1': 1.31,
|
||||
'cat-3:crit-3-2': 1.32,
|
||||
'cat-3:crit-3-3': 1.33,
|
||||
'cat-3:crit-3-4': 1.34,
|
||||
},
|
||||
},
|
||||
'cat-1:crit-1-2': {
|
||||
'cat-2:crit-2-2': {
|
||||
'cat-3:crit-3-3': 2.23,
|
||||
},
|
||||
},
|
||||
}
|
||||
app.get(
|
||||
'/manage/pricing/%s/matrix/%s/edit/min/' % (pricing.pk, criteria12.slug),
|
||||
status=200,
|
||||
)
|
||||
|
||||
app.get('/manage/pricing/%s/matrix/%s/edit/min/' % (0, criteria11.slug), status=404)
|
||||
app.get(
|
||||
'/manage/pricing/%s/matrix/%s/edit/min/' % (pricing.pk, 'unknown'),
|
||||
status=404,
|
||||
)
|
||||
app.get(
|
||||
'/manage/pricing/%s/matrix/%s/edit/min/' % (pricing.pk, criteria21.slug),
|
||||
status=404,
|
||||
)
|
||||
app.get(
|
||||
'/manage/pricing/%s/matrix/%s/edit/min/' % (pricing.pk, criteria31.slug),
|
||||
status=404,
|
||||
)
|
||||
app.get('/manage/pricing/%s/matrix/edit/min/' % pricing.pk, status=404)
|
||||
|
||||
|
||||
def test_edit_pricing_matrix_2_categories(app, admin_user):
|
||||
|
@ -1703,6 +1988,11 @@ def test_edit_pricing_matrix_2_categories(app, admin_user):
|
|||
status=404,
|
||||
)
|
||||
|
||||
app.get(
|
||||
'/manage/pricing/%s/matrix/edit/min/' % pricing.pk,
|
||||
status=404,
|
||||
)
|
||||
|
||||
pricing.kind = 'effort'
|
||||
pricing.save()
|
||||
resp = app.get('/manage/pricing/%s/matrix/edit/' % pricing.pk)
|
||||
|
@ -1710,6 +2000,81 @@ def test_edit_pricing_matrix_2_categories(app, admin_user):
|
|||
resp = resp.form.submit()
|
||||
pricing.refresh_from_db()
|
||||
assert pricing.pricing_data['cat-2:crit-2-1']['cat-3:crit-3-1'] == 111.9999
|
||||
app.get(
|
||||
'/manage/pricing/%s/matrix/edit/min/' % pricing.pk,
|
||||
status=404,
|
||||
)
|
||||
|
||||
pricing.kind = 'reduction'
|
||||
pricing.min_pricing_data = {
|
||||
'cat-2:crit-2-1': {
|
||||
'cat-3:crit-3-1': 1.11,
|
||||
'cat-3:crit-3-3': 'not-a-decimal',
|
||||
'cat-3:crit-3-4': 1.14,
|
||||
},
|
||||
'cat-2:crit-2-3': {
|
||||
'cat-3:crit-3-2': 1.32,
|
||||
},
|
||||
}
|
||||
pricing.save()
|
||||
resp = app.get('/manage/pricing/%s/' % pricing.pk)
|
||||
resp = resp.click(href='/manage/pricing/%s/matrix/edit/min/' % pricing.pk)
|
||||
assert resp.form['form-0-crit_0'].value == '1.11'
|
||||
assert resp.form['form-0-crit_1'].value == ''
|
||||
assert resp.form['form-0-crit_2'].value == ''
|
||||
assert resp.form['form-1-crit_0'].value == ''
|
||||
assert resp.form['form-1-crit_1'].value == ''
|
||||
assert resp.form['form-1-crit_2'].value == '1.32'
|
||||
assert resp.form['form-2-crit_0'].value == ''
|
||||
assert resp.form['form-2-crit_1'].value == ''
|
||||
assert resp.form['form-2-crit_2'].value == ''
|
||||
assert resp.form['form-3-crit_0'].value == '1.14'
|
||||
assert resp.form['form-3-crit_1'].value == ''
|
||||
assert resp.form['form-3-crit_2'].value == ''
|
||||
resp.form['form-0-crit_1'] = '1.21'
|
||||
resp.form['form-0-crit_2'] = '1.31'
|
||||
resp.form['form-1-crit_0'] = '1.12'
|
||||
resp.form['form-1-crit_1'] = '1.22'
|
||||
resp.form['form-1-crit_2'] = '1.32'
|
||||
resp.form['form-2-crit_0'] = '1.13'
|
||||
resp.form['form-2-crit_1'] = '1.23'
|
||||
resp.form['form-2-crit_2'] = '1.33'
|
||||
resp.form['form-3-crit_0'] = '9.14'
|
||||
resp.form['form-3-crit_1'] = '1.24'
|
||||
resp.form['form-3-crit_2'] = '1.34'
|
||||
resp = resp.form.submit()
|
||||
assert resp.location.endswith('/manage/pricing/%s/#open:min-matrix' % pricing.pk)
|
||||
pricing.refresh_from_db()
|
||||
assert pricing.min_pricing_data == {
|
||||
'cat-2:crit-2-1': {
|
||||
'cat-3:crit-3-1': 1.11,
|
||||
'cat-3:crit-3-2': 1.12,
|
||||
'cat-3:crit-3-3': 1.13,
|
||||
'cat-3:crit-3-4': 9.14,
|
||||
},
|
||||
'cat-2:crit-2-2': {
|
||||
'cat-3:crit-3-1': 1.21,
|
||||
'cat-3:crit-3-2': 1.22,
|
||||
'cat-3:crit-3-3': 1.23,
|
||||
'cat-3:crit-3-4': 1.24,
|
||||
},
|
||||
'cat-2:crit-2-3': {
|
||||
'cat-3:crit-3-1': 1.31,
|
||||
'cat-3:crit-3-2': 1.32,
|
||||
'cat-3:crit-3-3': 1.33,
|
||||
'cat-3:crit-3-4': 1.34,
|
||||
},
|
||||
}
|
||||
|
||||
app.get('/manage/pricing/%s/matrix/edit/min/' % 0, status=404)
|
||||
app.get(
|
||||
'/manage/pricing/%s/matrix/%s/edit/min/' % (pricing.pk, criteria21.slug),
|
||||
status=404,
|
||||
)
|
||||
app.get(
|
||||
'/manage/pricing/%s/matrix/%s/edit/min/' % (pricing.pk, criteria31.slug),
|
||||
status=404,
|
||||
)
|
||||
|
||||
|
||||
def test_edit_pricing_matrix_1_category(app, admin_user):
|
||||
|
@ -1758,6 +2123,8 @@ def test_edit_pricing_matrix_1_category(app, admin_user):
|
|||
status=404,
|
||||
)
|
||||
|
||||
app.get('/manage/pricing/%s/matrix/edit/min/' % pricing.pk, status=404)
|
||||
|
||||
pricing.kind = 'effort'
|
||||
pricing.save()
|
||||
resp = app.get('/manage/pricing/%s/matrix/edit/' % pricing.pk)
|
||||
|
@ -1765,6 +2132,39 @@ def test_edit_pricing_matrix_1_category(app, admin_user):
|
|||
resp = resp.form.submit()
|
||||
pricing.refresh_from_db()
|
||||
assert pricing.pricing_data['cat-3:crit-3-1'] == 111.9999
|
||||
app.get('/manage/pricing/%s/matrix/edit/min/' % pricing.pk, status=404)
|
||||
|
||||
pricing.kind = 'reduction'
|
||||
pricing.min_pricing_data = {
|
||||
'cat-3:crit-3-1': 1.11,
|
||||
'cat-3:crit-3-3': 'not-a-decimal',
|
||||
'cat-3:crit-3-4': 1.14,
|
||||
}
|
||||
pricing.save()
|
||||
resp = app.get('/manage/pricing/%s/' % pricing.pk)
|
||||
resp = resp.click(href='/manage/pricing/%s/matrix/edit/min/' % pricing.pk)
|
||||
assert resp.form['form-0-crit_0'].value == '1.11'
|
||||
assert resp.form['form-1-crit_0'].value == ''
|
||||
assert resp.form['form-2-crit_0'].value == ''
|
||||
assert resp.form['form-3-crit_0'].value == '1.14'
|
||||
resp.form['form-1-crit_0'] = '1.12'
|
||||
resp.form['form-2-crit_0'] = '1.13'
|
||||
resp.form['form-3-crit_0'] = '9.14'
|
||||
resp = resp.form.submit()
|
||||
assert resp.location.endswith('/manage/pricing/%s/#open:min-matrix' % pricing.pk)
|
||||
pricing.refresh_from_db()
|
||||
assert pricing.min_pricing_data == {
|
||||
'cat-3:crit-3-1': 1.11,
|
||||
'cat-3:crit-3-2': 1.12,
|
||||
'cat-3:crit-3-3': 1.13,
|
||||
'cat-3:crit-3-4': 9.14,
|
||||
}
|
||||
|
||||
app.get('/manage/pricing/%s/matrix/edit/min/' % 0, status=404)
|
||||
app.get(
|
||||
'/manage/pricing/%s/matrix/%s/edit/min/' % (pricing.pk, criteria31.slug),
|
||||
status=404,
|
||||
)
|
||||
|
||||
|
||||
def test_edit_pricing_matrix_empty(app, admin_user):
|
||||
|
|
Loading…
Reference in New Issue