Masse salariale: export ods, ajout des dossiers & formattage
authorJean-Philippe Caissy <jpcaissy@piji.ca>
Wed, 28 Mar 2012 22:33:31 +0000 (17:33 -0500)
committerJean-Philippe Caissy <jpcaissy@piji.ca>
Wed, 28 Mar 2012 22:33:31 +0000 (17:33 -0500)
project/rh/masse_salariale.py
project/rh/ods.py

index 9af02e3..f859766 100644 (file)
@@ -40,7 +40,7 @@ TYPE_NATURE_INDEMN = u"Indemnité"
 TYPE_NATURE_PAIEMENT = u"Accessoire"
 TYPE_NATURE_CHARGES = u"Charges"
 TYPE_NATURE_TRAITEMENT = u"Traitement"
-HEADER_SEPARATOR = ('sep', '')
+HEADER_SEPARATOR = ('sep', '', {'columnwidth': '0.4cm'})
 
 
 class MasseSalariale():
@@ -476,6 +476,7 @@ class MasseSalariale():
                     'masse_salariale_annee_euro': \
                             masse_salariale_euro.montant * regime *
                             rapport_nombre_jours,
+                    'sep': None,
             }
 
             grand_total += round(masse_salariale, 2)
@@ -571,7 +572,9 @@ class MasseSalariale():
             if len(h) > 2:
                 table.add_column(**h[2])
 
-        table.add_row([h[1] for h in self.headers], rowheight='2cm',
-                fontweight='bold')
+        table.add_row([h[1] for h in self.headers], rowheight='2cm')
+
+        for r in self.rapport:
+            table.add_row([r[h[0]] for h in self.headers])
 
         #a.doc.write('hello_world.ods')
index cbe2fce..87b315e 100644 (file)
@@ -6,10 +6,19 @@ import odf.opendocument
 import odf.style
 import odf.table
 from odf.style import Style, MasterPage, PageLayout, PageLayoutProperties, \
-        TextProperties, GraphicProperties, ParagraphProperties, DrawingPageProperties
-from odf.text import P
+        TextProperties, GraphicProperties, ParagraphProperties, \
+        DrawingPageProperties
 
+def valuetype(val):
+    valuetype="string"
+    if isinstance(val, str):
+        valuetype = "string"
+    if isinstance(val, (int, float, Decimal)):
+        valuetype = "float"
+    if isinstance(val, bool):
+        valuetype = "boolean"
 
+    return valuetype
 
 class Wrapper(object):
 
@@ -61,9 +70,6 @@ class Table(Wrapper):
             del kwargs['rowheight']
 
         style = {}
-        if 'fontweight' in kwargs:
-            style['fontweight'] = kwargs['fontweight']
-            del kwargs['fontweight']
 
         row = TableRow(**kwargs)
         row._doc = self._doc
@@ -94,11 +100,18 @@ class TableRow(Wrapper):
 
     def add_cell(self, value=None, **kwargs):
         if value:
-            if isinstance(value, basestring):
-                kwargs['stringvalue'] = value
+            if isinstance(value, (basestring, unicode)):
+                kwargs['stringvalue'] = unicode(value)
             elif isinstance(value, (int, float, Decimal)):
-                kwargs['valuetype'] = 'float'
-                kwargs['value'] = float(value)
+                kwargs['valuetype'] = "float"
+                kwargs['stringvalue'] = float(value)
+            elif type(value) == type(None):
+                kwargs['stringvalue'] = u""
+                kwargs['stringvalue'] = u""
+            else:
+                kwargs['stringvalue'] = unicode(value)
+
+            print kwargs['stringvalue']
 
         if 'verticalalign' in kwargs:
             style = self._doc.add_automatic_style(family='table-cell')
@@ -107,21 +120,21 @@ class TableRow(Wrapper):
             kwargs['stylename'] = style.getAttribute('name')
             del kwargs['verticalalign']
 
-        props = {}
-        if 'fontweight' in kwargs:
-            props['fontweight'] = kwargs.pop('fontweight')
-        if 'stringvalue' in kwargs:
-            props['stringvalue'] = kwargs.pop('stringvalue')
+#        props = {}
+#        if 'fontweight' in kwargs:
+#            props['fontweight'] = kwargs.pop('fontweight')
+#        if 'stringvalue' in kwargs:
+#            props['stringvalue'] = kwargs.pop('stringvalue')
 
         cell = odf.table.TableCell(**kwargs)
-        if 'fontweight' in props:
-            tablecontents = Style(name="Bold", family="paragraph")
-            tablecontents.addElement(TextProperties(fontweight="bold"))
-            self._doc.styles.addElement(tablecontents)
-
-        if 'stringvalue' in props:
-            p = P(stylename='Bold',text=props['stringvalue'])
-            cell.addElement(p)
+#        if 'fontweight' in props:
+#            tablecontents = Style(name="Bold", family="paragraph")
+#            tablecontents.addElement(TextProperties(fontweight="bold"))
+#            self._doc.styles.addElement(tablecontents)
+
+#        if 'stringvalue' in props:
+#            p = P(stylename='Bold',text=props['stringvalue'])
+#            cell.addElement(p)
 
         self.addElement(cell)
         return cell