⚠️ WORK IN PROGRESS ⚠️
This library is a Python wrapper for accessing Somconnexio's Odoo (Odoo v12 with customizations). More info about the customizations in SomConnexio Odoo module.
Resources
- SubscriptionRequest - Customer order
- CRMLead - Service order
- Provider - Service providers
- DiscoveryChannel
- Partner - Customer information
- Contract - Contract information
- ProductCatalog - Sales product variants
- CoopAgreement - lit for coop agreement code
Installation
$ pip install odoo-somconnexio-python-client
Configuration Environment
You need define the Odoo API-KEY and URL as environment variables. You need define:
ODOO_BASEURL=<YOUR ODOO HOST>/api
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. More info about the API-KEY in Auth API Key Odoo module.
Usage
Search providers by service
>>> from odoo_somconnexio_python_client.resources.provider import Provider
>>>
>>> mobile_providers = Provider.mobile_list()
>>> mobile_providers[0].id
123
>>> mobile_providers[0].name
"SomConnexió"
Get Partner with ref
>>> from odoo_somconnexio_python_client.resources.partner import Partner
>>>
>>> partner = Partner.get(1234)
>>> partner.id
123
>>> partner.ref
"1234"
Search Partner by VAT number
>>> from odoo_somconnexio_python_client.resources.partner import Partner
>>>
>>> partner = Partner.search_by_vat(vat="XXXX")
>>> partner.id
123
>>> partner.ref
"1234"
Search Contracts by partner's VAT number
>>> 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 exposes a dict object with the next structure:
Create a SubscriptionRequest
{
"name": "string",
"email": "string",
"ordered_parts": 0,
"share_product": 0,
"address": {
"street": "string",
"street2": "string",
"zip_code": "string",
"city": "string",
"country": "string",
"state": "string"
},
"lang": "string",
"iban": "string",
"vat": "string",
"coop_agreement": "string",
"voluntary_contribution": 0,
"nationality": "string",
"payment_type": "string"
}
Create a CRMLead
{
"iban": "string",
"subscription_request_id": 0,
"partner_id": 0,
"lead_line_ids": [
{
"product_code": "string",
"broadband_isp_info": {
"phone_number": "string",
"type": "string",
"delivery_address": {
"street": "string",
"street2": "string",
"zip_code": "string",
"city": "string",
"country": "string",
"state": "string"
},
"previous_provider": 0,
"previous_owner_vat_number": "string",
"previous_owner_name": "string",
"previous_owner_first_name": "string",
"service_address": {
"street": "string",
"street2": "string",
"zip_code": "string",
"city": "string",
"country": "string",
"state": "string"
},
"previous_service": "string",
"keep_phone_number": true,
"change_address": true
},
"mobile_isp_info": {
"phone_number": "string",
"type": "string",
"delivery_address": {
"street": "string",
"street2": "string",
"zip_code": "string",
"city": "string",
"country": "string",
"state": "string"
},
"previous_provider": 0,
"previous_owner_vat_number": "string",
"previous_owner_name": "string",
"previous_owner_first_name": "string",
"icc": "string",
"icc_donor": "string",
"previous_contract_type": "string"
}
}
]
}
Development
Setup environment
- Install
pyenv
curl https://pyenv.run | bash
- Build the Python version
pyenv install 3.8.13
- Create a virtualenv
pyenv virtualenv 3.8.13 odoo-somconnexio-python-client
- Install dependencies
pyenv exec pip install -r requirements-dev.txt
- Install pre-commit hooks
pyenv exec pre-commit install
Test the HTTP request
We are using the HTTP recording plugin of Pytest: pytest-recording.
With VRC we can catch the HTTP responses and then, execute the tests using them.
To actually call the Odoo local client in order to create or rewrite cassettes using the next pyenv commands, we need to first change the conftest.py file and temporally provide the actual Odoo API-KEY.
monkeypatch.setenv("ODOO_APIKEY", "<ACTUAL_ODOO_APIKEY>")
⚠️ Do not commit this change!
To add a new test:
- Expose the needed envvars. Look for them at the Configuration Environment section
- Execute the tests using
pytestcommand: - If you are writing a new test that is making requests, you should run:
$ pytest --record-mode=once path/to/your/test
- You might need to record requests for an specific tests. In that case make sure to only run the tests affected and run
$ pytest --record-mode=rewrite path/to/your/test
- Add the new
cassetesto the commit and push them. - The CI uses the cassetes to emulate the HTTP response in the test.
Run test suite
$ tox
Formatting
We use pre-commit to execute Black as formatter.
Release process
Update CHANGELOG.md following this steps:
- Add any entries missing from merged merge requests.
- Duplicate the
[Unreleased]header. - Replace the second
Unreleasedwith a version number followed by the current date. Copy the exact format from previous releases.
Then, you can release and publish the package to PyPi:
- Update the
__version__var in__init__.pymatching the version you specified in the CHANGELOG. - Open a merge request with these changes for the team to approve
- Merge it, add a git tag on that merge commit and push it.
- Once the pipeline has successfully passed, go approve the
publishstep.
Metadata
Release files for odoo-somconnexio-python-client 0.2.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| odoo_somconnexio_python_client-0.2.3.tar.gz | 36.4 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| odoo_somconnexio_python_client-0.2.3-py2.py3-none-any.whl | Python 3, Python 2 | none | any | Details |
Total release size: 86.6 kB
Release files / odoo_somconnexio_python_client-0.2.3.tar.gz
| Download URL | odoo_somconnexio_python_client-0.2.3.tar.gz |
|---|---|
| Size | 36.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
2ac5356920219c1f21f3adb6094215dc17f6d5e5cd406ff7a7ecc6e21f3c8b66
|
|
BLAKE2b-256 checksum How to use checksums |
046acff3f2703d32e425b5ce6f4a38e8b891582ce58248037adcbab80ab6e6ca
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.8.20
|
Release files / odoo_somconnexio_python_client-0.2.3-py2.py3-none-any.whl
| Download URL | odoo_somconnexio_python_client-0.2.3-py2.py3-none-any.whl |
|---|---|
| Size | 50.1 kB |
| Tags | Python 2 Python 3 |
|
SHA-256 checksum How to use checksums |
e8a72ab06440791660fc53a0891c8694605a0f40d7ffa192248b46da1777a35f
|
|
BLAKE2b-256 checksum How to use checksums |
eb86f520b198a3d2028176a480bd5e9bfe2b5cffdc8731152f5e7555ec0cb692
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.8.20
|