Skip to content
Snippets Groups Projects
Commit 75d0d946 authored by Borja Gimeno's avatar Borja Gimeno
Browse files

feat: add paging in Contract & isolate FiberContractsToPack

parent e67f928a
No related branches found
No related tags found
1 merge request!64Feature/contract catalog pack pagination
Pipeline #22715 passed
from odoo_somconnexio_python_client.client import Client from odoo_somconnexio_python_client.client import Client
from odoo_somconnexio_python_client.resources.odoo_paging import Paging
from ..exceptions import ResourceNotFound from ..exceptions import ResourceNotFound
class PagingContracts:
def __init__(self, contracts, paging):
self.contracts = contracts
self.paging = paging
class AddressContract:
def __init__(self, **kwargs):
self.street = kwargs.get("street")
self.zip = kwargs.get("zip")
self.city = kwargs.get("city")
class Contract: class Contract:
_url_path = "/contract" _url_path = "/contract"
...@@ -43,6 +57,37 @@ class Contract: ...@@ -43,6 +57,37 @@ class Contract:
self.date_end = date_end self.date_end = date_end
self.is_terminated = is_terminated self.is_terminated = is_terminated
self.fiber_signal = fiber_signal self.fiber_signal = fiber_signal
self.description = kwargs.get("description")
self.email = kwargs.get("email")
self.subscription_type = kwargs.get("subscription_type")
self.subscription_technology = kwargs.get("subscription_technology")
self.available_operations = kwargs.get("available_operations")
self.address = AddressContract(**kwargs.get("address", {}))
@classmethod
def paginated_search_by_customer_ref(cls, customer_ref, limit, offset):
"""
Search Contracts in Odoo by partner's ref and control paging params.
:return: Contracts object if exists and controls params to pagination
"""
return cls._get(
params={"customer_ref": customer_ref, "limit": limit, "offset": offset},
is_paginated=True,
)
@classmethod
def search_by_customer_ref(cls, customer_ref):
"""
Search Contracts in Odoo by partner's ref.
:return: Contracts object if exists
"""
return cls._get(
params={
"customer_ref": customer_ref,
},
)
@classmethod @classmethod
def search_by_customer_vat(cls, vat): def search_by_customer_vat(cls, vat):
...@@ -84,7 +129,7 @@ class Contract: ...@@ -84,7 +129,7 @@ class Contract:
) )
@classmethod @classmethod
def _get(cls, id=None, params={}): def _get(cls, id=None, params={}, is_paginated=False):
if id: if id:
url = "{}/{}".format(cls._url_path, id) url = "{}/{}".format(cls._url_path, id)
else: else:
...@@ -97,22 +142,14 @@ class Contract: ...@@ -97,22 +142,14 @@ class Contract:
if not response_data: if not response_data:
raise ResourceNotFound(resource=cls.__name__, filter=params) raise ResourceNotFound(resource=cls.__name__, filter=params)
return [cls(**contract_found) for contract_found in response_data] contracts = []
for contract_found in response_data.get("contracts", response_data):
contracts.append(cls(**contract_found))
class FiberContractsToPack(Contract):
_url_path = Contract._url_path + "/available-fibers-to-link-with-mobile"
@classmethod if not is_paginated:
def search_by_partner_ref(cls, partner_ref): return contracts
"""
Search available fiber contracts to pack
with in in Odoo, by their partner reference.
:return: Contract object if exists return PagingContracts(
""" contracts,
return cls._get( Paging(**response_data.get("paging", {})),
params={
"partner_ref": partner_ref,
}
) )
from odoo_somconnexio_python_client.client import Client
from odoo_somconnexio_python_client.resources.contract import Contract
from ..exceptions import ResourceNotFound
class FiberContractsToPack:
_url_path = "/contract/available-fibers-to-link-with-mobile"
@classmethod
def search_by_partner_ref(cls, partner_ref):
"""
Search available fiber contracts to pack
with in in Odoo, by their partner reference.
:return: Contract object if exists
"""
return cls._get(
params={
"partner_ref": partner_ref,
}
)
@classmethod
def _get(cls, params={}):
url = cls._url_path
response_data = Client().get(
url,
params=params,
)
if not response_data:
raise ResourceNotFound(resource=cls.__name__, filter=params)
return [Contract(**contract_found) for contract_found in response_data]
class Paging:
def __init__(self, **kwargs):
self.limit = kwargs.get("limit")
self.total_number_records = kwargs.get("totalNumberOfRecords")
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment