# 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
    _name = "paynet.service"
    _description = "Paynet service configuration"

    name = fields.Char(required=True)
    url = fields.Char(compute="_compute_url")
    username = fields.Char()
    password = fields.Char()
    client_pid = fields.Char(string="Paynet ID", size=17, required=True)
    use_test_service = fields.Boolean(string="Testing", help="Target the test service")
    service_type = fields.Selection(
        selection=[("b2b", "B2B"), ("b2c", "B2C")],
        string="Service type",
        default="b2b",
        help="Specify the type of XML exchange with the service.",
    )
    partner_bank_id = fields.Many2one(
        comodel_name="res.partner.bank", string="Bank account", ondelete="restrict"
    )
    invoice_message_ids = fields.One2many(
        comodel_name="paynet.invoice.message",
        inverse_name="service_id",
        string="Invoice Messages",
        readonly=True,
    )
    ebill_payment_contract_ids = fields.One2many(
        comodel_name="ebill.payment.contract",
        inverse_name="paynet_service_id",
        string="Contracts",
        readonly=True,
    )

# 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

    _name = "paynet.service"
    _description = "Paynet service configuration"

    name = fields.Char(required=True)
    url = fields.Char(compute="_compute_url")
    username = fields.Char()
    password = fields.Char()
    client_pid = fields.Char(string="Paynet ID", size=17, required=True)
    use_test_service = fields.Boolean(string="Testing", help="Target the test service")
    service_type = fields.Selection(
        selection=[("b2b", "B2B"), ("b2c", "B2C")],
        string="Service type",
        default="b2b",
        help="Specify the type of XML exchange with the service.",
    )
    partner_bank_id = fields.Many2one(
        comodel_name="res.partner.bank", string="Bank account", ondelete="restrict"
    )
    invoice_message_ids = fields.One2many(
        comodel_name="paynet.invoice.message",
        inverse_name="service_id",
        string="Invoice Messages",
        readonly=True,
    )
    ebill_payment_contract_ids = fields.One2many(
        comodel_name="ebill.payment.contract",
        inverse_name="paynet_service_id",
        string="Contracts",
        readonly=True,
    )

    active = fields.Boolean(default=True)