|
|
@@ -16,8 +16,9 @@ from path import Path # @UnusedImport
|
|
|
|
|
|
from core import logconf
|
|
|
from core.db import AccessSqlHelper
|
|
|
-from core.model import Model
|
|
|
-from core.pde import ControlesDb, AnalytiqueDb, mk_workdir, CommunDb
|
|
|
+from core.pde import ControlesDb, AnalytiqueDb, mk_workdir, CommunDb, Affaire, \
|
|
|
+ Interv, Tarification
|
|
|
+from core.sqlformatter import SqlFormatter
|
|
|
|
|
|
|
|
|
logger = logging.getLogger("ctrl2analytique")
|
|
|
@@ -27,10 +28,10 @@ logconf.start("ctrl2analytique", logging.DEBUG)
|
|
|
# > Lancer le script /resources/test_ctrl2analytique.py pour reinitialiser les données de la base de test
|
|
|
##-----------------------------------------------
|
|
|
|
|
|
-logger.warning("<<<<<<<<<<<<<< Mode TEST >>>>>>>>>>>>>>>>>")
|
|
|
-ControlesDb._path = Path(r"\\h2o\local\4-transversal\BDD\mdb_test\cg67Parc_data.mdb")
|
|
|
-AnalytiqueDb._path = Path(r"\\h2o\local\4-transversal\BDD\mdb_test\Db_analytique.mdb")
|
|
|
-CommunDb._path = Path(r"\\h2o\local\4-transversal\BDD\mdb_test\Commun_Data.mdb")
|
|
|
+# logger.warning("<<<<<<<<<<<<<< Mode TEST >>>>>>>>>>>>>>>>>")
|
|
|
+# ControlesDb._path = Path(r"\\h2o\local\4-transversal\BDD\mdb_test\cg67Parc_data.mdb")
|
|
|
+# AnalytiqueDb._path = Path(r"\\h2o\local\4-transversal\BDD\mdb_test\Db_analytique.mdb")
|
|
|
+# CommunDb._path = Path(r"\\h2o\local\4-transversal\BDD\mdb_test\Commun_Data.mdb")
|
|
|
|
|
|
##-----------------------------------------------
|
|
|
|
|
|
@@ -38,6 +39,8 @@ CommunDb._path = Path(r"\\h2o\local\4-transversal\BDD\mdb_test\Commun_Data.mdb")
|
|
|
# ######### INITIALISATION ##########
|
|
|
logger.info("Initialisation...")
|
|
|
|
|
|
+Sql = SqlFormatter()
|
|
|
+
|
|
|
no_prompt = ("-n" in sys.argv)
|
|
|
if no_prompt:
|
|
|
logger.info("> Lancé en mode automatique (sans interruption)")
|
|
|
@@ -63,20 +66,11 @@ for file in (affaires_file, intervs_file):
|
|
|
file.remove()
|
|
|
|
|
|
|
|
|
-class Affaire(Model):
|
|
|
- """ Modèle de données d'une affaire Analytique """
|
|
|
- pass
|
|
|
-
|
|
|
-class Interv(Model):
|
|
|
- """ Modèle de données d'une intervention de contrôle réseaux """
|
|
|
- pass
|
|
|
-
|
|
|
-class Tarification(Model):
|
|
|
- """ Modèle de donnée d'une ligne de tarification """
|
|
|
- pass
|
|
|
-
|
|
|
sqlHelper = AccessSqlHelper
|
|
|
|
|
|
+# date zéro pour Access
|
|
|
+date_zero = datetime(1899, 12, 30, 0, 0, 0)
|
|
|
+
|
|
|
def get_type_id(lngChantierId, bytCommandeId):
|
|
|
""" Recupère le type de chantier.
|
|
|
'ZP': Chantier de contrôle d'étanchéité
|
|
|
@@ -105,7 +99,7 @@ def get_coeff_k(lngChantierId):
|
|
|
""" Récupère le coefficient de calcul des frais généraux (batiments, frais administratifs...Etc.) """
|
|
|
# On déduit l'année du chantier à partir du code chantier
|
|
|
annee = "20" + str(lngChantierId)[:2] if len(str(lngChantierId)) == 6 else "200" + str(lngChantierId)[:1]
|
|
|
- return analytique_db.first("SELECT [COEFFG] FROM tbl_COEFFG WHERE [ANNEE] = {}".format(annee)).COEFFG / 100
|
|
|
+ return analytique_db.first(Sql.format("SELECT [COEFFG] FROM tbl_COEFFG WHERE [ANNEE] = {}", annee)).COEFFG / 100
|
|
|
|
|
|
|
|
|
|
|
|
@@ -135,6 +129,7 @@ for data in controles_db.read(sql):
|
|
|
affaire.Ref = data.strRefCommande
|
|
|
affaire.blnMarche = data.blnMarche
|
|
|
affaire.dblMarche = data.dblMtMarche
|
|
|
+ affaire.intDevisId = data.strdevis if data.strdevis else 0
|
|
|
affaire.intTypeContrat = 1
|
|
|
affaire.strCT = '1'
|
|
|
affaire.strTypeId = get_type_id(data.lngChantierId, data.bytCommandeId)
|
|
|
@@ -161,13 +156,15 @@ logger.info("> {} affaires ajoutées au fichier".format(compteur))
|
|
|
|
|
|
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))
|
|
|
+ return analytique_db.exists(Sql.format("SELECT strEnginId FROM tbl_Engin WHERE strEnginId={:text}", strEnginId))
|
|
|
|
|
|
def get_periode_validite(date_interv):
|
|
|
""" retourne la préiode comptable correspondant à la date de l'intervention """
|
|
|
- sql = """SELECT intPeriodeValiditeId FROM tblTarifValidite
|
|
|
- WHERE [dtmValiditeDebut] <= #{date_interv}# AND [dtmValiditeFin] > #{date_interv}# AND [bytClasseTarifId]=1
|
|
|
- """.format(date_interv=date_interv)
|
|
|
+ if not date_interv:
|
|
|
+ return None
|
|
|
+ sql = Sql.format("""SELECT intPeriodeValiditeId FROM tblTarifValidite
|
|
|
+ WHERE [dtmValiditeDebut] <= {date_interv:date} AND [dtmValiditeFin] > {date_interv:date} AND [bytClasseTarifId]=1
|
|
|
+ """, date_interv=date_interv)
|
|
|
return commun_db.first(sql).intPeriodeValiditeId
|
|
|
|
|
|
compteur = 0
|
|
|
@@ -213,7 +210,7 @@ for data in controles_db.read(sql):
|
|
|
interv.strunite = "u"
|
|
|
interv.dtmIntervention = data.dtmEssai
|
|
|
interv.dtmDureeIntervention = data.dtmDuree
|
|
|
- interv.dtmDureeInstallation = 0 # Les temps d'installation seront calculés en fin de traitement
|
|
|
+ interv.dtmDureeInstallation = date_zero # Les temps d'installation seront calculés en fin de traitement
|
|
|
interv.strLiaisonControle = "{}/{}/{}".format(data.lngChantierId, data.bytCommandeId, data.bytIntervId)
|
|
|
interv.strArticleId = data.strEnginId
|
|
|
interv.intPeriode = get_periode_validite(data.dtmEssai)
|
|
|
@@ -283,7 +280,7 @@ for data in controles_db.read(sql):
|
|
|
interv.strunite = "u"
|
|
|
interv.dtmIntervention = data.dtmEssai
|
|
|
interv.dtmDureeIntervention = data.dtmDuree
|
|
|
- interv.dtmDureeInstallation = 0 # Les temps d'installation seront recalculés en fin de traitement
|
|
|
+ interv.dtmDureeInstallation = date_zero # Les temps d'installation seront recalculés en fin de traitement
|
|
|
interv.strLiaisonControle = "{}/{}/{}".format(data.lngChantierId, data.bytCommandeId, data.bytIntervId)
|
|
|
interv.strArticleId = interv.strEnginId
|
|
|
interv.intPeriode = get_periode_validite(data.dtmEssai)
|
|
|
@@ -347,7 +344,7 @@ for data in controles_db.read(sql):
|
|
|
interv.strunite = "j"
|
|
|
interv.dtmIntervention = data.dtmIntervDu
|
|
|
interv.dtmDureeIntervention = data.dtmDuree
|
|
|
- interv.dtmDureeInstallation = 0 # Les temps d'installation seront recalculés en fin de traitement
|
|
|
+ interv.dtmDureeInstallation = date_zero # Les temps d'installation seront recalculés en fin de traitement
|
|
|
interv.strLiaisonControle = "{}/{}/{}".format(data.lngChantierId, data.bytCommandeId, data.bytIntervId)
|
|
|
interv.strArticleId = data.strEnginId
|
|
|
interv.intPeriode = get_periode_validite(data.dtmIntervDu)
|
|
|
@@ -398,31 +395,32 @@ while errors:
|
|
|
if not affaire.strMOId:
|
|
|
errors.append(prefix + "MO manquant")
|
|
|
else:
|
|
|
- if not commun_db.exists("SELECT [lngTiersId] FROM tblTiers WHERE [lngTiersId]={}".format(affaire.strMOId)):
|
|
|
+ if not commun_db.exists(Sql.format("SELECT [lngTiersId] FROM tblTiers WHERE [lngTiersId]={}", affaire.strMOId)):
|
|
|
errors.append(prefix + "Le MO {} n'existe pas dans tblTiers".format(affaire.strMOId))
|
|
|
if not affaire.strMOeId:
|
|
|
errors.append(prefix + "MOe manquant")
|
|
|
else:
|
|
|
- if not commun_db.exists("SELECT [lngTiersId] FROM tblTiers WHERE [lngTiersId]={}".format(affaire.strMOeId)):
|
|
|
+ if not commun_db.exists(Sql.format("SELECT [lngTiersId] FROM tblTiers WHERE [lngTiersId]={}", affaire.strMOeId)):
|
|
|
errors.append(prefix + "Le MOe {} n'existe pas dans tblTiers".format(affaire.strMOeId))
|
|
|
if not affaire.strEntrepriseId:
|
|
|
errors.append(prefix + "Entreprise manquante")
|
|
|
else:
|
|
|
- if not commun_db.exists("SELECT [lngTiersId] FROM tblTiers WHERE [lngTiersId]={}".format(affaire.strEntrepriseId)):
|
|
|
+ if not commun_db.exists(Sql.format("SELECT [lngTiersId] FROM tblTiers WHERE [lngTiersId]={}", affaire.strEntrepriseId)):
|
|
|
errors.append(prefix + "L'entreprise {} n'existe pas dans tblTiers".format(affaire.strEntrepriseId))
|
|
|
if not affaire.strCommneId:
|
|
|
errors.append(prefix + "Commune manquante")
|
|
|
else:
|
|
|
- if not commun_db.exists("SELECT [lngTiersId] FROM tblTiers WHERE [lngTiersId]={}".format(affaire.strCommneId)):
|
|
|
+ if not commun_db.exists(Sql.format("SELECT [lngTiersId] FROM tblTiers WHERE [lngTiersId]={}", affaire.strCommneId)):
|
|
|
errors.append(prefix + "La commune {} n'existe pas dans tblTiers".format(affaire.strCommneId))
|
|
|
if not affaire.strTypeId:
|
|
|
errors.append(prefix + "Type d'affaire manquant")
|
|
|
if not affaire.dtmCommande:
|
|
|
errors.append(prefix + "Date de commande manquante")
|
|
|
- if affaire.blnMarche == True and not affaire.intDevisId:
|
|
|
- errors.append(prefix + "Numéro de devis manquant")
|
|
|
+ if affaire.blnMarche == True:
|
|
|
+ if not affaire.intDevisId:
|
|
|
+ errors.append(prefix + "Numéro de devis manquant")
|
|
|
|
|
|
- if analytique_db.exists("SELECT dblAffaireId FROM tbl_Affaires WHERE [strLiaisonControle]='{}'".format(affaire.strLiaisonControle)):
|
|
|
+ if analytique_db.exists(Sql.format("SELECT dblAffaireId FROM tbl_Affaires WHERE [strLiaisonControle]='{}'", affaire.strLiaisonControle)):
|
|
|
errors.append(prefix + "Une affaire portant ce code existe déjà: {}".format(affaire.strLiaisonControle))
|
|
|
|
|
|
for interv in Interv.load_csv(intervs_file):
|
|
|
@@ -485,13 +483,13 @@ for affaire in affaires:
|
|
|
|
|
|
# insertion dans tbl_Affaires
|
|
|
|
|
|
- sql = """ INSERT INTO tbl_Affaires ( strMOId, strMOeId, strEntrepriseId, strCommneId, strLieux, strTypeId, dtmCommande, Ref,
|
|
|
+ sql = Sql.format(""" INSERT INTO tbl_Affaires ( strMOId, strMOeId, strEntrepriseId, strCommneId, strLieux, strTypeId, dtmCommande, Ref,
|
|
|
blnMarche, dblMarche, intTypeContrat, strCT, strLiaisonControle, blnTarification,
|
|
|
blnAnalyse, strSituation, intCoefFG )
|
|
|
- VALUES ('{affaire.strMOId}', '{affaire.strMOeId}', '{affaire.strEntrepriseId}', '{affaire.strCommneId}', '{affaire.strLieux}', '{affaire.strTypeId}',
|
|
|
- #{affaire.dtmCommande}#, '{affaire.Ref}', {affaire.blnMarche}, {affaire.dblMarche}, {affaire.intTypeContrat}, '{affaire.strCT}',
|
|
|
- '{affaire.strLiaisonControle}', True, False, '{affaire.strSituation}', {affaire.intCoefFG})
|
|
|
- """.format(affaire=affaire)
|
|
|
+ VALUES ({affaire.strMOId:text}, {affaire.strMOeId:text}, {affaire.strEntrepriseId:text}, {affaire.strCommneId:text}, {affaire.strLieux:text}, {affaire.strTypeId:text},
|
|
|
+ {affaire.dtmCommande:date}, {affaire.Ref:text}, {affaire.blnMarche}, {affaire.dblMarche}, {affaire.intTypeContrat}, {affaire.strCT:text},
|
|
|
+ {affaire.strLiaisonControle:text}, True, False, {affaire.strSituation:text}, {affaire.intCoefFG})
|
|
|
+ """, affaire=affaire)
|
|
|
|
|
|
analytique_db.execute(sql)
|
|
|
|
|
|
@@ -501,24 +499,26 @@ for affaire in affaires:
|
|
|
# On insère les interventions dans tbl_Intervention
|
|
|
for interv in intervs:
|
|
|
|
|
|
- affaire = analytique_db.first("SELECT TOP 1 DblAffaireId FROM tbl_Affaires WHERE [strLiaisonControle]='{}'".format(interv.LienAff))
|
|
|
+ affaire = analytique_db.first(Sql.format("SELECT TOP 1 DblAffaireId FROM tbl_Affaires WHERE [strLiaisonControle]='{}'", interv.LienAff))
|
|
|
if not affaire:
|
|
|
logger.error("Intervention {} : Impossible de trouver l'affaire {}".format(interv.strTest, interv.LienAff))
|
|
|
continue
|
|
|
|
|
|
interv.dblAffaireId = affaire.DblAffaireId
|
|
|
+ if not interv.intPeriode:
|
|
|
+ interv.intPeriode = get_periode_validite(data.dtmIntervDu) # Si la date d'interv manquait avant la validation, la periode n'a pa été mise à jour
|
|
|
|
|
|
- sql = """INSERT INTO tbl_Intervention ( DblAffaireId, strEquipeId, strEnginId, strRapportId, strCatégorieInterventionId, strTypeInterventionId,
|
|
|
+ sql = Sql.format("""INSERT INTO tbl_Intervention ( DblAffaireId, strEquipeId, strEnginId, strRapportId, strCatégorieInterventionId, strTypeInterventionId,
|
|
|
dblquantite, strunite, dtmIntervention, dtmDureeIntervention, dtmDureeInstallation, strcaracteristique1, strgrandeur1, strunite1,
|
|
|
strcaracteristique2, strgrandeur2, strunite2, strcaracteristique3, strgrandeur3, strunite3, strLiaisonControle, strarticleId,
|
|
|
intPeriode, blnTarification, blnAnalyse, blnFacturer, remarques, blnPeriode, dtmImportation, strTest )
|
|
|
- VALUES ({interv.dblAffaireId}, '{interv.strEquipeId}', '{interv.strEnginId}', '{interv.strRapportId}', '{interv.strCatégorieInterventionId}',
|
|
|
- '{interv.strTypeInterventionId}', {interv.dblquantite}, '{interv.strunite}', #{interv.dtmIntervention}#, #{interv.dtmDureeIntervention}#, #1899-12-30 00:00:00#,
|
|
|
- '{interv.strcaracteristique1}', '{interv.strgrandeur1}', '{interv.strunite1}', '{interv.strcaracteristique2}',
|
|
|
- '{interv.strgrandeur2}', '{interv.strunite2}', '{interv.strcaracteristique3}', '{interv.strgrandeur3}', '{interv.strunite3}', '{interv.strLiaisonControle}',
|
|
|
- '{interv.strArticleId}', {interv.intPeriode}, True, False, False, '{interv.remarques}',
|
|
|
- False, #{interv.dtmImportation}#, '{interv.strTest}')
|
|
|
- """.format(interv=interv)
|
|
|
+ VALUES ({interv.dblAffaireId}, {interv.strEquipeId:text}, {interv.strEnginId:text}, {interv.strRapportId:text}, {interv.strCatégorieInterventionId:text},
|
|
|
+ {interv.strTypeInterventionId:text}, {interv.dblquantite}, {interv.strunite:text}, {interv.dtmIntervention:date}, {interv.dtmDureeIntervention:date}, {date_zero:date},
|
|
|
+ {interv.strcaracteristique1:text}, {interv.strgrandeur1:text}, {interv.strunite1:text}, {interv.strcaracteristique2:text},
|
|
|
+ {interv.strgrandeur2:text}, {interv.strunite2:text}, {interv.strcaracteristique3:text}, {interv.strgrandeur3:text}, {interv.strunite3:text},
|
|
|
+ {interv.strLiaisonControle:text}, {interv.strArticleId:text}, {interv.intPeriode}, True, False, False, {interv.remarques:text},
|
|
|
+ False, {interv.dtmImportation:date}, {interv.strTest:text})
|
|
|
+ """, interv=interv, date_zero=date_zero)
|
|
|
|
|
|
analytique_db.execute(sql)
|
|
|
|
|
|
@@ -536,11 +536,15 @@ for strRapportId, strArticleId in set([(interv.strRapportId, interv.strArticleId
|
|
|
tarif.intervs = [interv for interv in intervs if interv.strRapportId == strRapportId and interv.strArticleId == strArticleId]
|
|
|
|
|
|
# recupere le prix unitaire de l'engin
|
|
|
- prix_unitaire = commun_db.first("""SELECT dblPU FROM tblTarif WHERE [strArticleId]='{}' AND [intPeriodeValiditeId]={}
|
|
|
- """.format(strArticleId, tarif.intervs[0].intPeriode)).dblPU
|
|
|
+ tarif_engin = commun_db.first(Sql.format("""SELECT dblPU FROM tblTarif WHERE [strArticleId]={:text} AND [intPeriodeValiditeId]={}
|
|
|
+ """, strArticleId, get_periode_validite(intervs[0].dtmIntervention)))
|
|
|
+ if not tarif_engin:
|
|
|
+ logger.error("Aucun tarif trouvé dans tblTarif pour l'article {}, periode {}".format(strArticleId, tarif.intervs[0].intPeriode))
|
|
|
+ prix_unitaire = tarif_engin.dblPU
|
|
|
+
|
|
|
# recupere le taux de tva applicable à l'engin
|
|
|
- taux_tva = commun_db.first("""SELECT tblTVATaux.dblTVATaux FROM tblArticle INNER JOIN tblTVATaux ON tblArticle.bytTVAArticleId = tblTVATaux.bytTVAId
|
|
|
- WHERE (((tblArticle.strArticleId)='{}'));""".format(strArticleId)).dblTVATaux
|
|
|
+ taux_tva = commun_db.first(Sql.format("""SELECT tblTVATaux.dblTVATaux FROM tblArticle INNER JOIN tblTVATaux ON tblArticle.bytTVAArticleId = tblTVATaux.bytTVAId
|
|
|
+ WHERE tblArticle.strArticleId={:text};""", strArticleId)).dblTVATaux
|
|
|
|
|
|
tarif.DblAffaireId = tarif.intervs[0].dblAffaireId
|
|
|
tarif.strRapportId = strRapportId
|
|
|
@@ -556,12 +560,12 @@ for strRapportId, strArticleId in set([(interv.strRapportId, interv.strArticleId
|
|
|
tarif.dblPrixTVA = tarif.dblPrixTotal * (0.01 * tarif.dblTauxTVA)
|
|
|
tarif.strStatut = 'A facturer'
|
|
|
|
|
|
- sql = """ INSERT INTO tbl_Tarification ( DblAffaireId, strRapportId, strArticleId, dblQuantite, strUnite, dtmDebut, dtmFin, bytPeriode,
|
|
|
+ sql = Sql.format(""" INSERT INTO tbl_Tarification ( DblAffaireId, strRapportId, strArticleId, dblQuantite, strUnite, dtmDebut, dtmFin, bytPeriode,
|
|
|
dblPrixUnitaire, dblPrixTotal, dblTauxTVA, dblPrixTVA, strStatut )
|
|
|
- VALUES ({tarif.DblAffaireId}, '{tarif.strRapportId}', '{tarif.strArticleId}', {tarif.dblQuantite}, '{tarif.strUnite}', #{tarif.dtmDebut}#,
|
|
|
- #{tarif.dtmFin}#, {tarif.bytPeriode}, {tarif.dblPrixUnitaire}, {tarif.dblPrixTotal},
|
|
|
- {tarif.dblTauxTVA}, {tarif.dblPrixTVA}, '{tarif.strStatut}')
|
|
|
- """.format(tarif=tarif)
|
|
|
+ VALUES ({tarif.DblAffaireId}, {tarif.strRapportId:text}, {tarif.strArticleId:text}, {tarif.dblQuantite}, {tarif.strUnite:text}, {tarif.dtmDebut:date},
|
|
|
+ {tarif.dtmFin:date}, {tarif.bytPeriode}, {tarif.dblPrixUnitaire}, {tarif.dblPrixTotal},
|
|
|
+ {tarif.dblTauxTVA}, {tarif.dblPrixTVA}, {tarif.strStatut:text})
|
|
|
+ """, tarif=tarif)
|
|
|
analytique_db.execute(sql)
|
|
|
|
|
|
logger.info("> Génération d'une ligne de tarification pour l'affaire {} (rapport {}, article: {})".format(tarif.intervs[0].LienAff, strRapportId, strArticleId))
|
|
|
@@ -570,13 +574,11 @@ for strRapportId, strArticleId in set([(interv.strRapportId, interv.strArticleId
|
|
|
# Maj champs MOS
|
|
|
# Ces champs sont utilisés dans les tables Controles pour savoir si une ligne a déjà été importée
|
|
|
for affaire in affaires:
|
|
|
- dblAffaireId = analytique_db.first("SELECT TOP 1 DblAffaireId FROM tbl_Affaires WHERE [strLiaisonControle]='{}'".format(affaire.strLiaisonControle)).DblAffaireId
|
|
|
+ dblAffaireId = analytique_db.first(Sql.format("SELECT TOP 1 DblAffaireId FROM tbl_Affaires WHERE [strLiaisonControle]={:text}", affaire.strLiaisonControle)).DblAffaireId
|
|
|
|
|
|
- sql = """UPDATE tblCommandes SET tblCommandes.sngAffaireIdMos = {DblAffaireId}
|
|
|
+ sql = Sql.format("""UPDATE tblCommandes SET tblCommandes.sngAffaireIdMos = {DblAffaireId}
|
|
|
WHERE [lngChantierId]={lngChantierId} AND [bytCommandeId]={bytCommandeId}
|
|
|
- """.format(DblAffaireId=dblAffaireId,
|
|
|
- lngChantierId=affaire.lngChantierId,
|
|
|
- bytCommandeId=affaire.bytCommandeId)
|
|
|
+ """, DblAffaireId=dblAffaireId, lngChantierId=affaire.lngChantierId, bytCommandeId=affaire.bytCommandeId)
|
|
|
controles_db.execute(sql)
|
|
|
|
|
|
for interv in intervs:
|
|
|
@@ -589,13 +591,13 @@ for interv in intervs:
|
|
|
else:
|
|
|
continue
|
|
|
|
|
|
- sql = """UPDATE {tbl} SET {tbl}.sngIntervIdMos = {DblAffaireId}
|
|
|
+ sql = Sql.format("""UPDATE {tbl} SET {tbl}.sngIntervIdMos = {DblAffaireId}
|
|
|
WHERE [lngChantierId]={lngChantierId} AND [bytCommandeId]={bytCommandeId} AND [bytIntervId]={bytIntervId}
|
|
|
- """.format(tbl=tbl,
|
|
|
- DblAffaireId=interv.dblAffaireId,
|
|
|
- lngChantierId=interv.lngChantierId,
|
|
|
- bytCommandeId=interv.bytCommandeId,
|
|
|
- bytIntervId=interv.bytIntervId)
|
|
|
+ """, tbl=tbl,
|
|
|
+ DblAffaireId=interv.dblAffaireId,
|
|
|
+ lngChantierId=interv.lngChantierId,
|
|
|
+ bytCommandeId=interv.bytCommandeId,
|
|
|
+ bytIntervId=interv.bytIntervId)
|
|
|
controles_db.execute(sql)
|
|
|
|
|
|
logger.info("> Mise à jour des champs MOS")
|
|
|
@@ -614,14 +616,13 @@ analytique_db.commit()
|
|
|
|
|
|
logger.info("Mise à jour des temps d'installation...")
|
|
|
|
|
|
-# date zéro pour Access
|
|
|
-date0 = datetime(1899, 12, 30, 0, 0, 0)
|
|
|
+
|
|
|
|
|
|
# On parcourt les interventions.
|
|
|
# Lorsque le temps d'intervention total d'une même équipe un même jour est inférieur à 8h,
|
|
|
# On affecte la différence de temps à la première intervention en tant que 'temps d'installation'
|
|
|
|
|
|
-sql = """SELECT First(tbl_Intervention.dblInterventionId) AS dblInterventionId, tbl_Intervention.strEquipeId,
|
|
|
+sql = Sql.format("""SELECT First(tbl_Intervention.dblInterventionId) AS dblInterventionId, tbl_Intervention.strEquipeId,
|
|
|
tbl_Intervention.dtmIntervention, CDate(Sum(tbl_Intervention.dtmDureeIntervention)) AS SD
|
|
|
FROM tbl_Intervention
|
|
|
WHERE tbl_Intervention.strLiaisonControle Like '%/%'
|
|
|
@@ -630,12 +631,12 @@ sql = """SELECT First(tbl_Intervention.dblInterventionId) AS dblInterventionId,
|
|
|
AND tbl_Intervention.strEquipeId Is Not Null
|
|
|
GROUP BY tbl_Intervention.strEquipeId, tbl_Intervention.dtmIntervention
|
|
|
HAVING (((CDate(Sum(tbl_Intervention.dtmDureeIntervention)))<#1899/12/30 8:0:0#))
|
|
|
- """.format(datetime.now().year - 1)
|
|
|
+ """, datetime.now().year - 1)
|
|
|
|
|
|
for interv in analytique_db.read_all(sql):
|
|
|
- tps_install = (date0 + timedelta(hours=8) - interv.SD)
|
|
|
- sql = """UPDATE tbl_Intervention SET tbl_Intervention.dtmDureeInstallation = #{}#
|
|
|
- WHERE (((tbl_Intervention.dblInterventionId)={}));""".format(date0 + tps_install, interv.dblInterventionId)
|
|
|
+ tps_install = (date_zero + timedelta(hours=8) - interv.SD)
|
|
|
+ sql = Sql.format("""UPDATE tbl_Intervention SET dtmDureeInstallation = #{}#
|
|
|
+ WHERE dblInterventionId={}""", date_zero + tps_install, interv.dblInterventionId)
|
|
|
analytique_db.execute(sql)
|
|
|
|
|
|
logger.debug("* Mise à jour du temps d'installation de l'intervention {}".format(interv.dblInterventionId))
|