Browse Source

little fix

Sylhaf 8 months ago
parent
commit
373eb3e618
2 changed files with 19 additions and 14 deletions
  1. 19 14
      main.py
  2. BIN
      msedgedriver.exe

+ 19 - 14
main.py

@@ -127,7 +127,7 @@ class invoice_link :
     
 
     stripe_customer_ref    : str
-    stripe_customer_name   : str
+    stripe_customer_name   : str = ""
     stripe_customer_mail   : str
     stripe_paid_amount     : float
     stripe_epoch_date      : int
@@ -219,12 +219,16 @@ logger.info(" --- --------------------------------------------------------------
 from selenium import webdriver
 from selenium.webdriver.common.keys import Keys
 from selenium.webdriver.common.by import By
+from selenium.webdriver.edge.options import Options
 import logging
 from selenium.webdriver.remote.remote_connection import LOGGER
 LOGGER.setLevel(logging.CRITICAL)
 
-
 logger.info("CRM Login")
+
+# Launch Microsoft Edge (Chromium)
+options = Options()
+options.add_experimental_option('excludeSwitches', ['enable-logging'])
 driver = webdriver.Edge()
 driver.get(str(dolibarr_url) + "/index.php")
 assert "Identifiant" in driver.title
@@ -254,14 +258,14 @@ logger.info("iterating over invoice links")
 link : invoice_link
 for link in invoice_links :
     link.crm_contract_activated == False
-    logger.debug("treating contract : " + link.contract_number)
+    logger.info("treating contract : " + link.contract_number + " for " + link.stripe_customer_name)
     driver.get(dolibarr_url + "/contrat/card.php?id=" + str(link.contract_number))
     logger.debug("testing if services are activated")
     #iterating service 
 
 
     contract_lines = driver.find_elements(By.XPATH,"//div[contains(@id,'contrat-lines-container')]/div")
-    logger.info(str(len(contract_lines)) + " service line found")
+    logger.debug(str(len(contract_lines)) + " service line found")
     for line in contract_lines :
         
         try :
@@ -273,8 +277,8 @@ for link in invoice_links :
             
         service_status = line.find_element(By.CLASS_NAME,"badge-status").text
 
-        logger.info(service_name)
-        logger.info(service_status)
+        logger.debug(service_name)
+        logger.debug(service_status)
 
         if "En service" in service_status :
             logger.debug("crm contract have at least one service activated")
@@ -282,7 +286,7 @@ for link in invoice_links :
 
 
     if link.crm_contract_activated == False:
-        logger.info("the contract with  number " + link.contract_number + " have all services disabled, SKIPPING CONTRACT")
+        logger.debug("the contract with  number " + link.contract_number + " have all services disabled, SKIPPING CONTRACT")
         continue
 
     contract_links_table = driver.find_element(By.XPATH,'//table[@data-block="showLinkedObject"]')
@@ -307,14 +311,14 @@ for link in invoice_links :
             logger.debug("invoice is unpaid")
             current_invoice.unpaid = True
     
-        logger.info("-----")
+        logger.debug("-----")
         if link.is_stripe_link :
-            logger.info("CRM linked invoice for customer : " + link.stripe_customer_name + " - " + link.stripe_customer_mail)
-        logger.info("CRM linked invoice url : " + current_invoice.url)
-        logger.info("CRM linked invoice date : " + str(current_invoice.amount))
-        logger.info("CRM linked invoice amount : " + str(current_invoice.date))
-        logger.info("CRM linked invoice unpaid ?  : " + str(current_invoice.unpaid))
-        logger.info("-----")
+            logger.debug("CRM linked invoice for customer : " + link.stripe_customer_name + " - " + link.stripe_customer_mail)
+        logger.debug("CRM linked invoice url : " + current_invoice.url)
+        logger.debug("CRM linked invoice date : " + str(current_invoice.amount))
+        logger.debug("CRM linked invoice amount : " + str(current_invoice.date))
+        logger.debug("CRM linked invoice unpaid ?  : " + str(current_invoice.unpaid))
+        logger.debug("-----")
     
       
 
@@ -471,4 +475,5 @@ logger.info(" --- --------------------------------------------------------------
 
 
 driver.close()
+driver.quit()
 exit(0)

BIN
msedgedriver.exe