django-picklefield
pygraphviz
simplejson
+ ordereddict
[django]
recipe = auf.recipe.django
.pagination { text-align: center; }
table.listing { width: 100%; }
.print-only { display: none; }
+.total-row th { background-color: #C7D1D8; }
\ No newline at end of file
# -*- encoding: utf-8 -*-
import datetime
+from ordereddict import OrderedDict
from django import forms
from django.core.urlresolvers import reverse
from django.forms.models import BaseInlineFormSet
else:
return devise
+ def has_changed(self):
+ """
+ Modification de has_changed pour qu'il ignore les montant a 0
+ et les 'types'.
+ """
+
+ changed_data = self.changed_data
+
+ # Type is set in hidden fields, it shouldn't be changed by the
+ # user; ignore when checking if data has changed.
+ if 'type' in changed_data:
+ changed_data.pop(changed_data.index('type'))
+
+ # Montant is set to 0 in javascript, ifnore 'montant' data if
+ # its value is 0.
+
+ # Generer le key tel qu'identifié dans self.data:
+ montant_key = '-'.join((self.prefix, 'montant'))
+
+ if ('montant' in changed_data and
+ self.data.get(montant_key, '0') == '0'):
+ changed_data.pop(changed_data.index('montant'))
+
+ return bool(changed_data)
+
class GroupedInlineFormset(BaseInlineFormSet):
- def set_groups(self, group_accessor):
+ def set_groups(self, group_accessor, group_order=[]):
"""
group_accessor: A function that will get the key and name from
each form.
+ group_order: list the group keys here in a list and
+ GroupedInlineFormset.groups will be ordered (ordereddict) by
+ the key sequence provided here. Any missing key from the
+ sequence will
"""
# Build group list.
- self.groups = {}
+ self.groups = OrderedDict()
+ temp_groups = {}
# self.groups_and_forms = []
for form in self.forms:
group_key, group_name = group_accessor(form)
- if not self.groups.has_key(group_key):
- self.groups[group_key] = {
+ if not temp_groups.has_key(group_key):
+ temp_groups[group_key] = {
'name': group_name,
+ 'key': group_key,
'forms': [],
}
- self.groups[group_key]['forms'].append(form)
+ temp_groups[group_key]['forms'].append(form)
+
+ for order_key in group_order:
+ if temp_groups.has_key(order_key):
+ self.groups[order_key] = temp_groups.pop(order_key)
+
+ for key in temp_groups:
+ self.groups[key] = temp_groups[key]
+
+ del temp_groups
+
self.group_list = self.groups.values()
can_order=False,
can_delete=True,
max_num=None,
- formfield_callback=None):
- """
- Returns an ``InlineFormSet`` for the given kwargs.
-
- You must provide ``fk_name`` if ``model`` has more than one ``ForeignKey``
- to ``parent_model``.
- """
+ formfield_callback=None,
+ group_order=None):
trs = rh.TypeRemuneration.objects.all()
extra = max_num = trs.count()
fk = _get_foreign_key(parent_model, model, fk_name=fk_name)
}
# Set form grouping.
- inst.set_groups(grouper)
+ inst.set_groups(grouper, group_order)
FormSet.__init__ = __init__
RemunForm = remun_formset_factory(
- dae.Dossier, dae.Remuneration, form=FlexibleRemunForm
+ dae.Dossier,
+ dae.Remuneration,
+ form=FlexibleRemunForm,
+ group_order = [
+ u'Traitement',
+ u'Indemnité',
+ u'Charges',
+ u'Accessoire',
+ ]
)
<th>Supprimer</th>
</tr>
{% for group in remunForm.group_list %}
+{% if group.name != 'RAS' %}
<tr>
<th colspan="6">{{ group.name }}</th>
</tr>
<td class="sous-total"></td>
<td colspan="2"></td>
</tr>
+{% endif %}
{% endfor %}
-<tr>
+<tr class="total-row">
<th><strong>Total</strong></th>
<th><!-- Laisser ce td pour que le javascript fonctionne bien. --></th>
<th class="total"></th>
<th class="total"></th>
<th colspan="2"></th>
</tr>
-</table>
-
-{% comment %}
-<table>
-<tr>
- <th>Type</th>
- <th>Devise locale</th>
- <th>Mensuel</th>
- <th>Annuel</th>
- <th colspan="2">Conversion en Euros</th>
- <th>Précision</th>
-</tr>
<tr>
- <th colspan="5">Coûts AUF</th>
- <th id="sous-total-cout" class="montant"></th>
- <th>EUR</th>
+ <th><strong>Rémunération autre source</strong></th>
+ <th><!-- Laisser ce td pour que le javascript fonctionne bien. --></th>
+ <th></th>
+ <th></th>
+ <th colspan="2"></th>
</tr>
-
-{% for remun in dossier.get_couts_auf %}
- <tr class="cout">
- <td>{{ remun.type }}</td>
- <td>
- {{ remun.devise }}
- <input type="hidden" id="taux_devise-{{ remun.id }}"
- name="taux_devise-{{ remun.id }}"
- value="{{ remun.taux_devise }}" />
- </td>
- <td>
- <input type="text" id="montant_mois-{{ remun.id }}"
- name="montant_mois-{{ remun.id }}"
- value="{{ remun.montant_mois }}" />
- </td>
- <td><input type="text" id="montant-{{ remun.id }}"
- name="cg-montant-{{ remun.id }}"
- value="{{ remun.montant|default_if_none:'' }}" />
- </td>
- <td id="montant_euro_mois-{{ remun.id }}" class="montant">
- {{ remun.montant_euro_mois }}</td>
- <td id="montant_euro-{{ remun.id }}" class="montant cumulable">{{ remun.montant_euros }}</td>
- <td><input type="text" name="cg-precision-{{ remun.id }}"
- value="{{ remun.precision|default_if_none:'' }}" /></td>
- </tr>
-{% empty %}
- <tr>
- <td colspan="6">
- Aucun coût au registre
- </td>
- </tr>
-{% endfor %}
-
-
-<tr>
- <th colspan="5">BSTG - Salaire de mise à disposition</th>
- <th id="sous-total-aide" class="montant"></th>
- <th>EUR</th>
+{% for f in remunForm.groups.RAS.forms %}
+<tr class="calculable">
+ {{ f.id }}
+ <td>{{ f.type.errors }} {{ f.type }}</td>
+ <td>{{ f.devise.errors }} {{ f.devise }}</td>
+ <td class="monnaie cumulable">{{ f.montant.errors }} {{ f.montant }}</td>
+ <td class="euro cumulable" id="id_{{ f.prefix }}-montant_annuel_euros"></td>
+ <td>{{ f.commentaire.errors }} {{ f.commentaire }}</td>
+ <td>{{ f.DELETE }}</td>
</tr>
-
-{% for remun in dossier.get_aides_auf %}
- <tr class="aide">
- <td>{{ remun.type }}</td>
- <td>
- {{ remun.devise }}
- <input type="hidden" id="taux_devise-{{ remun.id }}"
- name="taux_devise-{{ remun.id }}"
- value="{{ remun.taux_devise }}" />
- </td>
- <td>
- <input type="text" id="montant_mois-{{ remun.id }}"
- name="montant_mois-{{ remun.id }}"
- value="{{ remun.montant_mois }}" />
- </td>
- <td><input type="text" id="montant-{{ remun.id }}"
- name="cg-montant-{{ remun.id }}"
- value="{{ remun.montant|default_if_none:'' }}" />
- </td>
- <td id="montant_euro_mois-{{ remun.id }}" class="montant">
- {{ remun.montant_euro_mois }}</td>
- <td id="montant_euro-{{ remun.id }}" class="montant cumulable">{{ remun.montant_euros }}</td>
- <td><input type="text" name="cg-precision-{{ remun.id }}"
- value="{{ remun.precision|default_if_none:'' }}" /></td>
- </tr>
-{% empty %}
- <tr>
- <td colspan="6">
- Aucun coût au registre
- </td>
- </tr>
{% endfor %}
-
-<tr>
- <th colspan="5">TOTAL</th>
- <th id="remun-total" class="montant"></th>
- <th>EUR</th>
+<tr class="sous-totaux">
+ <td>Sous-total</td>
+ <td><!-- Laisser ce td pour que le javascript fonctionne bien. --></td>
+ <td class="sous-total"></td>
+ <td class="sous-total"></td>
+ <td colspan="2"></td>
</tr>
-{% endcomment %}
+</table>
class ReadOnlyChoiceWidget(Select):
def render(self, name, value, attrs=None, choices=()):
+ try:
+ key = long(value)
+ except ValueError:
+ key = ''
return mark_safe(
'<span>%(display)s</span><input type="hidden" '
'name="%(name)s" value="%(value)s" />' % {
- 'display': dict(self.choices)[value],
+ 'display': dict(self.choices)[key],
'name': name,
'value': value,
})
)
NATURE_REMUNERATION_CHOICES = (
- (u'Accessoire', u'Accessoire'),
- (u'Charges', u'Charges'),
+ (u'Accessoire', u'Traitement ponctuel'),
+ (u'Charges', u'Charges patronales'),
(u'Indemnité', u'Indemnité'),
(u'RAS', u'Rémunération autre source'),
(u'Traitement', u'Traitement'),
)
+# class NatureRemuneration(models.Model):
+# nom = models.CharField(64)
+# ordre = models.IntegerField(default=0)
+
+
class TypeRemuneration(Archivable):
"""
Catégorie de Remuneration.
type_paiement = models.CharField(
u"type de paiement", max_length=30, choices=TYPE_PAIEMENT_CHOICES
)
+
nature_remuneration = models.CharField(
u"nature de la rémunération", max_length=30,
choices=NATURE_REMUNERATION_CHOICES