Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • coopdevs/som-connexio/odoo/odoo-somconnexio-python-client
1 result
Show changes
Commits on Source (40)
Showing
with 397 additions and 26 deletions
......@@ -5,6 +5,30 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## [Unreleased]
## [0.1.26] - 2022-07-26
### Added
* Add has_landline_phone to product_catalog. [#41](https://git.coopdevs.org/coopdevs/som-connexio/odoo-somconnexio-python-client/-/merge_requests/41)
## [0.1.25] - 2022-07-06
### Added
* Add kwargs in constructor for models: address, broadband_isp, crm_lead, crm_lead_line, discoveryChannel, mobile_isp_info,product_catalog, and provider. [#42](https://git.coopdevs.org/coopdevs/som-connexio/odoo-somconnexio-python-client/-/merge_requests/42)
## [0.1.24] - 2022-06-30
### Added
* Add Sponsees model and methods to search them in Partner (by ref). [#35](https://git.coopdevs.org/coopdevs/som-connexio/odoo-somconnexio-python-client/-/merge_requests/35)
## [0.1.23] - 2022-06-16
### Added
* Add Contract model and methods to search them (by customer vat or by phone number). [#37](https://gitlab.com/coopdevs/odoo-somconnexio-python-client/-/merge_requests/37)
## [0.1.22] - 2022-06-08
### Added
* Add banned_actions to Partner object returned in get methods. [#36](https://gitlab.com/coopdevs/odoo-somconnexio-python-client/-/merge_requests/36)
## [0.1.21] - 2022-06-01
### Added
* Add addresses to Partner object returned in get methods. [#24](https://gitlab.com/coopdevs/odoo-somconnexio-python-client/-/merge_requests/24)
## [0.1.20] - 2022-04-20
### Added
* Add check_sponsor method to Partner resource [#32](https://gitlab.com/coopdevs/odoo-somconnexio-python-client/-/merge_requests/32)
......
......@@ -13,6 +13,7 @@ More info about the customizations in [SomConnexio Odoo module](https://gitlab.c
* Provider - Service providers
* DiscoveryChannel
* Partner - Customer information
* Contract - Contract information
## Installation
......@@ -26,7 +27,7 @@ You need define the Odoo API-KEY and URL as environment variables. You need defi
```
ODOO_BASEURL=<YOUR ODOO HOST>/api
ODOO_APIKEY=<YOUR OC USER>
ODOO_APIKEY=<YOUR ODOO API KEY>
```
If this envvars are not defined, a exception will be raised with the name of the envvar not defined.
......@@ -70,9 +71,21 @@ More info about the API-KEY in [Auth API Key](https://github.com/OCA/server-auth
"1234"
```
#### Search Contracts by partner's VAT number
```python
>>> from odoo_somconnexio_python_client.resources.contract import Contract
>>>
>>> contracts = Contract.search_by_customer_vat(vat="XXXX")
>>> contracts[0].id
123
>>> contracts[0].phone_number
"972445566"
```
### Create new mapper
Create a class that expose a dict objecti with the next structure:
Create a class that exposes a dict object with the next structure:
#### Create a SubscriptionRequest
......@@ -190,9 +203,9 @@ With VRC we can catch the HTTP responses and then, execute the tests using them.
To add a new test:
* Exepose the needes envvars. Looks the Configuration Environment section
* Expose the needed envvars. Look for them at the [Configuration Environment section](#configuration-environment)
* Execute the tests using `pytest` command:
* If you are writing a new tests that is making requests, you should run:
* If you are writing a new test that is making requests, you should run:
```
$ pytest --record-mode=once path/to/your/test
......@@ -233,7 +246,7 @@ Update CHANGELOG.md following this steps:
Then, you can release and publish the package to PyPi:
1. Update the `VERSION` var in `setup.py` matching the version you specified in the CHANGELOG.
1. Update the `__version__` var in `__init__.py` matching the version you specified in the CHANGELOG.
1. Open a merge request with these changes for the team to approve
1. Merge it, add a git tag on that merge commit and push it.
1. Once the pipeline has successfully passed, go approve the `publish` step.
__version__ = "0.1.20"
__version__ = "0.1.26"
......@@ -15,7 +15,7 @@ class Address:
"""
def __init__(
self, street="", zip_code="", city="", state="", country="", street2=None
self, street="", zip_code="", city="", state="", country="", street2=None, **kwargs
):
self.street = street
self.street2 = street2
......
......@@ -16,6 +16,7 @@ class BroadbandISPInfo:
change_address="no",
delivery_address=None,
invoice_address=None,
**kwargs
):
self.phone_number = phone_number
self.type = type
......
from odoo_somconnexio_python_client.client import Client
from ..exceptions import ResourceNotFound
class Contract:
_url_path = "/contract"
# TODO: Add all the needed fields in the future...
def __init__(
self,
id,
code,
customer_firstname,
customer_lastname,
customer_ref,
customer_vat,
phone_number,
current_tariff_product,
technology,
supplier,
iban,
ticket_number,
date_start,
date_end,
is_terminated,
**kwargs
):
self.id = id
self.code = code
self.customer_firstname = customer_firstname
self.customer_lastname = customer_lastname
self.customer_ref = customer_ref
self.customer_vat = customer_vat
self.phone_number = phone_number
self.current_tariff_product = current_tariff_product
self.technology = technology
self.supplier = supplier
self.iban = iban
self.ticket_number = ticket_number
self.date_start = date_start
self.date_end = date_end
self.is_terminated = is_terminated
@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,
}
)
@classmethod
def search_by_phone_number(cls, phone_number):
"""
Search Contract in Odoo by phone number.
:return: Contract object if exists
"""
return cls._get(
params={
"phone_number": phone_number,
}
)
@classmethod
def _get(cls, id=None, params={}):
if id:
url = "{}/{}".format(cls._url_path, id)
else:
url = cls._url_path
response_data = Client().get(
url,
params=params,
)
if not response_data:
raise ResourceNotFound(resource=cls.__name__, filter=params)
return [cls(**contract_found) for contract_found in response_data]
......@@ -13,6 +13,7 @@ class CRMLead:
lead_line_ids=None,
subscription_request_id=None,
partner_id=None,
**kwargs
):
lead_lines = []
if lead_line_ids:
......
......@@ -3,7 +3,7 @@ from odoo_somconnexio_python_client.resources.mobile_isp_info import MobileISPIn
class CRMLeadLine:
def __init__(self, product_code, broadband_isp_info=None, mobile_isp_info=None):
def __init__(self, product_code, broadband_isp_info=None, mobile_isp_info=None, **kwargs):
self.product_code = product_code
if broadband_isp_info:
self.broadband_isp_info = BroadbandISPInfo(**broadband_isp_info)
......
......@@ -4,7 +4,7 @@ from odoo_somconnexio_python_client.client import Client
class DiscoveryChannel:
_url_path = "/discovery-channel"
def __init__(self, id, name):
def __init__(self, id, name, **kwargs):
self.id = id
self.name = name
......
......@@ -15,6 +15,7 @@ class MobileISPInfo:
previous_contract_type="no",
delivery_address=None,
invoice_address=None,
**kwargs
):
self.phone_number = phone_number
self.type = type
......
from odoo_somconnexio_python_client.client import Client
from odoo_somconnexio_python_client.resources.address import Address
from .sponsees import Sponsees
from ..exceptions import ResourceNotFound
......@@ -29,6 +31,8 @@ class Partner:
sponsorship_code,
sponsees_max,
sponsees_number,
addresses,
banned_actions,
**kwargs
):
self.id = id
......@@ -51,6 +55,10 @@ class Partner:
self.sponsorship_code = sponsorship_code
self.sponsees_max = sponsees_max
self.sponsees_number = sponsees_number
self.addresses = []
for address in addresses:
self.addresses.append(Address(**address))
self.banned_actions = banned_actions
@classmethod
def get(cls, ref):
......@@ -97,6 +105,21 @@ class Partner:
raise ResourceNotFound(resource=cls.__name__, filter=params)
return response_data["result"] == "allowed", response_data["message"]
@classmethod
def sponsees(cls, ref):
"""
Get sponsees info from a Partner using the ref param.
:return: sponsees object if exists
"""
url = Sponsees._url_path
params = {"ref": ref}
response_data = Client().get(url, params=params)
if not response_data:
raise ResourceNotFound(resource=cls.__name__, filter={})
return Sponsees(**response_data)
@classmethod
def _get(cls, id=None, params={}):
if id:
......
......@@ -3,7 +3,17 @@ from odoo_somconnexio_python_client.client import Client
class Product:
def __init__(
self, name, code, price, category="", minutes="", data="", bandwidth="", available_for=[]
self,
name,
code,
price,
category="",
minutes="",
data="",
bandwidth="",
available_for=[],
has_landline_phone=False,
**kwargs
):
self.code = code
self.name = name
......@@ -13,6 +23,7 @@ class Product:
self.data = data
self.bandwidth = bandwidth
self.available_for = available_for
self.has_landline_phone = has_landline_phone
class ProductCatalog:
......
......@@ -4,7 +4,7 @@ from odoo_somconnexio_python_client.client import Client
class Provider:
_url_path = "/provider"
def __init__(self, id, name):
def __init__(self, id, name, **kwargs):
self.id = id
self.name = name
......
class Sponsees:
_url_path = "/partner/sponsees"
def __init__(
self,
sponsorship_code,
sponsees_max,
sponsees_number,
sponsees,
**kwargs
):
self.sponsorship_code = sponsorship_code
self.sponsees_max = sponsees_max
self.sponsees_number = sponsees_number
self.sponsees_list = sponsees
interactions:
- request:
body: null
headers:
API-KEY:
- DUMMY
Accept:
- application/json
Accept-Encoding:
- gzip, deflate
Connection:
- keep-alive
User-Agent:
- python-requests/2.27.1
method: GET
uri: http://odoo-sc.local:8069/api/contract?phone_number=676858494
response:
body:
string: '[{"id": 59, "code": "78979", "customer_firstname": "Felip", "customer_lastname":
"Dara", "customer_ref": "1234", "customer_vat": "ES55642302N", "phone_number":
"676858494", "current_tariff_product": "SE_SC_REC_MOBILE_T_150_1024", "ticket_number":
"456352563", "technology": "Mobile", "supplier": "M\u00e1sM\u00f3vil", "lang":
"es_ES", "iban": "ES6621000418401234567891", "is_terminated": false, "date_start":
"2022-06-14", "date_end": false}]'
headers:
Access-Control-Allow-Methods:
- GET
Access-Control-Allow-Origin:
- None
Content-Length:
- '442'
Content-Type:
- application/json
Date:
- Thu, 16 Jun 2022 10:00:02 GMT
Server:
- Werkzeug/0.11.15 Python/3.7.7
Set-Cookie:
- session_id=17c00746057a7e75ceb2b8cdc071edafae33a906; Expires=Wed, 14-Sep-2022
10:00:02 GMT; Max-Age=7776000; HttpOnly; Path=/
status:
code: 200
message: OK
version: 1
interactions:
- request:
body: null
headers:
API-KEY:
- DUMMY
Accept:
- application/json
Accept-Encoding:
- gzip, deflate
Connection:
- keep-alive
User-Agent:
- python-requests/2.27.1
method: GET
uri: http://odoo-sc.local:8069/api/contract?partner_vat=ES55642302N
response:
body:
string: '[{"id": 58, "code": "34636", "customer_firstname": "Felip", "customer_lastname":
"Dara", "customer_ref": "1234", "customer_vat": "ES55642302N", "phone_number":
"879786754", "current_tariff_product": "SE_SC_REC_BA_F_100", "ticket_number":
"63636", "technology": "Fiber", "supplier": "M\u00e1sM\u00f3vil", "lang":
"es_ES", "iban": "ES6621000418401234567891", "is_terminated": false, "date_start":
"2022-05-20", "date_end": false}, {"id": 59, "code": "78979", "customer_firstname":
"Felip", "customer_lastname": "Dara", "customer_ref": "1234", "customer_vat":
"ES55642302N", "phone_number": "676858494", "current_tariff_product": "SE_SC_REC_MOBILE_T_150_1024",
"ticket_number": "456352563", "technology": "Mobile", "supplier": "M\u00e1sM\u00f3vil",
"lang": "es_ES", "iban": "ES6621000418401234567891", "is_terminated": false,
"date_start": "2022-06-14", "date_end": false}]'
headers:
Access-Control-Allow-Methods:
- GET
Access-Control-Allow-Origin:
- None
Content-Length:
- '870'
Content-Type:
- application/json
Date:
- Thu, 16 Jun 2022 10:00:02 GMT
Server:
- Werkzeug/0.11.15 Python/3.7.7
Set-Cookie:
- session_id=0aca6efbdf9c1e027b5244c5b053eee47a56489a; Expires=Wed, 14-Sep-2022
10:00:02 GMT; Max-Age=7776000; HttpOnly; Path=/
status:
code: 200
message: OK
version: 1
interactions:
- request:
body: null
headers:
API-KEY:
- DUMMY
Accept:
- application/json
Accept-Encoding:
- gzip, deflate
Connection:
- keep-alive
User-Agent:
- python-requests/2.27.1
method: GET
uri: http://odoo-sc.local:8069/api/contract?partner_vat=ES3208282S
response:
body:
string: '{"code": 404, "name": "Not Found"}'
headers:
Content-Length:
- '34'
Content-Type:
- application/json
Date:
- Thu, 16 Jun 2022 10:00:02 GMT
Server:
- Werkzeug/0.11.15 Python/3.7.7
status:
code: 404
message: NOT FOUND
version: 1
interactions:
- request:
body: null
headers:
API-KEY:
- '****'
Accept:
- application/json
Accept-Encoding:
- gzip, deflate
Connection:
- keep-alive
User-Agent:
- python-requests/2.27.1
method: GET
uri: http://odoo-sc.local:8069/api/partner/sponsees?ref=NOT_EXISTS
response:
body:
string: '{"code": 404, "name": "Not Found"}'
headers:
Content-Length:
- '34'
Content-Type:
- application/json
Cookie: '****'
Date:
- Thu, 30 Jun 2022 11:23:51 GMT
Server:
- Werkzeug/0.11.15 Python/3.7.7
Set-Cookie: '****'
status:
code: 404
message: NOT FOUND
version: 1
interactions:
- request:
body: null
headers:
API-KEY:
- '****'
Accept:
- application/json
Accept-Encoding:
- gzip, deflate
Connection:
- keep-alive
User-Agent:
- python-requests/2.27.1
method: GET
uri: http://odoo-sc.local:8069/api/partner/sponsees?ref=1234
response:
body:
string: '{"sponsorship_code": "RYR6O", "sponsees_max": 5, "sponsees_number":
1, "sponsees": ["Joanau Basu"]}'
headers:
Content-Length:
- '99'
Content-Type:
- application/json
Cookie: '****'
Date:
- Thu, 30 Jun 2022 11:23:51 GMT
Server:
- Werkzeug/0.11.15 Python/3.7.7
Set-Cookie: '****'
status:
code: 200
message: OK
version: 1
......@@ -2,8 +2,8 @@ interactions:
- request:
body: null
headers:
!!python/unicode 'API-KEY':
- !!python/unicode 'DUMMY'
API-KEY:
- DUMMY
Accept:
- application/json
Accept-Encoding:
......@@ -11,7 +11,7 @@ interactions:
Connection:
- keep-alive
User-Agent:
- python-requests/2.22.0
- python-requests/2.27.1
method: GET
uri: http://odoo-sc.local:8069/api/partner/1234
response:
......@@ -21,23 +21,26 @@ interactions:
"vat": "ES55642302N", "type": "representative", "email": "felipdata@demo.net",
"phone": "", "mobile": "", "cooperator_register_number": 855, "cooperator_end_date":
"", "sponsor_id": 0, "coop_agreement_code": "", "coop_candidate": false, "member":
true, "sponsorship_code": "12345", "sponsees_max": 5, "sponsees_number": 2}'
true, "sponsorship_code": "12345", "sponsees_max": 5, "sponsees_number": 2, "addresses":
[{"street": "Carrer del Penal, 2", "zip_code": "17855", "city": "Oix", "country":
"Spain", "state": "Girona (Gerona)"}], "banned_actions": ["mobile_one_shot",
"mobile_tariff_change", "new_service"]}'
headers:
access-control-allow-methods:
Access-Control-Allow-Methods:
- GET
access-control-allow-origin:
Access-Control-Allow-Origin:
- None
content-length:
- '383'
content-type:
Content-Length:
- '517'
Content-Type:
- application/json
date:
- Mon, 18 Jan 2021 15:31:34 GMT
server:
Date:
- Wed, 19 Jan 2022 09:24:32 GMT
Server:
- Werkzeug/0.11.15 Python/3.7.7
set-cookie:
- session_id=82cf8ab00ba8e0facd5a2ddac265e70d77bfc7f8; Expires=Sun, 18-Apr-2021
15:31:34 GMT; Max-Age=7776000; HttpOnly; Path=/
Set-Cookie:
- session_id=7bbc7f3ced360754ef8243715949ee210d187d12; Expires=Tue, 19-Apr-2022
09:24:32 GMT; Max-Age=7776000; HttpOnly; Path=/
status:
code: 200
message: OK
......