0002-lingo-add-default-values-for-TIPI-reference-fields-2.patch
combo/apps/lingo/migrations/0033_auto_20181204_2241.py | ||
---|---|---|
1 |
# -*- coding: utf-8 -*- |
|
2 |
from __future__ import unicode_literals |
|
3 | ||
4 |
from django.db import migrations, models |
|
5 | ||
6 | ||
7 |
class Migration(migrations.Migration): |
|
8 | ||
9 |
dependencies = [ |
|
10 |
('lingo', '0032_basketitem_capture_date'), |
|
11 |
] |
|
12 | ||
13 |
operations = [ |
|
14 |
migrations.AddField( |
|
15 |
model_name='tipipaymentformcell', |
|
16 |
name='exer', |
|
17 |
field=models.CharField(help_text='Default value to be used in form', max_length=4, verbose_name='Exer', blank=True), |
|
18 |
), |
|
19 |
migrations.AddField( |
|
20 |
model_name='tipipaymentformcell', |
|
21 |
name='idligne', |
|
22 |
field=models.CharField(help_text='Default value to be used in form', max_length=6, verbose_name='IDLIGNE', blank=True), |
|
23 |
), |
|
24 |
migrations.AddField( |
|
25 |
model_name='tipipaymentformcell', |
|
26 |
name='idpce', |
|
27 |
field=models.CharField(help_text='Default value to be used in form', max_length=8, verbose_name='IDPCE', blank=True), |
|
28 |
), |
|
29 |
migrations.AddField( |
|
30 |
model_name='tipipaymentformcell', |
|
31 |
name='roldeb', |
|
32 |
field=models.CharField(help_text='Default value to be used in form', max_length=2, verbose_name='ROLDEB', blank=True), |
|
33 |
), |
|
34 |
migrations.AddField( |
|
35 |
model_name='tipipaymentformcell', |
|
36 |
name='roldet', |
|
37 |
field=models.CharField(help_text='Default value to be used in form', max_length=13, verbose_name='ROLDET', blank=True), |
|
38 |
), |
|
39 |
migrations.AddField( |
|
40 |
model_name='tipipaymentformcell', |
|
41 |
name='rolrec', |
|
42 |
field=models.CharField(help_text='Default value to be used in form', max_length=2, verbose_name='ROLREC', blank=True), |
|
43 |
), |
|
44 |
] |
combo/apps/lingo/models.py | ||
---|---|---|
712 | 712 |
url = models.URLField(_('TIPI payment service URL'), default='https://www.tipi.budget.gouv.fr/tpa/paiement.web') |
713 | 713 |
regies = models.CharField(_('Regies'), help_text=_('separated by commas'), max_length=256) |
714 | 714 |
control_protocol = models.CharField(_('Control protocol'), max_length=8, choices=TIPI_CONTROL_PROCOTOLS, default='pesv2') |
715 |
exer = models.CharField(_('Exer'), max_length=4, blank=True, help_text=_('Default value to be used in form')) |
|
716 |
idpce = models.CharField(_('IDPCE'), max_length=8, blank=True, help_text=_('Default value to be used in form')) |
|
717 |
idligne = models.CharField(_('IDLIGNE'), max_length=6, blank=True, help_text=_('Default value to be used in form')) |
|
718 |
rolrec = models.CharField(_('ROLREC'), max_length=2, blank=True, help_text=_('Default value to be used in form')) |
|
719 |
roldeb = models.CharField(_('ROLDEB'), max_length=2, blank=True, help_text=_('Default value to be used in form')) |
|
720 |
roldet = models.CharField(_('ROLDET'), max_length=13, blank=True, help_text=_('Default value to be used in form')) |
|
715 | 721 |
test_mode = models.BooleanField(_('Test mode'), default=False) |
716 | 722 |
template_name = 'lingo/tipi_form.html' |
723 |
manager_form_template = 'combo/tipi_cell_form.html' |
|
717 | 724 | |
718 | 725 |
class Meta: |
719 | 726 |
verbose_name = _('TIPI Payment Form') |
... | ... | |
723 | 730 | |
724 | 731 |
def get_cell_extra_context(self, context): |
725 | 732 |
extra_context = super(TipiPaymentFormCell, self).get_cell_extra_context(context) |
733 |
form_fields = self.get_default_form_class().base_fields |
|
734 |
field_definitions = ({'protocol': 'any', 'fields': ['exer']}, |
|
735 |
{'protocol': 'pesv2', 'fields': ['idligne', 'idpce']}, |
|
736 |
{'protocol': 'rolmre', 'fields': ['rolrec', 'roldeb', 'roldet']} |
|
737 |
) |
|
738 |
reference_fields = [] |
|
739 |
for definition in field_definitions: |
|
740 |
for field in definition['fields']: |
|
741 |
field_pattern = '[0-9]+' |
|
742 |
# special pattern for rolrec |
|
743 |
if field == 'rolrec': |
|
744 |
field_pattern = '[A-Z0-9]+' |
|
745 |
reference_fields.append({'name': field, 'length': form_fields[field].max_length, |
|
746 |
'placeholder': '0'*form_fields[field].max_length, |
|
747 |
'pattern': field_pattern, |
|
748 |
'protocol': definition['protocol']}) |
|
726 | 749 |
context['title'] = self.title |
727 | 750 |
context['url'] = self.url |
728 | 751 |
context['mode'] = 'T' if self.test_mode else 'M' |
729 |
context['pesv2'] = (self.control_protocol == 'pesv2')
|
|
752 |
context['control_protocol'] = self.control_protocol
|
|
730 | 753 |
context['regies'] = [] |
754 |
for field in reference_fields: |
|
755 |
if getattr(self, field['name']): |
|
756 |
field['default'] = getattr(self, field['name']) |
|
757 |
context['reference_fields'] = reference_fields |
|
731 | 758 |
for regie in self.regies.split(','): |
732 | 759 |
regie_id = regie.strip() |
733 | 760 |
if not regie_id: |
combo/apps/lingo/templates/lingo/tipi_form.html | ||
---|---|---|
24 | 24 |
</ul> |
25 | 25 |
<p> |
26 | 26 |
<label>{% trans "Reference" %}</label> |
27 |
<input type="text" id="exer" required pattern="[0-9]+" maxlength="4" size="4" placeholder="0000" /> - |
|
28 |
{% if pesv2 %} |
|
29 |
<input type="text" id="idpce" required pattern="[0-9]+" maxlength="8" size="8" placeholder="00000000" /> - |
|
30 |
<input type="text" id="idligne" required pattern="[0-9]+" maxlength="6" size="6" placeholder="000000" /> |
|
31 |
{% else %} |
|
32 |
<input type="text" id="rolrec" required pattern="[A-Z0-9]+" maxlength="2" size="2" placeholder="00" /> - |
|
33 |
<input type="text" id="roldeb" required pattern="[0-9]+" maxlength="2" size="2" placeholder="00" /> - |
|
34 |
<input type="text" id="roldet" required pattern="[0-9]+" maxlength="13" size="13" placeholder="0000000000000" /> |
|
27 |
{% regroup reference_fields by protocol as fields %} |
|
28 |
{% for field in fields %} |
|
29 |
{% for f in field.list %} |
|
30 |
{% if field.grouper == control_protocol or field.grouper == 'any' %} |
|
31 |
<input type="text" id="{{ f.name }}" required pattern="{{ f.pattern }}" maxlength="{{ f.length }}" size="{{ f.length }}" placeholder="{{ f.placeholder }}" {% if f.default %}value="{{ f.default }}" readonly {% endif %}/>{% if field.grouper == 'any' or not forloop.last %} - {% endif %} |
|
35 | 32 |
{% endif %} |
33 |
{% endfor %} |
|
34 |
{% endfor %} |
|
36 | 35 |
</p> |
37 | 36 |
<ul class="errorlist" id="montant_error" style="display: none"> |
38 | 37 |
<li>{% trans "invalid amount" %}</li> |
combo/manager/templates/combo/tipi_cell_form.html | ||
---|---|---|
1 |
{% extends "combo/cell_form.html" %} |
|
2 |
{% block cell-edit-form %} |
|
3 |
{{ block.super }} |
|
4 |
<script type="text/javascript"> |
|
5 |
function handle_tipi_protocol_fields_display() { |
|
6 |
var $control_element = $('[name=c{{ cell.get_reference }}-control_protocol]'); |
|
7 |
function hide_fields(fields) { |
|
8 |
fields.forEach(function(f) { |
|
9 |
$("[name=c{{ cell.get_reference }}-" + f + "]").parent().hide(); |
|
10 |
}); |
|
11 |
} |
|
12 |
function show_fields(fields) { |
|
13 |
fields.forEach(function(f) { |
|
14 |
$("[name=c{{ cell.get_reference }}-" + f + "]").parent().show(); |
|
15 |
}) |
|
16 |
} |
|
17 |
$control_element.on('change', function() { |
|
18 |
if ($control_element.val() == 'pesv2') { |
|
19 |
show_fields(['idpce', 'idligne']); |
|
20 |
hide_fields(['rolrec', 'roldeb', 'roldet']); |
|
21 |
} else { |
|
22 |
show_fields(['rolrec', 'roldeb', 'roldet']); |
|
23 |
hide_fields(['idpce', 'idligne']); |
|
24 |
} |
|
25 |
}); |
|
26 |
$control_element.trigger('change'); |
|
27 |
}; |
|
28 |
handle_tipi_protocol_fields_display(); |
|
29 |
</script> |
|
30 |
{% endblock %} |
tests/test_lingo_cells.py | ||
---|---|---|
199 | 199 |
html = cell.render({}) |
200 | 200 |
assert "Community identifier" in html |
201 | 201 |
assert '<select id="numcli">' in html |
202 | ||
203 |
# set reference default values and check they are filled and readonly |
|
204 |
cell.exer = '1234' |
|
205 |
cell.rolrec = '00' |
|
206 |
cell.save() |
|
207 |
html = cell.render({}) |
|
208 |
assert 'value="1234" readonly' in html |
|
209 |
assert 'value="00" readonly' in html |
tests/test_lingo_manager.py | ||
---|---|---|
10 | 10 | |
11 | 11 |
import eopayment |
12 | 12 |
from combo.data.models import Page |
13 |
from combo.apps.lingo.models import Regie, BasketItem, Transaction, ActiveItems |
|
13 |
from combo.apps.lingo.models import Regie, BasketItem, Transaction, ActiveItems, TipiPaymentFormCell
|
|
14 | 14 |
from decimal import Decimal |
15 | 15 | |
16 | 16 |
pytestmark = pytest.mark.django_db |
... | ... | |
155 | 155 |
assert resp.text.count('<tr') == 0 |
156 | 156 |
assert 'No transactions found matching' in resp.text |
157 | 157 | |
158 |
def test_configure_tipi_cell(app, admin_user): |
|
159 |
page = Page(title='tipi', slug='tipi', template_name='standard') |
|
160 |
page.save() |
|
161 | ||
162 |
app = login(app) |
|
163 |
resp = app.get('/manage/pages/%s/' % page.id, status=200) |
|
164 | ||
165 |
cell = TipiPaymentFormCell(title='Test payment', page=page, placeholder='content', order=0) |
|
166 |
cell.save() |
|
167 |
resp = app.get('/manage/pages/%s/' % page.id, status=200) |
|
168 |
assert resp.text.count('Exer:') == 1 |
|
169 |
assert resp.text.count('IDPCE:') == 1 |
|
170 |
assert resp.text.count('IDLIGNE:') == 1 |
|
171 |
assert resp.text.count('ROLREC:') == 1 |
|
172 |
assert resp.text.count('ROLDEB:') == 1 |
|
173 |
assert resp.text.count('ROLDET:') == 1 |
|
174 |
assert resp.text.count('handle_tipi_protocol_fields_display') == 1 |
|
175 | ||
158 | 176 |
def test_configure_invoices_cell(app, admin_user): |
159 | 177 |
page = Page(title='xxx', slug='test', template_name='standard') |
160 | 178 |
page.save() |
... | ... | |
165 | 183 |
# 2 occurences of tipi payment form should be present, and no other cells |
166 | 184 |
assert resp.text.count('lingo') == 2 |
167 | 185 |
assert resp.text.count('lingo_tipipaymentformcell') == 2 |
186 |
assert resp.text.count('lingo_tipipaymentformcell') == 2 |
|
168 | 187 | |
169 | 188 |
regie = Regie() |
170 | 189 |
regie.label = 'Test' |
171 |
- |