Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[16.0][MIG] connector_cbl: Migration to 16.0 #355

Open
wants to merge 6 commits into
base: 16.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 64 additions & 0 deletions connector_cbl/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
=============
CBL Connector
=============

..
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:c101f320f89ead1e1b773b9e96d380efa593d9b7d202c1f23f23d8e97d0d7ac4
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
:target: https://odoo-community.org/page/development-status
:alt: Beta
.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-nuobit%2Fodoo--addons-lightgray.png?logo=github
:target: https://github.com/nuobit/odoo-addons/tree/16.0/connector_cbl
:alt: nuobit/odoo-addons

|badge1| |badge2| |badge3|

Connector to get tracking info from CBL

**Table of contents**

.. contents::
:local:

Bug Tracker
===========

Bugs are tracked on `GitHub Issues <https://github.com/nuobit/odoo-addons/issues>`_.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us to smash it by providing a detailed and welcomed
`feedback <https://github.com/nuobit/odoo-addons/issues/new?body=module:%20connector_cbl%0Aversion:%2016.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.

Do not contact contributors directly about support or help with technical issues.

Credits
=======

Authors
~~~~~~~

* NuoBiT Solutions SL

Contributors
~~~~~~~~~~~~

* `NuoBiT <https://www.nuobit.com>`__:

* Eric Antones <[email protected]>
* Kilian Niubo <[email protected]>


Maintainers
~~~~~~~~~~~

This module is part of the `nuobit/odoo-addons <https://github.com/nuobit/odoo-addons/tree/16.0/connector_cbl>`_ project on GitHub.

You are welcome to contribute.
2 changes: 2 additions & 0 deletions connector_cbl/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from . import controllers
from . import models
27 changes: 27 additions & 0 deletions connector_cbl/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Copyright NuoBiT Solutions - Eric Antones <[email protected]>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl)

{
"name": "CBL Connector",
"version": "16.0.1.0.0",
"author": "NuoBiT Solutions SL",
"license": "AGPL-3",
"category": "Connector",
"website": "https://github.com/nuobit/odoo-addons",
"external_dependencies": {
"python": [
"requests",
"lxml",
],
},
"depends": [
"connector",
],
"data": [
"views/backend_views.xml",
"views/menus.xml",
"templates/cbl_template.xml",
"security/ir.model.access.csv",
],
"installable": True,
}
1 change: 1 addition & 0 deletions connector_cbl/controllers/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import main
56 changes: 56 additions & 0 deletions connector_cbl/controllers/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# Copyright NuoBiT Solutions - Eric Antones <[email protected]>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl)

import logging

import werkzeug.exceptions

from odoo import http

from ..models.cbl import CBL

_logger = logging.getLogger(__name__)


class CBLController(http.Controller):
@http.route(
[
"/tracking/cbl/<string:tracking_number>",
],
type="http",
auth="public",
)
def tracking_data(self, tracking_number=None):
remote_ip = http.request.httprequest.environ["REMOTE_ADDR"]

Check warning on line 24 in connector_cbl/controllers/main.py

View check run for this annotation

Codecov / codecov/patch

connector_cbl/controllers/main.py#L24

Added line #L24 was not covered by tests
cbl_backend = (
http.request.env["cbl.backend"]
.sudo()
.search(
[
("active", "=", True),
("state", "=", "checked"),
]
)
.sorted(lambda x: x.sequence)
)

if not cbl_backend:
return werkzeug.exceptions.InternalServerError("No configuration found")

Check warning on line 38 in connector_cbl/controllers/main.py

View check run for this annotation

Codecov / codecov/patch

connector_cbl/controllers/main.py#L38

Added line #L38 was not covered by tests

er = CBL(username=cbl_backend.username, password=cbl_backend.password)

Check warning on line 40 in connector_cbl/controllers/main.py

View check run for this annotation

Codecov / codecov/patch

connector_cbl/controllers/main.py#L40

Added line #L40 was not covered by tests

_logger.info("Asking %s CBL shipment... from %s" % (tracking_number, remote_ip))

Check warning on line 42 in connector_cbl/controllers/main.py

View check run for this annotation

Codecov / codecov/patch

connector_cbl/controllers/main.py#L42

Added line #L42 was not covered by tests
if not er.login():
return werkzeug.exceptions.Unauthorized()

Check warning on line 44 in connector_cbl/controllers/main.py

View check run for this annotation

Codecov / codecov/patch

connector_cbl/controllers/main.py#L44

Added line #L44 was not covered by tests

data = er.filter_by_refcte(tracking_number)

Check warning on line 46 in connector_cbl/controllers/main.py

View check run for this annotation

Codecov / codecov/patch

connector_cbl/controllers/main.py#L46

Added line #L46 was not covered by tests
if not data:
return werkzeug.exceptions.NotFound(

Check warning on line 48 in connector_cbl/controllers/main.py

View check run for this annotation

Codecov / codecov/patch

connector_cbl/controllers/main.py#L48

Added line #L48 was not covered by tests
"There's no data with tracking number '%s'" % tracking_number
)
_logger.info(

Check warning on line 51 in connector_cbl/controllers/main.py

View check run for this annotation

Codecov / codecov/patch

connector_cbl/controllers/main.py#L51

Added line #L51 was not covered by tests
"CBL shipment %s successfully retrieved from %s."
% (tracking_number, remote_ip)
)

return http.request.render("connector_cbl.index", {"expeditions": data})

Check warning on line 56 in connector_cbl/controllers/main.py

View check run for this annotation

Codecov / codecov/patch

connector_cbl/controllers/main.py#L56

Added line #L56 was not covered by tests
2 changes: 2 additions & 0 deletions connector_cbl/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from . import backend
from . import cbl
65 changes: 65 additions & 0 deletions connector_cbl/models/backend.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# Copyright NuoBiT Solutions - Eric Antones <[email protected]>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl)

import logging

from odoo import _, api, fields, models
from odoo.exceptions import ValidationError

from . import cbl

_logger = logging.getLogger(__name__)


class CBLBackend(models.Model):
_name = "cbl.backend"
_inherit = "connector.backend"

_description = "CBL Backend Configuration"

@api.model
def _select_state(self):
return [

Check warning on line 22 in connector_cbl/models/backend.py

View check run for this annotation

Codecov / codecov/patch

connector_cbl/models/backend.py#L22

Added line #L22 was not covered by tests
("draft", "Draft"),
("checked", "Checked"),
("production", "In Production"),
]

name = fields.Char(
required=True,
)
sequence = fields.Integer(
required=True,
default=1,
)
username = fields.Char(
required=True,
)
password = fields.Char(
required=True,
)
output = fields.Text(
readonly=True,
)
active = fields.Boolean(
default=True,
)
state = fields.Selection(
selection="_select_state",
default="draft",
)

def button_reset_to_draft(self):
self.ensure_one()
self.write({"state": "draft", "output": None})

Check warning on line 54 in connector_cbl/models/backend.py

View check run for this annotation

Codecov / codecov/patch

connector_cbl/models/backend.py#L53-L54

Added lines #L53 - L54 were not covered by tests

def _check_connection(self):
self.ensure_one()
er = cbl.CBL(username=self.username, password=self.password)

Check warning on line 58 in connector_cbl/models/backend.py

View check run for this annotation

Codecov / codecov/patch

connector_cbl/models/backend.py#L57-L58

Added lines #L57 - L58 were not covered by tests
if not er.login():
raise ValidationError(_("Error on logging in"))
self.output = "OK"

Check warning on line 61 in connector_cbl/models/backend.py

View check run for this annotation

Codecov / codecov/patch

connector_cbl/models/backend.py#L60-L61

Added lines #L60 - L61 were not covered by tests

def button_check_connection(self):
self._check_connection()
self.write({"state": "checked"})

Check warning on line 65 in connector_cbl/models/backend.py

View check run for this annotation

Codecov / codecov/patch

connector_cbl/models/backend.py#L64-L65

Added lines #L64 - L65 were not covered by tests
Loading
Loading