Merge remote branch 'origin/dev' into dae
authorNicolas Cadou <ncadou@cadou.ca>
Fri, 8 Apr 2011 04:55:55 +0000 (00:55 -0400)
committerNicolas Cadou <ncadou@cadou.ca>
Fri, 8 Apr 2011 04:55:55 +0000 (00:55 -0400)
Conflicts:
project/dae/templates/dae/embauche.html

1  2 
project/dae/models.py
project/dae/templates/dae/embauche.html
project/dae/views.py
project/rh_v1/models.py

Simple merge
          function loadEmploye() {
              var employeUrl = '{% url employe %}/' + $(this).val();
              $('#form-employe').html('<tr><td>Chargement...</td></tr>')
-                               .load(employeUrl, activateEmployeDropDown);
+                 .load(employeUrl, activateEmployeDropDown);
              var dossierUrl = '{% url dossier %}/' + $('#poste').val() +
-                              '/' + $(this).val();
+                 '/' + $(this).val();
              $('#form-dossier').html('<tr><td>Chargement...</td></tr>')
-                               .load(dossierUrl, activateDossierDropDowns);
+                 .load(dossierUrl, activateDossierDropDowns);
          }
          activateEmployeDropDown();
 -    </script>
 -    
 -    {% with forms.dossier as form %}
 +      </script>
 +
-       <h2>Dossier</h2>
-       <table cellspacing="0" id="form-dossier">
-         {{ forms.dossier.as_table }}
-       </table>
++      {% with forms.dossier as form %}
+         {% include "dae/embauche-dossier.html" %}
 -    {% endwith %}
 -    
 -    <h2 class="section">SECTION 3 - COÛT GLOBAL</h2>
 -    
 -    <h2 class="section">SECTION 4 - JUSTIFICATION DE LA DEMANDE (OBLIGATOIRE)</h2>
++      {% endwith %}
+     
 -    <input type="submit" name="save" value="Sauvegarder" />
 -{% endif %}
 -</form>
 +      <script type="text/javascript">
 +        function activateDossierDropDowns() {
 +            $('#id_classement, #id_devise').change(loadSalaire);
 +        }
 +
 +        function loadSalaire() {
 +            $.getJSON('{% url salaire %}/' + $('#implantation').val() + '/' +
 +                      $('#id_devise').val() + '/' + $('#id_classement').val(),
 +              function(data) {
 +                console.log(data);
 +                $('#id_salaire').val(data.salaire_devise);
 +              });
 +        }
 +
 +        activateDossierDropDowns();
 +      </script>
 +
++      <h2 class="section">SECTION 3 - COÛT GLOBAL</h2>
++
 +      <fieldset>
-         <h2>Coût global</h2>
 +
 +        {% if new %}
 +          <p>
 +            Vous devez enregister ce dossier avant de pouvoir détailler le
 +            coût global.
 +          </p>
 +        {% else %}
 +          <table cellspacing="0" id="global-cost">
 +            {% include 'dae/embauche-remun.html' %}
 +          </table>
 +
 +          <select id="type-remun" name="type-remun">
 +            <option value="">(Ajouter une ligne)</option>
 +            {% for tr in type_remun %}
 +              <option value="{{ tr.id }}">{{ tr.nom }}</option>
 +            {% endfor %}
 +          </select>
 +        {% endif %}
 +
 +      </fieldset>
 +
++      <h2 class="section">SECTION 4 - JUSTIFICATION DE LA DEMANDE (OBLIGATOIRE)</h2>
++
 +      <input type="submit" name="save" value="Sauvegarder" />
 +    </form>
 +    <script type="text/javascript">
 +        $('#type-remun').change(function() {
 +            if ($(this).val() != '') {
 +                $('#global-cost').html('<tr><td>Chargement...</td></tr>')
 +                                 .load('{% url add_remun %}/' +
 +                                       $('#dossier').val() + '/' +
 +                                       $(this).val(), function() {
 +                    $('#type-remun').val('');
 +                });
 +            }
 +        });
 +    </script>
 +  {% endif %}
  {% endblock %}
  
@@@ -164,34 -158,8 +168,35 @@@ def embauche(request, key=None, dossier
                  else:
                      dossier = get_object_or_404(dae.Dossier, pk=dossier)
                  dossier_form = DossierForm(request.POST, instance=dossier)
 +
++                #import ipdb; ipdb.set_trace()
                  if dossier_form.is_valid():
                      dossier = dossier_form.save()
 +                    if not dossier.remuneration_set.all():
 +                        # Pré-peuplement des entrées de la section "coût
 +                        # global", à l'exclusion de "Indemnité de fonction"
 +                        for type in type_remun.all():
 +                            dae.Remuneration(dossier=dossier, type=type,
 +                                             devise=dossier.devise).save()
 +
 +                    else:
 +                        # Sauvegarde du coût global
 +                        cg_lines = defaultdict(dict)
 +                        for k, v in request.POST.items():
 +                            if k.startswith('cg-'):
 +                                prefix, field_name, cg_id = k.split('-')
 +                                cg_lines[int(cg_id)][unicode(field_name)] = v
 +
 +                        for r in dossier.remuneration_set.all():
 +                            print 'trying %r' % r
 +                            if r.id in cg_lines:
 +                                if cg_lines[r.id]['montant'] == '':
 +                                   r.delete()
 +                                else:
 +                                    for k, v in cg_lines[r.id].items():
 +                                        setattr(r, k, v)
 +                                        r.save()
 +
                      return redirect('embauche', key='dae-%s' % poste.id,
                                      dossier=dossier.id)
              else:
Simple merge