Browse Source

CHG Maj gf2analytique pour ne plus dependre de l'editeur tsv

olivier.massot 7 years ago
parent
commit
d96773fd12

+ 0 - 81
core/select_list_dialog.py

@@ -1,81 +0,0 @@
-'''
-
-    Boite de dialogue qui prend une liste de strings en entrée,
-    permet d'en selectionner une ou plusieurs,
-    et retourne une liste des strings selectionnées
-
-    > utilisée par le script qgis_sync_compactage
-
-    @author: olivier.massot, mai 2018
-'''
-import sys
-
-from PyQt5 import uic
-from PyQt5.Qt import QApplication, QMessageBox, QTableWidgetItem, \
-    Qt, QDialog
-from path import Path
-
-
-Ui_window, _ = uic.loadUiType(Path(__file__).parent / 'select_list_dialog.ui')
-
-def exec_(*args, **kwargs):
-
-    _ = QApplication(sys.argv)
-
-    SYS_HOOK = sys.excepthook
-    def error_handler(typ, value, trace):
-        while QApplication.overrideCursor():
-            QApplication.restoreOverrideCursor()
-        QMessageBox.critical(dlg, typ.__name__, "{}".format(value))
-        SYS_HOOK(typ, value, trace)
-    sys.excepthook = error_handler
-
-    dlg = SelectListDialog(*args, **kwargs)
-    dlg.show()
-    r = dlg.exec_()
-    if r:
-        return dlg.selection()
-    else:
-        return []
-
-class SelectListDialog(QDialog):
-
-    def __init__(self, input_list, modifier=lambda x: x, title="Sélectionner les lignes"):
-        super (SelectListDialog, self).__init__()
-        self.input_list = input_list
-        self.modifier = modifier
-        self.title = title
-        self.createWidgets()
-
-    def createWidgets(self):
-        self.ui = Ui_window()
-        self.ui.setupUi(self)
-
-        self.setWindowModality(Qt.ApplicationModal)
-        self.ui.btn_ok.clicked.connect(self.ok)
-        self.ui.lbl_title.setText(self.title)
-
-        index = 0
-        for item in self.input_list:
-            self.ui.tbl_selection.insertRow(index)
-            self.ui.tbl_selection.setItem(index, 0, QTableWidgetItem(str(self.modifier(item))))
-            index += 1
-        self.ui.tbl_selection.sortItems(0, Qt.AscendingOrder)
-
-    def selection(self):
-        output_list = []
-
-        for model_index in self.ui.tbl_selection.selectedIndexes():
-            output_list.append(self.input_list[model_index.row()])
-
-        return output_list
-
-    def ok(self):
-        self.done(1)
-
-
-
-if __name__ == "__main__":
-    selection = exec_(["1", "2", "3"])
-    print(selection)
-

+ 0 - 146
core/select_list_dialog.ui

@@ -1,146 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<ui version="4.0">
- <class>window</class>
- <widget class="QDialog" name="window">
-  <property name="geometry">
-   <rect>
-    <x>0</x>
-    <y>0</y>
-    <width>237</width>
-    <height>346</height>
-   </rect>
-  </property>
-  <property name="maximumSize">
-   <size>
-    <width>433</width>
-    <height>793</height>
-   </size>
-  </property>
-  <property name="windowTitle">
-   <string>Sélection</string>
-  </property>
-  <layout class="QVBoxLayout" name="verticalLayout">
-   <item>
-    <widget class="QLabel" name="lbl_title">
-     <property name="minimumSize">
-      <size>
-       <width>0</width>
-       <height>21</height>
-      </size>
-     </property>
-     <property name="maximumSize">
-      <size>
-       <width>16777215</width>
-       <height>21</height>
-      </size>
-     </property>
-     <property name="text">
-      <string>Sélectionnez les lignes</string>
-     </property>
-    </widget>
-   </item>
-   <item>
-    <widget class="QTableWidget" name="tbl_selection">
-     <property name="palette">
-      <palette>
-       <active>
-        <colorrole role="Base">
-         <brush brushstyle="SolidPattern">
-          <color alpha="255">
-           <red>249</red>
-           <green>249</green>
-           <blue>249</blue>
-          </color>
-         </brush>
-        </colorrole>
-       </active>
-       <inactive>
-        <colorrole role="Base">
-         <brush brushstyle="SolidPattern">
-          <color alpha="255">
-           <red>249</red>
-           <green>249</green>
-           <blue>249</blue>
-          </color>
-         </brush>
-        </colorrole>
-       </inactive>
-       <disabled>
-        <colorrole role="Base">
-         <brush brushstyle="SolidPattern">
-          <color alpha="255">
-           <red>240</red>
-           <green>240</green>
-           <blue>240</blue>
-          </color>
-         </brush>
-        </colorrole>
-       </disabled>
-      </palette>
-     </property>
-     <property name="font">
-      <font>
-       <family>Verdana</family>
-      </font>
-     </property>
-     <property name="frameShape">
-      <enum>QFrame::StyledPanel</enum>
-     </property>
-     <property name="editTriggers">
-      <set>QAbstractItemView::NoEditTriggers</set>
-     </property>
-     <property name="alternatingRowColors">
-      <bool>true</bool>
-     </property>
-     <property name="selectionMode">
-      <enum>QAbstractItemView::MultiSelection</enum>
-     </property>
-     <property name="selectionBehavior">
-      <enum>QAbstractItemView::SelectRows</enum>
-     </property>
-     <attribute name="horizontalHeaderVisible">
-      <bool>false</bool>
-     </attribute>
-     <attribute name="horizontalHeaderDefaultSectionSize">
-      <number>50</number>
-     </attribute>
-     <attribute name="horizontalHeaderStretchLastSection">
-      <bool>true</bool>
-     </attribute>
-     <attribute name="verticalHeaderVisible">
-      <bool>false</bool>
-     </attribute>
-     <column>
-      <property name="text">
-       <string>nom</string>
-      </property>
-     </column>
-    </widget>
-   </item>
-   <item>
-    <widget class="QPushButton" name="btn_ok">
-     <property name="minimumSize">
-      <size>
-       <width>0</width>
-       <height>31</height>
-      </size>
-     </property>
-     <property name="maximumSize">
-      <size>
-       <width>16777215</width>
-       <height>31</height>
-      </size>
-     </property>
-     <property name="text">
-      <string>OK</string>
-     </property>
-     <property name="default">
-      <bool>true</bool>
-     </property>
-    </widget>
-   </item>
-  </layout>
- </widget>
- <resources/>
- <connections/>
-</ui>

+ 0 - 80
core/tsv_editor.py

@@ -1,80 +0,0 @@
-'''
-@author: olivier.massot
-'''
-
-import csv
-import sys
-
-from PyQt5 import uic
-from PyQt5.Qt import QMainWindow, QApplication, QMessageBox, QStandardItemModel, \
-    QStandardItem, Qt, QFileDialog
-from path import Path
-
-
-Ui_window, _ = uic.loadUiType(Path(__file__).parent / 'tsv_editor.ui')
-
-csv.register_dialect('tsv', delimiter='\t', quotechar='', quoting=csv.QUOTE_NONE)
-
-def exec_(filename=''):
-
-    app = QApplication(sys.argv)
-
-    SYS_HOOK = sys.excepthook
-    def error_handler(typ, value, trace):
-        while QApplication.overrideCursor():
-            QApplication.restoreOverrideCursor()
-        QMessageBox.critical(iface, typ.__name__, "{}".format(value))
-        SYS_HOOK(typ, value, trace)
-    sys.excepthook = error_handler
-
-    if not filename:
-        filename, _ = QFileDialog.getOpenFileName(None, "Selectionner un fichier TSV", ".", "Tsv Files (*.tsv *.csv)")
-
-    iface = MainWindow(filename)
-    iface.show()
-
-    r = app.exec_()
-    return r
-
-class MainWindow(QMainWindow):
-
-    def __init__(self, csvpath):
-        super (MainWindow, self).__init__()
-        self.csvpath = csvpath
-        self.createWidgets()
-
-    def createWidgets(self):
-        self.ui = Ui_window()
-        self.ui.setupUi(self)
-
-        self.ui.btn_cancel.clicked.connect(self.cancel)
-        self.ui.btn_ok.clicked.connect(self.ok)
-
-        self.model = QStandardItemModel(self)
-        self.ui.tbl_data.setModel(self.model)
-        self.ui.lbl_path.setText(self.csvpath)
-
-        with open(self.csvpath, newline='') as csvfile:
-            reader = csv.reader(csvfile, 'tsv')
-            self.headers = next(reader)
-            self.model.setHorizontalHeaderLabels(self.headers)
-            for row in reader:
-                items = [ QStandardItem(field) for field in row ]
-                self.model.appendRow(items)
-
-    def ok(self):
-        with open(self.csvpath, "w", newline='') as fileOutput:
-            writer = csv.writer(fileOutput, "tsv")
-            writer.writerow(self.headers)
-            for rowNumber in range(self.model.rowCount()):
-                fields = [self.model.data(self.model.index(rowNumber, columnNumber), Qt.DisplayRole)
-                          for columnNumber in range(self.model.columnCount())]
-                writer.writerow(fields)
-        self.close()
-
-    def cancel(self):
-        self.close()
-
-
-if __name__ == '__main__':
-    exec_()

+ 0 - 130
core/tsv_editor.ui

@@ -1,130 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<ui version="4.0">
- <class>window</class>
- <widget class="QMainWindow" name="window">
-  <property name="geometry">
-   <rect>
-    <x>0</x>
-    <y>0</y>
-    <width>910</width>
-    <height>704</height>
-   </rect>
-  </property>
-  <property name="windowTitle">
-   <string>TSV - Editor</string>
-  </property>
-  <widget class="QWidget" name="centralwidget">
-   <layout class="QVBoxLayout" name="verticalLayout">
-    <item>
-     <layout class="QHBoxLayout" name="horizontalLayout_2">
-      <item>
-       <widget class="QLabel" name="lbl_path">
-        <property name="minimumSize">
-         <size>
-          <width>0</width>
-          <height>25</height>
-         </size>
-        </property>
-        <property name="text">
-         <string>Fichier</string>
-        </property>
-        <property name="textInteractionFlags">
-         <set>Qt::LinksAccessibleByMouse|Qt::TextSelectableByMouse</set>
-        </property>
-       </widget>
-      </item>
-     </layout>
-    </item>
-    <item>
-     <widget class="QTableView" name="tbl_data">
-      <property name="minimumSize">
-       <size>
-        <width>521</width>
-        <height>221</height>
-       </size>
-      </property>
-      <property name="alternatingRowColors">
-       <bool>true</bool>
-      </property>
-      <property name="selectionMode">
-       <enum>QAbstractItemView::NoSelection</enum>
-      </property>
-      <property name="gridStyle">
-       <enum>Qt::DotLine</enum>
-      </property>
-      <property name="sortingEnabled">
-       <bool>true</bool>
-      </property>
-      <attribute name="horizontalHeaderCascadingSectionResizes">
-       <bool>true</bool>
-      </attribute>
-      <attribute name="horizontalHeaderDefaultSectionSize">
-       <number>80</number>
-      </attribute>
-      <attribute name="horizontalHeaderMinimumSectionSize">
-       <number>30</number>
-      </attribute>
-      <attribute name="horizontalHeaderShowSortIndicator" stdset="0">
-       <bool>true</bool>
-      </attribute>
-      <attribute name="verticalHeaderVisible">
-       <bool>false</bool>
-      </attribute>
-      <attribute name="verticalHeaderShowSortIndicator" stdset="0">
-       <bool>false</bool>
-      </attribute>
-     </widget>
-    </item>
-    <item>
-     <layout class="QHBoxLayout" name="horizontalLayout">
-      <item>
-       <spacer name="horizontalSpacer">
-        <property name="orientation">
-         <enum>Qt::Horizontal</enum>
-        </property>
-        <property name="sizeHint" stdset="0">
-         <size>
-          <width>40</width>
-          <height>20</height>
-         </size>
-        </property>
-       </spacer>
-      </item>
-      <item>
-       <widget class="QPushButton" name="btn_cancel">
-        <property name="minimumSize">
-         <size>
-          <width>100</width>
-          <height>27</height>
-         </size>
-        </property>
-        <property name="text">
-         <string>Annuler</string>
-        </property>
-       </widget>
-      </item>
-      <item>
-       <widget class="QPushButton" name="btn_ok">
-        <property name="minimumSize">
-         <size>
-          <width>100</width>
-          <height>27</height>
-         </size>
-        </property>
-        <property name="text">
-         <string>Valider</string>
-        </property>
-        <property name="default">
-         <bool>true</bool>
-        </property>
-       </widget>
-      </item>
-     </layout>
-    </item>
-   </layout>
-  </widget>
-  <widget class="QStatusBar" name="statusbar"/>
- </widget>
- <resources/>
- <connections/>
-</ui>

+ 7 - 7
gf2analytique.py

@@ -32,10 +32,10 @@ logconf.start("gf2analytique", logging.DEBUG)
 # # POUR TESTER, décommenter les lignes suivantes
 ##-----------------------------------------------
 
-GfWebservice._url = r"http://webservices-t.bas-rhin.fr/CG67.AstreGF.WebServices/public/WsPDE.asmx"
-AnalytiqueDb._path = Path(r"\\h2o\local\4-transversal\BDD\mdb_test\Db_analytique.mdb")
-logger.handlers = [h for h in logger.handlers if (type(h) == logging.StreamHandler)]
-logger.warning("<<<<<<<<<<<<<<   Mode TEST   >>>>>>>>>>>>>>>>>")
+# GfWebservice._url = r"http://webservices-t.bas-rhin.fr/CG67.AstreGF.WebServices/public/WsPDE.asmx"
+# AnalytiqueDb._path = Path(r"\\h2o\local\4-transversal\BDD\mdb_test\Db_analytique.mdb")
+# logger.handlers = [h for h in logger.handlers if (type(h) == logging.StreamHandler)]
+# logger.warning("<<<<<<<<<<<<<<   Mode TEST   >>>>>>>>>>>>>>>>>")
 
 ##-----------------------------------------------
 
@@ -72,7 +72,7 @@ def main():
                   """, facture.numExBudget, facture.numLiqMandat, facture.numMandat)):
             continue
 
-        logger.info("* Facture %s/%s/%s: import", facture.numExBudget, facture.numMandat, facture.numLiqMandat)
+        logger.info("* La facture %s/%s/%s sera importée", facture.numExBudget, facture.numMandat, facture.numLiqMandat)
 
         # # Auto-correction des données
         # correction auto des codes chantiers
@@ -82,7 +82,7 @@ def main():
         # echappe les apostrophes
         facture.libRai = facture.libRai.replace("'", "''")
 
-        # renomme automatiquement les noms de materiels
+        # corrige automatiquement les noms de materiels
         if facture.codeAxe == "ENGIN":
             row = analytique_db.first(Sql.format("""SELECT txtMateriel FROM tbl_materiel
                                             WHERE txtMateriel={codeCout:text} or txtMateriel='ZZ {codeCout}'
@@ -192,7 +192,7 @@ def main():
                          strObjet=facture.dateMandat.strftime("%d/%m/%Y"),
                          dblMontantTVA=facture.mntTvaMandat or 0,
                          dblMontantTotal=facture.mntVent or 0,
-                         strORIGINE_DONNEES='ASTRE'
+                         strORIGINE_DONNEES='ASTRE_{:%y%m%d}'.format(datetime.now())
                          )
         logger.debug("> %s", sql)
         analytique_db.execute(sql)

BIN
resources/CSVpad/CSVpad.exe


+ 0 - 20
resources/CSVpad/settings.ini

@@ -1,20 +0,0 @@
-[Settings]
-AutoResize=0
-Label=1
-Line1=clWhite
-Line2=$00EEEEEE
-FontColor=clBlack
-FontSize=10
-FontName=Arial
-FontStyle=
-labelc=clBtnFace
-
-[View]
-ToolBar=1
-StatusBar=1
-
-[Main]
-LID=1
-SID=1
-SettingsSave=1
-EID=1

+ 1 - 0
resources/test_gf2analytique.py

@@ -20,6 +20,7 @@ if __name__ == "__main__":
             analytique_db.execute("DELETE * FROM tbl_Facture_Affaire WHERE [dblFactureId]={}".format(factid))
             analytique_db.execute("DELETE * FROM tbl_Facture_Engin WHERE [dblFactureId]={}".format(factid))
             analytique_db.execute("DELETE * FROM tbl_Factures WHERE [dblFactureId]={}".format(factid))
+            analytique_db.execute("DELETE * FROM tbl_Mandatement WHERE [dblFacture]={}".format(factid))
 
         analytique_db.commit()