Commits

Raimon Esteve (Zikzakmedia)  committed ff90e74

Test methods + services method (default services envialia)

  • Participants
  • Parent commits e27bc85

Comments (0)

Files changed (4)

File envialia/__init__.py

 __version__ = '0.0.1'
 
 __all__ = [
-            'API',
-            'ENVXML',
-            'Picking',
-            ]
+    'API',
+    'ENVXML',
+    'Picking',
+]
 
 from api import API
 from envxml import ENVXML

File envialia/envxml.py

         '</ROClientIDHeader>' \
         '</soap:Header>' \
         '<soap:Body>' \
-        '<WebServService___ConsEtiquetaEnvio>' \
+        '<WebServService___ConsEtiquetaEnvio3>' \
         '<strCodAgeOri>%(agency_cargo)s</strCodAgeOri>' \
         '<strAlbaran>%(reference)s</strAlbaran>' \
-        '</WebServService___ConsEtiquetaEnvio>' \
+        '</WebServService___ConsEtiquetaEnvio3>' \
         '</soap:Body>' \
         '</soap:Envelope>' % {
             'session':session,

File envialia/picking.py

 from envialia.api import API
 
 from xml.dom.minidom import parseString
+import re
+import datetime
 
 class Picking(API):
     """
     """
     __slots__ = ( )
 
-    def list(self, date='2010-01-01'):
+    def list(self, date=None):
         """
-        Retreive list of pickings a date
+        Retreive list of pickings a date (get all deliveries by date)
 
-        :param date: String date YYYY-MM-DD
+        :param date: String date YYYY/MM/DD
 
-        :return: List of dictionaries of matching records
+        :return: List delivery references
         """
+        if not date:
+            today = datetime.date.today()
+            date = today.strftime('%Y/%m/%d')
+        deliveries = []
         envxml = ENVXML()
         data = envxml.envialia_xml_picking_list(self.session, date)
         data = self.connect(data)
         dom = parseString(data)
-        deliveries = dom.getElementsByTagName('INF_ENVIOS')
+        info = dom.getElementsByTagName('v1:strInfEnvios')
+        if info[0].firstChild:
+            info = info[0].firstChild.data
+            info = re.sub('<CONSULTA><INF_ENVIOS ', '', info)
+            info = re.sub('/></CONSULTA>', '', info)
+            infos = info.split('" ')
+            for inf in infos:
+                i = inf.split('="')
+                key = i[0]
+                value = i[1]
+                if key == 'V_ALBARAN':
+                    deliveries.append(value)
         return deliveries
 
     def info(self, reference, data):
 
         :return: List of dictionaries of matching records
         """
+        delivery = {}
         envxml = ENVXML()
         data = envxml.envialia_xml_picking_info(self.session, reference, data)
         data = self.connect(data)
         dom = parseString(data)
-        deliveries = dom.getElementsByTagName('INF_ENVIOS')
-        return deliveries
+        info = dom.getElementsByTagName('v1:strEnvio')
+        if info[0].firstChild:
+            info = info[0].firstChild.data
+            info = re.sub('<CONSULTA><ENVIOS ', '', info)
+            info = re.sub('/></CONSULTA>', '', info)
+            infos = info.split('" ')
+            for inf in infos:
+                i = inf.split("=")
+                key = re.sub("'", '', i[0])
+                value = i[1][1:]
+                delivery[key] = value
+        return delivery
 
     def create(self, data):
         """
 
         :param reference: String Reference
         :param data: Dictionary of values
-        :return: String
+        :return: True/False
         """
         envxml = ENVXML()
         data = envxml.envialia_xml_picking_delete(self.session, reference, data)
         dom = parseString(data)
         error = dom.getElementsByTagName('v1:intCodError')
         if error[0].firstChild:
-            return {'error':error[0].firstChild.data}
+            # return {'error':error[0].firstChild.data}
+            return False
         return True
 
     def state(self, reference, data):
         dom = parseString(data)
         state = dom.getElementsByTagName('v1:strEnvEstados')
         if not state[0].firstChild:
-            return False
+            return None
         return state[0].firstChild.data
 
     def label(self, reference, data):

File envialia/utils.py

     else:
         return 'http://wstest.envialia-urgente.com:9082/soap' #TODO: Change this URL to production
 
-
+def services():
+    services = {
+        '10':'Entrega antes de las 10h',
+        '100':'INT-COURIER',
+        '101':'INT-BAG',
+        '14':'Entrega antes de las 13h',
+        '200':'EU-ESTANDAR',
+        '24':'Entrega antes de las 19',
+        '300':'EU-PACK',
+        '301':'EU-BAG',
+        '72':'Entrega antes de 72h',
+        '830':'Entrega antes de las 8:30',
+        'CM':'Canarias Maritimo',
+        'DEV':'Devolucion',
+        'E24':'ECOMM 24 Entrega dia siguiente',
+        'E72':'ECOMM 72 Entrega en tres dias',
+        'EEU':'ECOMM Europe Express',
+        'EWW':'ECOMM Worldwide',
+        'RCS':'Retorno copia sellada',
+        'RED':'Recogeran en delegacion',
+        'RET':'Retorno',
+        'SMD':'Servicio Medio Dia',
+        'V00':'Valija Todo Dia',
+        'V10':'Valija 10h',
+        'V14':'Valija 14h',
+    }
+    return services