# Path: ebill_paynet/components/api.py
# class PayNetDWS:
#     """PayNet DWS web services."""
# 
#     def __init__(self, url, test_service):
#         settings = zeep.Settings(xml_huge_tree=True)
#         session = requests.Session()
#         if test_service:
#             session.verify = SSL_TEST_CERTIFICATE
#         else:
#             session.verify = SSL_PROD_CERTIFICATE
#         transport = zeep.transports.Transport(session=session)
#         self.client = zeep.Client(WSDL_DOC, transport=transport, settings=settings)
#         if url:
#             self.service = self.client.create_service(
#                 "{http://www.sap.com/DWS}DWSBinding", url
#             )
#         else:
#             self.service = self.client.service
# 
#     @staticmethod
#     def authorization(userid, password):
#         """Generate Authorization node."""
#         return {"UserName": userid, "Password": password}
# 
#     @staticmethod
#     def handle_fault(fault):
#         msg = ("{}\n" "code: {} -> {}\n" "actor: {}\n" "detail: {}\n").format(
#             fault.message.upper(),
#             fault.code,
#             fault.subcodes,
#             fault.actor,
#             html.tostring(fault.detail),
#         )
#         _logger.info("Paynet DWS fault : {}".format(msg))
#         return msg


import logging
import zeep
from lxml import etree
from odoo import api, fields, models
from odoo.exceptions import UserError
from ..components.api import PayNetDWS
    active = fields.Boolean(default=True)

    @api.depends("use_test_service")
    def _compute_url(self):
        for record in self:
            if record.use_test_service:
                record.url = SYSTEM_TEST_URL
            else:
                record.url = SYSTEM_PROD_URL

    def take_shipment(self, content):
        """Send a shipment via DWS to the Paynet System

        Return value is the shipment id
        """
        self.ensure_one()
        dws = PayNetDWS(self.url, self.use_test_service)
        content = content.encode("utf-8")
        res = dws.service.takeShipment(
            Authorization=dws.authorization(self.username, self.password),
            # ProcessingDate  : Preferred processing date,
            #                   if not provided, processed asap
            # ShipmentPriority: Value between 1 and 9 (default is 5)
            Content=content,
        )
        return res

    def get_shipment_list(self):
        """Get a list of shipments present on the DWS."""
        self.ensure_one()

# Path: ebill_paynet/components/api.py
# class PayNetDWS:
#     """PayNet DWS web services."""
# 
#     def __init__(self, url, test_service):
#         settings = zeep.Settings(xml_huge_tree=True)
#         session = requests.Session()
#         if test_service:
#             session.verify = SSL_TEST_CERTIFICATE
#         else:
#             session.verify = SSL_PROD_CERTIFICATE
#         transport = zeep.transports.Transport(session=session)
#         self.client = zeep.Client(WSDL_DOC, transport=transport, settings=settings)
#         if url:
#             self.service = self.client.create_service(
#                 "{http://www.sap.com/DWS}DWSBinding", url
#             )
#         else:
#             self.service = self.client.service
# 
#     @staticmethod
#     def authorization(userid, password):
#         """Generate Authorization node."""
#         return {"UserName": userid, "Password": password}
# 
#     @staticmethod
#     def handle_fault(fault):
#         msg = ("{}\n" "code: {} -> {}\n" "actor: {}\n" "detail: {}\n").format(
#             fault.message.upper(),
#             fault.code,
#             fault.subcodes,
#             fault.actor,
#             html.tostring(fault.detail),
#         )
#         _logger.info("Paynet DWS fault : {}".format(msg))
#         return msg


# Path: ebill_paynet/models/paynet_service.py
import logging
import zeep
from lxml import etree
from odoo import api, fields, models
from odoo.exceptions import UserError
from ..components.api import PayNetDWS

    active = fields.Boolean(default=True)

    @api.depends("use_test_service")
    def _compute_url(self):
        for record in self:
            if record.use_test_service:
                record.url = SYSTEM_TEST_URL
            else:
                record.url = SYSTEM_PROD_URL

    def take_shipment(self, content):
        """Send a shipment via DWS to the Paynet System

        Return value is the shipment id
        """
        self.ensure_one()
        dws = PayNetDWS(self.url, self.use_test_service)
        content = content.encode("utf-8")
        res = dws.service.takeShipment(
            Authorization=dws.authorization(self.username, self.password),
            # ProcessingDate  : Preferred processing date,
            #                   if not provided, processed asap
            # ShipmentPriority: Value between 1 and 9 (default is 5)
            Content=content,
        )
        return res

    def get_shipment_list(self):
        """Get a list of shipments present on the DWS."""
        self.ensure_one()

        dws = PayNetDWS(self.url, self.use_test_service)