Fix for salaire de base bug
[auf_rh_dae.git] / project / dae / forms.py
index 4326834..373099f 100644 (file)
@@ -375,6 +375,7 @@ class GroupedInlineFormset(BaseInlineFormSet):
                 }
 
         # Assign each form to a group.
+        ungrouped_forms = []
         for form in self.forms:
             if bool(form.initial):
                 grp = group_accessor(form)
@@ -385,19 +386,26 @@ class GroupedInlineFormset(BaseInlineFormSet):
                         'forms': [],
                         }
                 self.groups[grp[0]]['forms'].append(form)
+            else:
+                ungrouped_forms.append(form)
+            
     
-        # Add extra forms (n extra for each grop).
-        tmp_extras = []
-        for i in xrange(len(self.groups) * self.extra):
-            tmp_extras.insert(0,
-        self._construct_form(self.initial_form_count() + i))
-
+        # Distribuer les extras de django dans les groupes, et ajouter
+        # des extras pour les groupes en nécessitant.
+        f_count = len(self.forms)
         for g in self.groups:
-            for i in xrange(self.extra):
-                tmp_form = tmp_extras.pop()
-                self.groups[g]['forms'].append(tmp_form)
-                self.forms.append(tmp_form)
-            
+            for i in xrange(f_count, f_count + self.extra):
+                if len(ungrouped_forms) == 0:
+                    f_count += 1
+
+                if len(ungrouped_forms) > 0:
+                    new_form = ungrouped_forms.pop()
+                else:
+                    new_form = self._construct_form(i)
+                    self.forms.append(new_form)
+
+                self.groups[g]['forms'].append(new_form)
+                
 
         # Override form choices with the data provided in
         # choice_overrides
@@ -411,41 +419,6 @@ class GroupedInlineFormset(BaseInlineFormSet):
         # Create an iterable for easier access in template.
         self.group_list = self.groups.values()
 
-    # def set_groups(self, group_accessor, groups, 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 = OrderedDict()
-    #     temp_groups = {}
-    #     # self.groups_and_forms = []
-    #     for form in self.forms:
-    #         group_key, group_name = group_accessor(form)
-    #         if not temp_groups.has_key(group_key):
-    #             temp_groups[group_key] = {
-    #                 'name': group_name,
-    #                 'key': group_key,
-    #                 'forms': [],
-    #                 }
-    #         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()
-
 
 def remun_formset_factory(parent_model,
                           model,
@@ -576,6 +549,7 @@ def remun_formset_factory_factory(
             },
         )
 
+
 RemunForm = remun_formset_factory_factory(
     read_only=False,
     parent_model=dae.Dossier,