Skip to content

Commit

Permalink
[MIG] connector_cbl: Migration to 16.0
Browse files Browse the repository at this point in the history
  • Loading branch information
KNVx committed Jan 8, 2024
1 parent 2b0c78b commit 181f310
Show file tree
Hide file tree
Showing 15 changed files with 544 additions and 103 deletions.
57 changes: 46 additions & 11 deletions connector_cbl/README.rst
Original file line number Diff line number Diff line change
@@ -1,29 +1,64 @@
.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3

=============
CBL Connector
=============

* Connector to get tracking info from CBL
..
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:408776493168f36e425f42805d3208e71093361bc51c002563aab79dc7ae37b2
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
.. |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 smashing it by providing a detailed and welcomed feedback.
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]>
* 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.
4 changes: 0 additions & 4 deletions connector_cbl/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,2 @@
# Copyright NuoBiT Solutions, S.L. (<https://www.nuobit.com>)
# Eric Antones <[email protected]>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl)

from . import controllers
from . import models
8 changes: 3 additions & 5 deletions connector_cbl/__manifest__.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
# Copyright NuoBiT Solutions, S.L. (<https://www.nuobit.com>)
# Eric Antones <[email protected]>
# Copyright NuoBiT Solutions - Eric Antones <[email protected]>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl)

{
"name": "CBL Connector",
"description": "Connector to get tracking info from CBL",
"version": "11.0.0.1.2",
"author": "NuoBiT Solutions, S.L., Eric Antones",
"version": "16.0.1.0.2",
"author": "NuoBiT Solutions SL",
"license": "AGPL-3",
"category": "Connector",
"website": "https://github.com/nuobit/odoo-addons",
Expand Down
4 changes: 0 additions & 4 deletions connector_cbl/controllers/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1 @@
# Copyright NuoBiT Solutions, S.L. (<https://www.nuobit.com>)
# Eric Antones <[email protected]>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl)

from . import main
8 changes: 4 additions & 4 deletions connector_cbl/controllers/main.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
# 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 odoo.addons.connector_cbl.models.cbl import CBL
from ..models.cbl import CBL

_logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -45,9 +48,6 @@ def tracking_data(self, tracking_number=None):
return werkzeug.exceptions.NotFound(
"There's no data with tracking number '%s'" % tracking_number
)

# if not er.logout():
# return werkzeug.exceptions.InternalServerError("Logout not successful")
_logger.info(
"CBL shipment %s successfully retrieved from %s."
% (tracking_number, remote_ip)
Expand Down
4 changes: 0 additions & 4 deletions connector_cbl/models/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,2 @@
# Copyright NuoBiT Solutions, S.L. (<https://www.nuobit.com>)
# Eric Antones <[email protected]>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl)

from . import backend
from . import cbl
49 changes: 26 additions & 23 deletions connector_cbl/models/backend.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
# Copyright NuoBiT Solutions, S.L. (<https://www.nuobit.com>)
# Eric Antones <[email protected]>
# 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, exceptions, fields, models
from odoo import _, api, exceptions, fields, models

from . import cbl

Expand All @@ -25,37 +24,41 @@ def _select_state(self):
("production", "In Production"),
]

name = fields.Char("Name", required=True)
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",
)

sequence = fields.Integer("Sequence", required=True, default=1)

username = fields.Char("Username", required=True)
password = fields.Char("Password", required=True)

output = fields.Text("Output", readonly=True)

active = fields.Boolean(string="Active", default=True)
state = fields.Selection(selection="_select_state", string="State", default="draft")

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

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

if not er.login():
raise exceptions.ValidationError("Error on logging in")

# if not er.logout():
# raise exceptions.ValidationError("Error on logging out")

raise exceptions.ValidationError(_("Error on logging in"))
self.output = "OK"

@api.multi
def button_check_connection(self):
self._check_connection()
self.write({"state": "checked"})
42 changes: 27 additions & 15 deletions connector_cbl/models/cbl.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# Copyright NuoBiT Solutions, S.L. (<https://www.nuobit.com>)
# Eric Antones <[email protected]>
# Copyright NuoBiT Solutions - Eric Antones <[email protected]>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl)

import datetime
Expand All @@ -10,13 +9,29 @@
import requests
from lxml import etree

from odoo import _
from odoo.exceptions import ValidationError

_logger = logging.getLogger(__name__)


def xpath1(tree, xpath):
tag_l = tree.xpath(xpath)
if len(tag_l) == 0:
raise ValidationError(_("No elements found on xpath: %s" % xpath))
if len(tag_l) != 1:
raise Exception("Expected 1 element")
raise ValidationError(
_(
"Expected 1 element, %(elements)s found on "
"xpath: %(xpath)s"
"Elements:%(tags)s"
% {
"elements": len(tag_l),
"xpath": xpath,
"tags": tag_l,
}
)
)

return tag_l[0]

Expand All @@ -30,18 +45,17 @@ def __init__(self, username, password, debug=False):
self.username = username
self.password = password
self.headers = {
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.108 Safari/537.36",
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) "
"AppleWebKit/537.36 (KHTML, like Gecko) "
"Chrome/78.0.3904.108 Safari/537.36",
}
self.debug = debug

def login(self):
url = "%s/login.aspx" % self._base_url

## obtenim les dades del viewstate
res = self.session.get(url, headers=self.headers)
self._update_viewstate(res)

## fem el login
# login
form_data = {
"ScriptManager1": "UpdatePanel1|Login1$LoginButton",
"Login1$UserName": self.username,
Expand All @@ -51,13 +65,11 @@ def login(self):
form_data.update(self.viewstate)
res = self.session.post(url, data=form_data, headers=self.headers)
self._update_viewstate(res)

## comprovem que el login ha estat ok
# Check login
return not self.is_login_page(res)

def filter_by_refcte(self, refcte):
url = "%s/Consultas/envios.aspx" % self._base_url

res = self.session.get(url, headers=self.headers)
self._update_viewstate(res)

Expand Down Expand Up @@ -123,15 +135,15 @@ def filter_by_refcte(self, refcte):
input_detail_l = elem_table.xpath(
"//tr/td/input[contains(@onclick, 'MuestraDetalleConsulta')]"
)
for input in input_detail_l:
for input_d in input_detail_l:
m = re.match(
r"^.+MuestraDetalleConsulta\('([^']+)'\)", input.attrib["onclick"]
r"^.+MuestraDetalleConsulta\('([^']+)'\)", input_d.attrib["onclick"]
)
if not m:
raise Exception("Unexpected content on MuestraDetalleConsulta")
nexpedicion = m.group(1)

### detalle expedicion
# Expedition detail
url = "%s/api/Comun/DetalleEnvio/QueryDatosExpedicion" % self._base_url
form_data = {
"expedicion": nexpedicion,
Expand All @@ -141,7 +153,7 @@ def filter_by_refcte(self, refcte):
data = res.json()["data"]
expedition_d = data

### tracking
# tracking
url = "%s/api/Comun/DetalleEnvio/QueryTracking" % self._base_url
form_data = {
"jtStartIndex": "1",
Expand Down
5 changes: 5 additions & 0 deletions connector_cbl/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
* `NuoBiT <https://www.nuobit.com>`__:

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

1 change: 1 addition & 0 deletions connector_cbl/readme/DESCRIPTION.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Connector to get tracking info from CBL
Loading

0 comments on commit 181f310

Please sign in to comment.