pricing: display agenda pricing matrix on detail page (#65053)
This commit is contained in:
parent
35600c2952
commit
f4920fd7f3
|
@ -22,4 +22,35 @@
|
|||
{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
{% for matrix in object.iter_pricing_matrix %}
|
||||
<div class="section">
|
||||
{% if matrix.criteria %}<h3>{{ matrix.criteria.label }}</h3>{% endif %}
|
||||
<div>
|
||||
<table class="main pricing-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 }}">{{ cell.value|floatformat:"2"|default_if_none:"" }}</td>{% endfor %}
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
{% empty %}
|
||||
<div class="big-msg-info">
|
||||
{% blocktrans %}
|
||||
This pricing model is misconfigured.
|
||||
{% endblocktrans %}
|
||||
</div>
|
||||
{% endfor %}
|
||||
{% endblock %}
|
||||
|
|
|
@ -513,7 +513,9 @@ class AgendaPricingDetailView(ViewableAgendaMixin, DetailView):
|
|||
self.agenda = get_object_or_404(Agenda, pk=kwargs.get('pk'), kind='events')
|
||||
|
||||
def get_queryset(self):
|
||||
return AgendaPricing.objects.filter(agenda=self.agenda)
|
||||
return AgendaPricing.objects.filter(agenda=self.agenda).prefetch_related(
|
||||
'pricing__criterias__category'
|
||||
)
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
kwargs['user_can_manage'] = self.agenda.can_be_managed(self.request.user)
|
||||
|
|
|
@ -978,3 +978,210 @@ def test_detail_agenda_pricing(app, admin_user):
|
|||
agenda.kind = kind
|
||||
agenda.save()
|
||||
app.get('/manage/pricing/agenda/%s/pricing/%s/' % (agenda.pk, agenda_pricing.pk), status=404)
|
||||
|
||||
|
||||
def test_detail_agenda_pricing_3_categories(app, admin_user):
|
||||
category1 = CriteriaCategory.objects.create(label='Cat 1')
|
||||
Criteria.objects.create(label='Crit 1-1', slug='crit-1-1', category=category1, order=1)
|
||||
Criteria.objects.create(label='Crit 1-2', slug='crit-1-2', category=category1, order=2)
|
||||
category2 = CriteriaCategory.objects.create(label='Cat 2')
|
||||
Criteria.objects.create(label='Crit 2-1', slug='crit-2-1', category=category2, order=1)
|
||||
Criteria.objects.create(label='Crit 2-2', slug='crit-2-2', category=category2, order=2)
|
||||
Criteria.objects.create(label='Crit 2-3', slug='crit-2-3', category=category2, order=3)
|
||||
category3 = CriteriaCategory.objects.create(label='Cat 3')
|
||||
Criteria.objects.create(label='Crit 3-1', slug='crit-3-1', category=category3, order=1)
|
||||
Criteria.objects.create(label='Crit 3-3', slug='crit-3-3', category=category3, order=3)
|
||||
Criteria.objects.create(label='Crit 3-4', slug='crit-3-4', category=category3, order=4)
|
||||
Criteria.objects.create(label='Crit 3-2', slug='crit-3-2', category=category3, order=2)
|
||||
|
||||
agenda = Agenda.objects.create(label='Foo bar', kind='events')
|
||||
pricing = Pricing.objects.create(label='Foo bar')
|
||||
pricing.categories.add(category1, through_defaults={'order': 1})
|
||||
pricing.categories.add(category2, through_defaults={'order': 2})
|
||||
pricing.categories.add(category3, through_defaults={'order': 3})
|
||||
pricing.criterias.set(Criteria.objects.all())
|
||||
agenda_pricing = AgendaPricing.objects.create(
|
||||
agenda=agenda,
|
||||
pricing=pricing,
|
||||
date_start=datetime.date(year=2021, month=9, day=1),
|
||||
date_end=datetime.date(year=2021, month=10, day=1),
|
||||
pricing_data={
|
||||
'cat-1:crit-1-1': {
|
||||
'cat-2:crit-2-1': {
|
||||
'cat-3:crit-3-1': 111,
|
||||
'cat-3:crit-3-3': 'not-a-decimal',
|
||||
'cat-3:crit-3-4': 114,
|
||||
},
|
||||
'cat-2:crit-2-3': {
|
||||
'cat-3:crit-3-2': 132,
|
||||
},
|
||||
},
|
||||
'cat-1:crit-1-2': {
|
||||
'cat-2:crit-2-2': {
|
||||
'cat-3:crit-3-3': 223,
|
||||
},
|
||||
},
|
||||
},
|
||||
)
|
||||
|
||||
app = login(app)
|
||||
resp = app.get('/manage/pricing/agenda/%s/pricing/%s/' % (agenda.pk, agenda_pricing.pk))
|
||||
assert '<h3>Crit 1-1</h3>' in resp
|
||||
ths = resp.pyquery.find('table.pricing-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-matrix-crit-1-1 tr.pricing-row-crit-3-1 th')[0].text == 'Crit 3-1'
|
||||
assert resp.pyquery.find('table.pricing-matrix-crit-1-1 tr.pricing-row-crit-3-2 th')[0].text == 'Crit 3-2'
|
||||
assert resp.pyquery.find('table.pricing-matrix-crit-1-1 tr.pricing-row-crit-3-3 th')[0].text == 'Crit 3-3'
|
||||
assert resp.pyquery.find('table.pricing-matrix-crit-1-1 tr.pricing-row-crit-3-4 th')[0].text == 'Crit 3-4'
|
||||
assert (
|
||||
resp.pyquery.find('table.pricing-matrix-crit-1-1 tr.pricing-row-crit-3-1 td.pricing-cell-crit-2-1')[
|
||||
0
|
||||
].text
|
||||
== '111.00'
|
||||
)
|
||||
assert (
|
||||
resp.pyquery.find('table.pricing-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-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-matrix-crit-1-1 tr.pricing-row-crit-3-4 td.pricing-cell-crit-2-1')[
|
||||
0
|
||||
].text
|
||||
== '114.00'
|
||||
)
|
||||
assert (
|
||||
resp.pyquery.find('table.pricing-matrix-crit-1-1 tr.pricing-row-crit-3-2 td.pricing-cell-crit-2-3')[
|
||||
0
|
||||
].text
|
||||
== '132.00'
|
||||
)
|
||||
assert '<h3>Crit 1-2</h3>' in resp
|
||||
ths = resp.pyquery.find('table.pricing-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-matrix-crit-1-2 tr.pricing-row-crit-3-1 th')[0].text == 'Crit 3-1'
|
||||
assert resp.pyquery.find('table.pricing-matrix-crit-1-2 tr.pricing-row-crit-3-2 th')[0].text == 'Crit 3-2'
|
||||
assert resp.pyquery.find('table.pricing-matrix-crit-1-2 tr.pricing-row-crit-3-3 th')[0].text == 'Crit 3-3'
|
||||
assert resp.pyquery.find('table.pricing-matrix-crit-1-2 tr.pricing-row-crit-3-4 th')[0].text == 'Crit 3-4'
|
||||
assert (
|
||||
resp.pyquery.find('table.pricing-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-matrix-crit-1-2 tr.pricing-row-crit-3-3 td.pricing-cell-crit-2-2')[
|
||||
0
|
||||
].text
|
||||
== '223.00'
|
||||
)
|
||||
|
||||
|
||||
def test_detail_agenda_pricing_2_categories(app, admin_user):
|
||||
category2 = CriteriaCategory.objects.create(label='Cat 2')
|
||||
Criteria.objects.create(label='Crit 2-1', slug='crit-2-1', category=category2, order=1)
|
||||
Criteria.objects.create(label='Crit 2-2', slug='crit-2-2', category=category2, order=2)
|
||||
Criteria.objects.create(label='Crit 2-3', slug='crit-2-3', category=category2, order=3)
|
||||
category3 = CriteriaCategory.objects.create(label='Cat 3')
|
||||
Criteria.objects.create(label='Crit 3-1', slug='crit-3-1', category=category3, order=1)
|
||||
Criteria.objects.create(label='Crit 3-3', slug='crit-3-3', category=category3, order=3)
|
||||
Criteria.objects.create(label='Crit 3-4', slug='crit-3-4', category=category3, order=4)
|
||||
Criteria.objects.create(label='Crit 3-2', slug='crit-3-2', category=category3, order=2)
|
||||
|
||||
agenda = Agenda.objects.create(label='Foo bar', kind='events')
|
||||
pricing = Pricing.objects.create(label='Foo bar')
|
||||
pricing.categories.add(category2, through_defaults={'order': 2})
|
||||
pricing.categories.add(category3, through_defaults={'order': 3})
|
||||
pricing.criterias.set(Criteria.objects.all())
|
||||
agenda_pricing = AgendaPricing.objects.create(
|
||||
agenda=agenda,
|
||||
pricing=pricing,
|
||||
date_start=datetime.date(year=2021, month=9, day=1),
|
||||
date_end=datetime.date(year=2021, month=10, day=1),
|
||||
pricing_data={
|
||||
'cat-2:crit-2-1': {
|
||||
'cat-3:crit-3-1': 111,
|
||||
'cat-3:crit-3-3': 'not-a-decimal',
|
||||
'cat-3:crit-3-4': 114,
|
||||
},
|
||||
'cat-2:crit-2-3': {
|
||||
'cat-3:crit-3-2': 132,
|
||||
},
|
||||
},
|
||||
)
|
||||
|
||||
app = login(app)
|
||||
resp = app.get('/manage/pricing/agenda/%s/pricing/%s/' % (agenda.pk, agenda_pricing.pk))
|
||||
assert '<h3>' not in resp
|
||||
ths = resp.pyquery.find('table 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 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
|
||||
) # 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'
|
||||
|
||||
|
||||
def test_detail_agenda_pricing_1_category(app, admin_user):
|
||||
category3 = CriteriaCategory.objects.create(label='Cat 3')
|
||||
Criteria.objects.create(label='Crit 3-1', slug='crit-3-1', category=category3, order=1)
|
||||
Criteria.objects.create(label='Crit 3-3', slug='crit-3-3', category=category3, order=3)
|
||||
Criteria.objects.create(label='Crit 3-4', slug='crit-3-4', category=category3, order=4)
|
||||
Criteria.objects.create(label='Crit 3-2', slug='crit-3-2', category=category3, order=2)
|
||||
|
||||
agenda = Agenda.objects.create(label='Foo bar', kind='events')
|
||||
pricing = Pricing.objects.create(label='Foo bar')
|
||||
pricing.categories.add(category3, through_defaults={'order': 3})
|
||||
pricing.criterias.set(Criteria.objects.all())
|
||||
agenda_pricing = AgendaPricing.objects.create(
|
||||
agenda=agenda,
|
||||
pricing=pricing,
|
||||
date_start=datetime.date(year=2021, month=9, day=1),
|
||||
date_end=datetime.date(year=2021, month=10, day=1),
|
||||
pricing_data={
|
||||
'cat-3:crit-3-1': 111,
|
||||
'cat-3:crit-3-3': 'not-a-decimal',
|
||||
'cat-3:crit-3-4': 114,
|
||||
},
|
||||
)
|
||||
|
||||
app = login(app)
|
||||
resp = app.get('/manage/pricing/agenda/%s/pricing/%s/' % (agenda.pk, agenda_pricing.pk))
|
||||
assert '<h3>' not in resp
|
||||
ths = resp.pyquery.find('table 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'
|
||||
|
|
Loading…
Reference in New Issue