From f27c4d0de5d4f5fc9c62cd5a54913211543ddbc8 Mon Sep 17 00:00:00 2001 From: Guewen Baconnier Date: Mon, 16 Dec 2019 14:22:45 +0100 Subject: [PATCH] [IMP] stock_vertical_lift: black, isort --- stock_vertical_lift_kardex/README.rst | 84 ++++ stock_vertical_lift_kardex/__manifest__.py | 25 +- stock_vertical_lift_kardex/models/__init__.py | 1 - .../models/stock_location.py | 41 +- .../models/vertical_lift_shuttle.py | 55 ++- .../proxy/kardex-proxy.py | 21 +- stock_vertical_lift_kardex/proxy/test.py | 64 +-- .../static/description/index.html | 433 ++++++++++++++++++ 8 files changed, 620 insertions(+), 104 deletions(-) create mode 100644 stock_vertical_lift_kardex/README.rst create mode 100644 stock_vertical_lift_kardex/static/description/index.html diff --git a/stock_vertical_lift_kardex/README.rst b/stock_vertical_lift_kardex/README.rst new file mode 100644 index 000000000..8d4a3f730 --- /dev/null +++ b/stock_vertical_lift_kardex/README.rst @@ -0,0 +1,84 @@ +====================== +Vertical Lift - Kardex +====================== + +.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |badge1| image:: https://img.shields.io/badge/maturity-Alpha-red.png + :target: https://odoo-community.org/page/development-status + :alt: Alpha +.. |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-OCA%2Fstock--logistics--warehouse-lightgray.png?logo=github + :target: https://github.com/OCA/stock-logistics-warehouse/tree/13.0/stock_vertical_lift_kardex + :alt: OCA/stock-logistics-warehouse +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/stock-logistics-warehouse-13-0/stock-logistics-warehouse-13-0-stock_vertical_lift_kardex + :alt: Translate me on Weblate +.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png + :target: https://runbot.odoo-community.org/runbot/153/13.0 + :alt: Try me on Runbot + +|badge1| |badge2| |badge3| |badge4| |badge5| + +Add support for Kardex Remstar vertical lifts to the Vertical Lift +module. + +.. IMPORTANT:: + This is an alpha version, the data model and design can change at any time without warning. + Only for development or testing purpose, do not use in production. + `More details on development status `_ + +**Table of contents** + +.. contents:: + :local: + +Known issues / Roadmap +====================== + +* Add support of the hardware + +Bug Tracker +=========== + +Bugs are tracked on `GitHub 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 `_. + +Do not contact contributors directly about support or help with technical issues. + +Credits +======= + +Authors +~~~~~~~ + +* Camptocamp + +Contributors +~~~~~~~~~~~~ + +* Guewen Baconnier + +Maintainers +~~~~~~~~~~~ + +This module is maintained by the OCA. + +.. image:: https://odoo-community.org/logo.png + :alt: Odoo Community Association + :target: https://odoo-community.org + +OCA, or the Odoo Community Association, is a nonprofit organization whose +mission is to support the collaborative development of Odoo features and +promote its widespread use. + +This module is part of the `OCA/stock-logistics-warehouse `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/stock_vertical_lift_kardex/__manifest__.py b/stock_vertical_lift_kardex/__manifest__.py index 8ccd05222..e973ec0b5 100644 --- a/stock_vertical_lift_kardex/__manifest__.py +++ b/stock_vertical_lift_kardex/__manifest__.py @@ -1,18 +1,15 @@ # Copyright 2019 Camptocamp SA # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). { - 'name': 'Vertical Lift - Kardex', - 'summary': 'Integrate with Kardex Remstar Vertical Lifts', - 'version': '12.0.1.0.0', - 'category': 'Stock', - 'author': 'Camptocamp, Odoo Community Association (OCA)', - 'license': 'AGPL-3', - 'depends': [ - 'stock_vertical_lift', - ], - 'website': 'https://www.camptocamp.com', - 'data': [ - ], - 'installable': True, - 'development_status': 'Alpha', + "name": "Vertical Lift - Kardex", + "summary": "Integrate with Kardex Remstar Vertical Lifts", + "version": "12.0.1.0.0", + "category": "Stock", + "author": "Camptocamp, Odoo Community Association (OCA)", + "license": "AGPL-3", + "depends": ["stock_vertical_lift"], + "website": "https://www.camptocamp.com", + "data": [], + "installable": True, + "development_status": "Alpha", } diff --git a/stock_vertical_lift_kardex/models/__init__.py b/stock_vertical_lift_kardex/models/__init__.py index 5a191bac8..51a3830f6 100644 --- a/stock_vertical_lift_kardex/models/__init__.py +++ b/stock_vertical_lift_kardex/models/__init__.py @@ -1,3 +1,2 @@ from . import stock_location from . import vertical_lift_shuttle - diff --git a/stock_vertical_lift_kardex/models/stock_location.py b/stock_vertical_lift_kardex/models/stock_location.py index 39d66fc28..8b3cd73c2 100644 --- a/stock_vertical_lift_kardex/models/stock_location.py +++ b/stock_vertical_lift_kardex/models/stock_location.py @@ -2,17 +2,20 @@ # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). import logging + from odoo import models _logger = logging.getLogger(__name__) class StockLocation(models.Model): - _inherit = 'stock.location' + _inherit = "stock.location" def _hardware_kardex_prepare_payload(self, cell_location=None): - message_template = ("{code}|{hostId}|{addr}|{carrier}|{carrierNext}|" - "{x}|{y}|{boxType}|{Q}|{order}|{part}|{desc}|\r\n") + message_template = ( + "{code}|{hostId}|{addr}|{carrier}|{carrierNext}|" + "{x}|{y}|{boxType}|{Q}|{order}|{part}|{desc}|\r\n" + ) shuttle = self.vertical_lift_shuttle_id if shuttle.mode == "pick": code = "1" @@ -25,23 +28,23 @@ class StockLocation(models.Model): if cell_location: x, y = cell_location.tray_cell_center_position() else: - x, y = '', '' + x, y = "", "" subst = { - 'code': code, - 'hostId': self.env['ir.sequence'].next_by_code('vertical.lift.command'), - 'addr': shuttle.name, - 'carrier': self.level, - 'carrierNext': '0', - 'x': x, - 'y': y, - 'boxType': '', - 'Q': '', - 'order': '', - 'part': '', - 'desc': '', + "code": code, + "hostId": self.env["ir.sequence"].next_by_code("vertical.lift.command"), + "addr": shuttle.name, + "carrier": self.level, + "carrierNext": "0", + "x": x, + "y": y, + "boxType": "", + "Q": "", + "order": "", + "part": "", + "desc": "", } payload = message_template.format(**subst) - return payload.encode('iso-8859-1', 'replace') + return payload.encode("iso-8859-1", "replace") def _hardware_vertical_lift_tray_payload(self, cell_location=None): """Prepare the message to be sent to the vertical lift hardware @@ -84,5 +87,7 @@ class StockLocation(models.Model): _logger.debug("Sending to kardex: {}", payload) # TODO implement the communication with kardex else: - payload = super()._hardware_vertical_lift_tray_payload(cell_location=cell_location) + payload = super()._hardware_vertical_lift_tray_payload( + cell_location=cell_location + ) return payload diff --git a/stock_vertical_lift_kardex/models/vertical_lift_shuttle.py b/stock_vertical_lift_kardex/models/vertical_lift_shuttle.py index 256439d35..54e046dfd 100644 --- a/stock_vertical_lift_kardex/models/vertical_lift_shuttle.py +++ b/stock_vertical_lift_kardex/models/vertical_lift_shuttle.py @@ -3,61 +3,58 @@ from odoo import api, models - JMIF_STATUS = { - 0: 'success', - 101: 'common error', - 102: 'sequence number invalid', - 103: 'machine busy', - 104: 'timeout', - 105: 'max retry reached', - 106: 'carrier in use or undefined', - 107: 'cancelled', - 108: 'invalid user input data', - 201: 'request accepted and queued', - 202: 'request processing started / request active', - 203: 'carrier arrived, maybe overwritten by code 0', - 301: 'AO occupied with other try on move back (store / put)', - 302: 'AO occupied with other try on fetch (pick)', + 0: "success", + 101: "common error", + 102: "sequence number invalid", + 103: "machine busy", + 104: "timeout", + 105: "max retry reached", + 106: "carrier in use or undefined", + 107: "cancelled", + 108: "invalid user input data", + 201: "request accepted and queued", + 202: "request processing started / request active", + 203: "carrier arrived, maybe overwritten by code 0", + 301: "AO occupied with other try on move back (store / put)", + 302: "AO occupied with other try on fetch (pick)", } class VerticalLiftShuttle(models.Model): - _inherit = 'vertical.lift.shuttle' + _inherit = "vertical.lift.shuttle" @api.model def _selection_hardware(self): values = super()._selection_hardware() - values += [('kardex', 'Kardex')] + values += [("kardex", "Kardex")] return values def _check_server_response(self, command): response = command.answer - code, sep, remaining = response.partition('|') + code, sep, remaining = response.partition("|") code = int(code) if code == 0: return True elif 1 <= code <= 99: - command.error = 'interface error %d' % code + command.error = "interface error %d" % code return False elif code in JMIF_STATUS and code < 200: - command.error = '%d: %s' % (code, JMIF_STATUS[code]) + command.error = "%d: %s" % (code, JMIF_STATUS[code]) return False elif code in JMIF_STATUS and code < 300: - command.error = '%d: %s' % (code, JMIF_STATUS[code]) + command.error = "%d: %s" % (code, JMIF_STATUS[code]) return True elif code in JMIF_STATUS: - command.error = '%d: %s' % (code, JMIF_STATUS[code]) + command.error = "%d: %s" % (code, JMIF_STATUS[code]) elif 501 <= code <= 999: - command.error = '%d: %s' % (code, 'MM260 Error') + command.error = "%d: %s" % (code, "MM260 Error") elif 1000 <= code <= 32767: - command.error = '%d: %s' % ( - code, 'C2000TCP/C3000CGI machine error' - ) + command.error = "%d: %s" % (code, "C2000TCP/C3000CGI machine error") elif 0xFF0 <= code == 0xFFF: - command.error = '%x: %s' % ( - code, 'C3000CGI machine error (global short)' + command.error = "{:x}: {}".format( + code, "C3000CGI machine error (global short)" ) elif 0xFFF < code: - command.error = '%x: %s' % (code, 'C3000CGI machine error (long)') + command.error = "{:x}: {}".format(code, "C3000CGI machine error (long)") return False diff --git a/stock_vertical_lift_kardex/proxy/kardex-proxy.py b/stock_vertical_lift_kardex/proxy/kardex-proxy.py index f568c5a91..97607999d 100644 --- a/stock_vertical_lift_kardex/proxy/kardex-proxy.py +++ b/stock_vertical_lift_kardex/proxy/kardex-proxy.py @@ -87,11 +87,11 @@ class KardexClientProtocol(asyncio.Protocol): if b"\r\n" in self.buffer: msg, sep, rem = self.buffer.partition(b"\r\n") self.buffer = rem - msg = msg.decode('iso-8859-1', 'replace').strip() - if msg.startswith('0|ping'): - _logger.info('ping ok') + msg = msg.decode("iso-8859-1", "replace").strip() + if msg.startswith("0|ping"): + _logger.info("ping ok") else: - _logger.info('notify odoo: %s', msg) + _logger.info("notify odoo: %s", msg) self.loop.create_task(self.notify_odoo(msg)) def connection_lost(self, exc): @@ -100,12 +100,10 @@ class KardexClientProtocol(asyncio.Protocol): async def notify_odoo(self, msg): url = self.args.odoo_url + "/vertical-lift" async with aiohttp.ClientSession() as session: - params = {'answer': msg, 'secret': self.args.secret} + params = {"answer": msg, "secret": self.args.secret} async with session.post(url, data=params) as resp: resp_text = await resp.text() - _logger.info( - 'Reponse from Odoo: %s %s', resp.status, resp_text - ) + _logger.info("Reponse from Odoo: %s %s", resp.status, resp_text) def main(args, ssl_context=None): @@ -116,9 +114,7 @@ def main(args, ssl_context=None): queue = asyncio.Queue(loop=loop) # create the main server coro = loop.create_server( - lambda: KardexProxyProtocol(loop, queue, args), - host=args.host, - port=args.port + lambda: KardexProxyProtocol(loop, queue, args), host=args.host, port=args.port ) loop.run_until_complete(coro) @@ -160,7 +156,7 @@ def make_parser(): ("--port", listen_port, int), ("--odoo-url", odoo_url, str), ("--odoo-db", odoo_db, str), - ("--secret", secret, str), + ("--secret", secret, str), ("--kardex-host", kardex_host, str), ("--kardex-port", kardex_port, str), ("--kardex-use-tls", kardex_use_tls, bool), @@ -169,6 +165,7 @@ def make_parser(): parser.add_argument(name, default=default, action="store", type=type_) return parser + if __name__ == "__main__": parser = make_parser() args = parser.parse_args() diff --git a/stock_vertical_lift_kardex/proxy/test.py b/stock_vertical_lift_kardex/proxy/test.py index 5b6ad5188..a7899f21a 100644 --- a/stock_vertical_lift_kardex/proxy/test.py +++ b/stock_vertical_lift_kardex/proxy/test.py @@ -1,69 +1,74 @@ -import socket +# pylint: disable=W8116 import asyncio import logging +import socket import time -_logger = logging.getLogger('kardex.proxy') +_logger = logging.getLogger("kardex.proxy") logging.basicConfig(level=logging.DEBUG) class KardexProxyProtocol(asyncio.Protocol): def __init__(self, loop, queue): - _logger.info('Proxy created') + _logger.info("Proxy created") self.transport = None - self.buffer = b'' + self.buffer = b"" self.queue = queue self.loop = loop def connection_made(self, transport): - _logger.info('Proxy incoming cnx') + _logger.info("Proxy incoming cnx") self.transport = transport - self.buffer = b'' + self.buffer = b"" def data_received(self, data): self.buffer += data - _logger.info('Proxy: received %s', data) + _logger.info("Proxy: received %s", data) if len(self.buffer) > 65535: # prevent buffer overflow self.transport.close() def eof_received(self): - _logger.info('Proxy: received EOF') - if self.buffer[-1] != b'\n': + _logger.info("Proxy: received EOF") + if self.buffer[-1] != b"\n": # bad format -> close self.transport.close() - data = self.buffer.replace(b'\r\n', b'\n').replace(b'\n', b'\r\n').decode('iso-8859-1', 'replace') + data = ( + self.buffer.replace(b"\r\n", b"\n") + .replace(b"\n", b"\r\n") + .decode("iso-8859-1", "replace") + ) task = self.loop.create_task(self.queue.put(data)) - self.buffer = b'' - print('toto', task) + self.buffer = b"" + print("toto", task) def connection_lost(self, exc): self.transport = None - self.buffer = b'' + self.buffer = b"" class KardexClientProtocol(asyncio.Protocol): def __init__(self, loop, queue): - _logger.info('started kardex client') + _logger.info("started kardex client") self.loop = loop self.queue = queue self.transport = None - self.buffer = b'' + self.buffer = b"" def connection_made(self, transport): self.transport = transport - _logger.info('connected to kardex server %r', transport) + _logger.info("connected to kardex server %r", transport) async def keepalive(self): while True: t = int(time.time()) - msg = '61|ping%d|SH1-1|0|0||||||||\r\n' % t + msg = "61|ping%d|SH1-1|0|0||||||||\r\n" % t await self.send_message(msg) await asyncio.sleep(5) async def send_message(self, message): - _logger.info('SEND %s', message) - message = message.encode('iso-8859-1').ljust(1024, b'\0') + _logger.info("SEND %s", message) + message = message.encode("iso-8859-1").ljust(1024, b"\0") self.transport.write(message) async def process_queue(self): @@ -72,31 +77,30 @@ class KardexClientProtocol(asyncio.Protocol): await self.send_message(message) def data_received(self, data): - data = data.replace(b'\0', b'') - _logger.info('RECV %s', data) + data = data.replace(b"\0", b"") + _logger.info("RECV %s", data) self.buffer += data def connection_lost(self, exc): self.loop.stop() -if __name__ == '__main__': - _logger.info('starting') +if __name__ == "__main__": + _logger.info("starting") loop = asyncio.get_event_loop() loop.set_debug(1) queue = asyncio.Queue(loop=loop) coro = loop.create_server( - lambda: KardexProxyProtocol(loop, queue), - port=3000, - family=socket.AF_INET + lambda: KardexProxyProtocol(loop, queue), port=3000, family=socket.AF_INET ) server = loop.run_until_complete(coro) - coro = loop.create_connection(lambda: KardexClientProtocol(loop, queue), - 'localhost', 9600) + coro = loop.create_connection( + lambda: KardexClientProtocol(loop, queue), "localhost", 9600 + ) transport, client = loop.run_until_complete(coro) - print('%r' % transport) + print("%r" % transport) loop.create_task(client.keepalive()) loop.create_task(client.process_queue()) - _logger.info('run loop') + _logger.info("run loop") loop.run_forever() loop.close() diff --git a/stock_vertical_lift_kardex/static/description/index.html b/stock_vertical_lift_kardex/static/description/index.html new file mode 100644 index 000000000..ae2800eba --- /dev/null +++ b/stock_vertical_lift_kardex/static/description/index.html @@ -0,0 +1,433 @@ + + + + + + +Vertical Lift - Kardex + + + +
+

Vertical Lift - Kardex

+ + +

Alpha License: AGPL-3 OCA/stock-logistics-warehouse Translate me on Weblate Try me on Runbot

+

Add support for Kardex Remstar vertical lifts to the Vertical Lift +module.

+
+

Important

+

This is an alpha version, the data model and design can change at any time without warning. +Only for development or testing purpose, do not use in production. +More details on development status

+
+

Table of contents

+ +
+

Known issues / Roadmap

+
    +
  • Add support of the hardware
  • +
+
+
+

Bug Tracker

+

Bugs are tracked on GitHub 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.

+

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

+
+
+

Credits

+
+

Authors

+
    +
  • Camptocamp
  • +
+
+
+

Contributors

+ +
+
+

Maintainers

+

This module is maintained by the OCA.

+Odoo Community Association +

OCA, or the Odoo Community Association, is a nonprofit organization whose +mission is to support the collaborative development of Odoo features and +promote its widespread use.

+

This module is part of the OCA/stock-logistics-warehouse project on GitHub.

+

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

+
+
+
+ +