Browse Source

pep8 | doliarrbAlchemy.py

Philippe Le Brouster 9 years ago
parent
commit
2a04dcfa12
2 changed files with 44 additions and 39 deletions
  1. 26 18
      himports/dolibarrAlchemy.py
  2. 18 21
      himports/dolibarrAlchemyHledger.py

+ 26 - 18
himports/dolibarrAlchemy.py

@@ -1,19 +1,11 @@
 # -*- coding: utf-8 -*-
 from __future__ import unicode_literals
 
-import datetime
-
-import settings
-import MySQLdb as mdb
-import sys
-import os
-import codecs
-
-from sqlalchemy import Column, Integer, ForeignKey, UniqueConstraint, PrimaryKeyConstraint, Float
-from sqlalchemy.orm import relationship, backref, sessionmaker
+from sqlalchemy import Column, Integer, ForeignKey, UniqueConstraint
+from sqlalchemy.orm import relationship, sessionmaker
 from sqlalchemy.ext.declarative import declarative_base, DeferredReflection
 
-from sqlalchemy import create_engine, MetaData, select, join
+from sqlalchemy import create_engine, MetaData
 
 Base = declarative_base(cls=DeferredReflection)
 
@@ -422,11 +414,17 @@ MYSQL_QUERIES = {
                   p.ref as p_ref,
                   p.label as p_label,
                   p.accountancy_code_buy as p_accountancy_code_buy,
-                  a.account_number as a_account_number FROM llx_societe as s LEFT JOIN llx_c_pays as c ON s.fk_pays = c.rowid,
-                  llx_facture_fourn as f LEFT JOIN llx_facture_fourn_extrafields as extra ON f.rowid = extra.fk_object ,
-                  llx_facture_fourn_det as fd LEFT JOIN llx_product as p on (fd.fk_product = p.rowid) LEFT JOIN llx_accountingaccount as a ON fd.fk_code_ventilation = a.rowid WHERE f.fk_soc = s.rowid AND f.rowid = fd.fk_facture_fourn AND f.entity = 1",
-
-    "social": "SELECT DISTINCT cc.libelle as cc_libelle,
+                  a.account_number as a_account_number FROM llx_societe as s
+                  LEFT JOIN llx_c_pays as c
+                    ON s.fk_pays = c.rowid, llx_facture_fourn as f
+                  LEFT JOIN llx_facture_fourn_extrafields as extra
+                    ON f.rowid = extra.fk_object, llx_facture_fourn_det as fd
+                  LEFT JOIN llx_product as p on (fd.fk_product = p.rowid)
+                  LEFT JOIN llx_accountingaccount as a
+                    ON fd.fk_code_ventilation = a.rowid
+                    WHERE f.fk_soc = s.rowid AND f.rowid = fd.fk_facture_fourn AND f.entity = 1""",
+
+    "social": """SELECT DISTINCT cc.libelle as cc_libelle,
                   c.rowid as c_rowid,
                   c.libelle as c_libelle,
                   c.date_ech as c_date_ech,
@@ -439,14 +437,24 @@ MYSQL_QUERIES = {
                   p.num_paiement as p_num_paiement,
                   cc.accountancy_code as cc_acc_code,
                   cc.code as cc_code FROM llx_c_chargesociales as cc,
-                  llx_chargesociales as c LEFT JOIN llx_paiementcharge as p ON p.fk_charge = c.rowid WHERE c.fk_type = cc.id AND c.entity = 1""",
+                  llx_chargesociales as c
+                  LEFT JOIN llx_paiementcharge as p
+                    ON p.fk_charge = c.rowid
+                    WHERE c.fk_type = cc.id AND c.entity = 1""",
 
 }
 
 
 class DolibarrSQLAlchemy(object):
 
-    def __init__(self, mysql_host, mysql_port, mysql_database, mysql_user, mysql_password, echo = False):
+    def __init__(
+            self,
+            mysql_host,
+            mysql_port,
+            mysql_database,
+            mysql_user,
+            mysql_password,
+            echo=False):
         self.mysql_database = mysql_database
         self.mysql_host = mysql_host
         self.mysql_password = mysql_password

+ 18 - 21
himports/dolibarrAlchemyHledger.py

@@ -2,7 +2,7 @@
 from __future__ import unicode_literals
 
 import settings
-
+import datetime
 import decimal
 
 from himports.dolibarrAlchemy import *
@@ -78,7 +78,7 @@ class HledgerJournal(object):
                 by_year[entry_year] = []
             by_year[entry_year].append(entry)
         return by_year
-    
+
     def check_pc(self):
         pc_missing = set()
         for entry in self.get_entries():
@@ -90,16 +90,16 @@ class HledgerJournal(object):
 class HledgerBankEntry(HledgerEntry):
     sql_class = Bank
     k_accounting_date = 'datev'
-   
+
     @classmethod
     def get_third_code(cls, e):
         third_code = ""
         if e.url_payment_supplier:
             if e.url_company:
                 third_code = e.url_company.societe.code_compta_fournisseur
-        
+
         if e.url_payment_sc:
-            code = e.url_payment_sc.payment_sc.cotisation_sociale.type.code 
+            code = e.url_payment_sc.payment_sc.cotisation_sociale.type.code
             if code in settings.get('SOCIAL_REFS'):
                 third_code = settings.get('SOCIAL_REFS')[code]
 
@@ -110,7 +110,7 @@ class HledgerBankEntry(HledgerEntry):
         if third_code == "":
             fn = settings.get('PC_REFS')['fn_custom_code']
             third_code = fn(e)
-        
+
         if third_code == "":
             third_code = cls.pc_default_tiers
 
@@ -167,7 +167,7 @@ class HledgerBankEntry(HledgerEntry):
             'account': settings.get_ledger_account(third_code),
             'amount': self._value(e.amount)
         }
-        
+
         if e.url_payment_supplier:
             for f in e.url_payment_supplier.payment_supplier.factures:
                 tvas = HledgerSupplierEntry.get_tva_paiement_amounts(f.facture, journal="bank")
@@ -234,7 +234,7 @@ class HledgerFactureEntry(HledgerEntry):
                         tvas[tva_account] = 0
                     tvas[tva_account] += -total_tva
                     tvas[tva_regul] += total_tva
- 
+
             elif journal == "sell" or journal == "supplier":
                 if ed.product_type == 1 and cls.tva_type == 'standard':
                     if tva_regul not in tvas:
@@ -246,11 +246,11 @@ class HledgerFactureEntry(HledgerEntry):
                     tvas[tva_account] += -total_tva
 
         return tvas
-    
+
     @classmethod
     def get_tva_regul_account(cls, ed):
         tx = int(float(ed.tva_tx) * 100)
-        
+
         key = "tva_regul_%s" % (tx,)
 
         return settings.get('PC_REFS')[key]
@@ -323,7 +323,7 @@ class HledgerSupplierEntry(HledgerFactureEntry):
                 'compte_produit': settings.get_ledger_account(p_code),
                 'amount_ht': self._value(-ed.total_ht)
             }
-        
+
         tvas = self.get_tva_facture_amounts(self.e, journal="supplier")
         for k in tvas:
             s += "    %(compte_tva)s \t %(amount_tva)s\n" % {
@@ -332,12 +332,12 @@ class HledgerSupplierEntry(HledgerFactureEntry):
             }
 
         return s
-  
+
     @classmethod
     def get_tva_account(cls, ed):
         p_code = cls.get_product_account_code(ed)
         tx = int(float(ed.tva_tx) * 100)
-        
+
         if p_code.startswith("2"):
             prefix = 'tva_deductible'
         else:
@@ -356,7 +356,7 @@ class HledgerSupplierEntry(HledgerFactureEntry):
         else:
             p_code = cls.pc_default_charge
         return p_code
-   
+
     @classmethod
     def get_supplier_code(cls, e):
         s_code = e.societe.code_compta_fournisseur
@@ -387,7 +387,7 @@ class HledgerSellEntry(HledgerFactureEntry):
             'amount_ttc': self._value(-e.total_ttc),
 
         }
-        
+
         # lignes pour compte de produits
         for ed in e.details:
             p_code = self.get_product_account_code(ed)
@@ -405,7 +405,7 @@ class HledgerSellEntry(HledgerFactureEntry):
             }
 
         return s
-    
+
     @classmethod
     def get_tva_account(cls, ed):
         tx = int(float(ed.tva_tx) * 100)
@@ -468,7 +468,7 @@ class HledgerSellEntry(HledgerFactureEntry):
 class HledgerSocialEntry(HledgerEntry):
     sql_class = CotisationsSociales
     k_accounting_date = 'date_ech'
-    
+
     @classmethod
     def get_entries(cls, session):
         return [cls(e) for e in session.query(cls.sql_class).order_by(CotisationsSociales.date_ech).all()]
@@ -490,7 +490,7 @@ class HledgerSocialEntry(HledgerEntry):
         if s_code == "":
             s_code = cls.pc_default_charge
         return s_code
-    
+
     def getMissingPC(self):
         pc_missing = []
         if self.get_social_code(self.e) == self.pc_default_charge:
@@ -543,6 +543,3 @@ class HledgerDolibarrSQLAlchemy(DolibarrSQLAlchemy):
 
     def get_social_journal(self):
         return HledgerJournal(self.session, HledgerSocialEntry)
-
-
-