Skip to content
Snippets Groups Projects

Feature/contract catalog pack pagination

Merged Borja Gimeno requested to merge feature/contract-catalog-pack-pagination into master
All threads resolved!
Files
18
from odoo_somconnexio_python_client.client import Client
from odoo_somconnexio_python_client.resources.address import Address
from odoo_somconnexio_python_client.resources.odoo_paging import Paging
from ..exceptions import ResourceNotFound
default_limit = 100
default_offset = 0
default_sortBy = "id"
default_sortOrder = "DESCENDENT"
class PagingContracts:
# TODO: Add all the needed fields in the future...
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:
_url_path = "/contract"
@@ -40,6 +38,12 @@ class Contract:
date_end,
is_terminated,
fiber_signal,
description,
email,
subscription_type,
subscription_technology,
available_operations,
address,
**kwargs
):
self.id = id
@@ -58,29 +62,34 @@ class Contract:
self.date_end = date_end
self.is_terminated = is_terminated
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", {}))
self.description = description
self.email = email
self.subscription_type = subscription_type
self.subscription_technology = subscription_technology
self.available_operations = available_operations
self.address = Address(**address)
@classmethod
def paginated_search_by_customer_ref(
cls, customer_ref, limit=None, offset=None, sortBy=None, sortOrder=None
def search_by_customer_ref(
cls,
customer_ref,
limit=default_limit,
offset=default_offset,
sortBy=default_sortBy,
sortOrder=default_sortOrder,
):
"""
Search Contracts in Odoo by partner's ref and control paging params.
:return: Contracts object if exists and controls params to pagination
:return: Contracts objects if exists and controls params to pagination
"""
paging = Paging(
customer_ref=customer_ref,
limit=limit,
offset=limit,
sortOrder=limit,
offset=offset,
sortBy=sortBy,
sortOrder=sortOrder,
)
paging.validate_pagintion()
paging.validate_pagination()
params = {"customer_ref": customer_ref}
params.update(paging.__dict__)
@@ -90,33 +99,36 @@ class Contract:
)
@classmethod
def search_by_customer_ref(cls, customer_ref):
def search_by_customer_vat(
cls,
vat,
limit=default_limit,
offset=default_offset,
sortBy=default_sortBy,
sortOrder=default_sortOrder,
):
"""
Search Contracts in Odoo by partner's ref.
Search Contracts in Odoo by partner's vat and control paging params.
:return: Contracts object if exists
:return: Contracts objects if exists and controls params to pagination
"""
return cls._get(
params={
"customer_ref": customer_ref,
},
paging = Paging(
limit=limit,
offset=offset,
sortBy=sortBy,
sortOrder=sortOrder,
)
paging.validate_pagination()
params = {"partner_vat": vat}
params.update(paging.__dict__)
@classmethod
def search_by_customer_vat(cls, vat):
"""
Search Contract in Odoo by partner's vat.
:return: Contract object if exists
"""
return cls._get(
params={
"partner_vat": vat,
}
params=params,
is_paginated=True,
)
@classmethod
def search_by_phone_number(cls, phone_number):
def get_by_phone_number(cls, phone_number):
"""
Search Contract in Odoo by phone number.
@@ -129,7 +141,7 @@ class Contract:
)
@classmethod
def search_by_code(cls, code):
def get_by_code(cls, code):
"""
Search Contract in Odoo by code reference.
Loading