瀏覽代碼

CHG Correction mineure modèles

olivier.massot 7 年之前
父節點
當前提交
3552efd951
共有 2 個文件被更改,包括 31 次插入30 次删除
  1. 7 4
      core/model.py
  2. 24 26
      ctrl2analytique.py

+ 7 - 4
core/model.py

@@ -5,11 +5,17 @@
 '''
 import logging
 
-
 logger = logging.getLogger("model")
 
 class Model():
     """ Modèle de données d'un objet """
+
+    def __repr__(self):
+        return "<{} => {}>".format(self.__class__.__name__, ",".join(["{}={}".format(field, getattr(self, field)) for field in self.__dict__]))
+
+
+class CsvModel(Model):
+    """ Modèle de données d'un objet à stocker au format CSV """
     _FIELDS = []
 
     def __init__(self):
@@ -18,9 +24,6 @@ class Model():
         for fld in self._FIELDS:
             setattr(self, fld, None)
 
-    def __repr__(self):
-        return "<{} => {}>".format(self.__class__.__name__, ",".join(["{}={}".format(field, getattr(self, field)) for field in self._FIELDS]))
-
     @classmethod
     def from_dict(cls, data):
         """ Retourne un objet à partir d'un dictionnaire de données """

+ 24 - 26
ctrl2analytique.py

@@ -15,7 +15,7 @@ import sys
 from path import Path  # @UnusedImport
 
 from core import logconf
-from core.model import Model
+from core.model import CsvModel, Model
 from core.pde import ControlesDb, AnalytiqueDb, mk_workdir, CommunDb
 
 
@@ -33,6 +33,29 @@ logconf.start("ctrl2analytique", logging.DEBUG)
 
 ##-----------------------------------------------
 
+
+class Affaire(CsvModel):
+    """ Modèle de données d'une affaire Analytique """
+    _FIELDS = ["strLiaisonControle", "strMOeId", "strCommneId", "strLieux",
+               "strEntrepriseId", "strMOId", "dtmCommande", "Ref", "blnMarche",
+               "dblMarche", "intTypeContrat", "strCT", "strTypeId", "intCoefFG", "strSituation",
+               "lngChantierId", "bytCommandeId"]
+
+class Interv(CsvModel):
+    """ Modèle de données d'une intervention de contrôle réseaux """
+    _FIELDS = ["strEquipeId", "strEnginId", "strRapportId", "strTypeInterventionId",
+               "strCatégorieInterventionId", "dblquantite", "strunite", "dtmIntervention",
+               "dtmDureeIntervention", "strLiaisonControle", "strArticleId", "intPeriode",
+               "remarques", "strgrandeur1", "strgrandeur2", "strgrandeur3",
+               "strcaracteristique1", "strcaracteristique2", "strcaracteristique3",
+               "strunite1", "strunite2", "strunite3", "dtmImportation", "strTest", "LienAff",
+               "lngChantierId", "bytCommandeId", "bytIntervId"
+               ]
+
+class Tarification(Model):
+    """ Modèle de donnée d'une ligne de tarification """
+    pass
+
 # #########    INITIALISATION    ##########
 logger.info("Initialisation...")
 
@@ -60,14 +83,6 @@ for file in (affaires_file, intervs_file):
         logger.debug("Supprime le fichier %s", file)
         file.remove()
 
-class Affaire(Model):
-    """ Modèle de données d'une affaire Analytique """
-    _FIELDS = ["strLiaisonControle", "strMOeId", "strCommneId", "strLieux",
-               "strEntrepriseId", "strMOId", "dtmCommande", "Ref", "blnMarche",
-               "dblMarche", "intTypeContrat", "strCT", "strTypeId",
-               "intCoefFG", "strSituation",
-               "lngChantierId", "bytCommandeId"]
-
 def get_type_id(lngChantierId, bytCommandeId):
     """ Recupère le type de chantier.
     'ZP': Chantier de contrôle d'étanchéité
@@ -150,18 +165,6 @@ logger.info("> {} affaires ajoutées au fichier".format(compteur))
 
 # Importe les interventions de contrôle du compactage dans le fichier intervs.csv
 
-class Interv(Model):
-    """ Modèle de données d'une intervention de contrôle réseaux """
-    _FIELDS = ["strEquipeId", "strEnginId", "strRapportId", "strTypeInterventionId",
-               "strCatégorieInterventionId", "dblquantite", "strunite", "dtmIntervention",
-               "dtmDureeIntervention", "strLiaisonControle", "strArticleId", "intPeriode",
-               "remarques", "strgrandeur1", "strgrandeur2", "strgrandeur3",
-               "strcaracteristique1", "strcaracteristique2", "strcaracteristique3",
-               "strunite1", "strunite2", "strunite3",
-               "dtmImportation", "strTest", "LienAff",
-               "lngChantierId", "bytCommandeId", "bytIntervId"
-               ]
-
 def engin_existe(strEnginId):
     """ retourne True si le code de l'engin existe dans la table tbl_Engin """
     return analytique_db.exists("SELECT strEnginId FROM tbl_Engin WHERE strEnginId='{}'".format(strEnginId))
@@ -503,11 +506,6 @@ with open(intervs_file) as f:
         interv = Interv.from_csv(line)
         intervs.append(interv)
 
-class Tarification(Model):
-    """ Modèle de donnée d'une ligne de tarification """
-    _FIELDS = ["DblAffaireId", "strRapportId", "strArticleId", "dblQuantite", "strUnite",
-               "dtmDebut", "dtmFin", "bytPeriode", "dblPrixUnitaire", "dblPrixTotal", "strStatut"]
-
 
 # On insère les affaires, interventions dans Analytique, et on génère la ou les lignes de tarification associées