Skip to content

Commit

Permalink
💚 pre-commit: auto cleanups
Browse files Browse the repository at this point in the history
  • Loading branch information
Ivan Yelizariev committed Feb 10, 2020
1 parent de40575 commit 70883cb
Show file tree
Hide file tree
Showing 242 changed files with 5,147 additions and 4,523 deletions.
2 changes: 1 addition & 1 deletion .DINAR/image/dependencies/pip.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
wechatpy[cryptography]
requests-mock
python-alipay-sdk
websocket-client
websocket-client
4 changes: 2 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
name: Telegram Notifications

on:
on:
issues:
types: [opened, reopened, deleted, closed]

jobs:
notify:

runs-on: ubuntu-latest

steps:
- name: Send notifications to Telegram
run: curl -s -X POST https://api.telegram.org/bot${{ secrets.TELEGRAM_TOKEN }}/sendMessage -d chat_id=${{ secrets.TELEGRAM_CHAT_ID }} -d text="${MESSAGE}" >> /dev/null
Expand Down
2 changes: 1 addition & 1 deletion .isort.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ line_length=88
known_odoo=odoo
known_odoo_addons=odoo.addons
sections=FUTURE,STDLIB,THIRDPARTY,ODOO,ODOO_ADDONS,FIRSTPARTY,LOCALFOLDER
known_third_party=
known_third_party=lxml,mock,psycopg2,pytz,requests,unittest2,xmlrpclib
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -162,4 +162,4 @@ General Public License ever published by the Free Software Foundation.
whether future versions of the GNU Lesser General Public License shall
apply, that proxy's public statement of acceptance of any version is
permanent authorization for you to choose that version for the
Library.
Library.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
Odoo POS addons
===============

Odoo POS addons
Odoo POS addons

List of repositories:
---------------------
Expand Down
1 change: 1 addition & 0 deletions hw_printer_network/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html).


def post_load():
from . import controllers
14 changes: 3 additions & 11 deletions hw_printer_network/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,28 +9,20 @@
"images": [],
"version": "12.0.2.0.1",
"application": False,

"author": "IT-Projects LLC, Dinar Gabbasov",
"support": "[email protected]",
"website": "https://apps.odoo.com/apps/modules/12.0/hw_printer_network/",
"license": "LGPL-3",
"price": 59.00,
"currency": "EUR",

"depends": [
"hw_escpos",
],
"depends": ["hw_escpos"],
"external_dependencies": {"python": [], "bin": []},
"data": [
],
"qweb": [
],
"data": [],
"qweb": [],
"demo": [],

"post_load": "post_load",
"pre_init_hook": None,
"post_init_hook": None,

"auto_install": False,
"installable": False,
}
91 changes: 54 additions & 37 deletions hw_printer_network/controllers/hw_printer_network_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
# Copyright 2018 Tom Blauwendraat <[email protected]>
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html).

from odoo import http
import logging
import time
import socket
import subprocess
import threading
import time
import traceback

from odoo import http

_logger = logging.getLogger(__name__)

Expand All @@ -30,7 +30,7 @@ def __init__(self, ip):
self.stdout = None
self.stderr = None
threading.Thread.__init__(self)
self.status = 'offline'
self.status = "offline"
self.ip = ip
self.stop = False

Expand All @@ -40,10 +40,10 @@ def run(self):
["ping", "-c1", "-w5", self.ip],
shell=False,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE
stderr=subprocess.PIPE,
)
child.communicate()
self.status = 'offline' if child.returncode else 'online'
self.status = "offline" if child.returncode else "online"
time.sleep(1)

def get_status(self):
Expand All @@ -54,7 +54,6 @@ def __del__(self):


class EscposNetworkDriver(EscposDriver):

def __init__(self):
self.network_printers = []
self.ping_processes = {}
Expand All @@ -64,11 +63,11 @@ def __init__(self):
def get_network_printer(self, ip, name=None):
found_printer = False
for printer in self.network_printers:
if printer['ip'] == ip:
if printer["ip"] == ip:
found_printer = True
if name:
printer['name'] = name
if printer['status'] == 'online':
printer["name"] = name
if printer["status"] == "online":
printer_object = self.printer_objects.get(ip, None)
if not printer_object:
try:
Expand All @@ -82,11 +81,7 @@ def get_network_printer(self, ip, name=None):
return None

def add_network_printer(self, ip, name=None):
printer = dict(
ip=ip,
status='offline',
name=name or 'Unnamed printer'
)
printer = dict(ip=ip, status="offline", name=name or "Unnamed printer")
self.network_printers.append(printer) # dont return because offline
self.start_pinging(ip)

Expand All @@ -96,58 +91,80 @@ def start_pinging(self, ip):
pinger.start()

def update_driver_status(self):
count = len([p for p in self.network_printers if p.get('status', None) == 'online'])
count = len(
[p for p in self.network_printers if p.get("status", None) == "online"]
)
if count:
self.set_status('connected', '{} printer(s) Connected'.format(count))
self.set_status("connected", "{} printer(s) Connected".format(count))
else:
self.set_status('disconnected', 'Disconnected')
self.set_status("disconnected", "Disconnected")

def run(self):
if not escpos:
_logger.error('ESC/POS cannot initialize, please verify system dependencies.')
_logger.error(
"ESC/POS cannot initialize, please verify system dependencies."
)
return
while True:
try:
error = True
timestamp, task, data = self.queue.get(True)
if task == 'xml_receipt':
if task == "xml_receipt":
error = False
if timestamp >= (time.time() - 1 * 60 * 60):
receipt, network_printer_ip = data
printer_info = self.get_network_printer(network_printer_ip)
printer = self.printer_objects.get(network_printer_ip, None)
if printer_info and printer_info['status'] == 'online' and printer:
_logger.info('Printing XML receipt on printer %s...', network_printer_ip)
if (
printer_info
and printer_info["status"] == "online"
and printer
):
_logger.info(
"Printing XML receipt on printer %s...",
network_printer_ip,
)
try:
printer.receipt(receipt)
except socket.error:
printer.open()
printer.receipt(receipt)
_logger.info('Done printing XML receipt on printer %s', network_printer_ip)
_logger.info(
"Done printing XML receipt on printer %s",
network_printer_ip,
)
else:
_logger.error('xml_receipt: printer offline!')
_logger.error("xml_receipt: printer offline!")
# add a missed order to queue
time.sleep(3)
self.queue.put((timestamp, task, data))
elif task == 'printstatus':
elif task == "printstatus":
pass
elif task == 'status':
elif task == "status":
error = False
for printer in self.network_printers:
ip = printer['ip']
ip = printer["ip"]
pinger = self.ping_processes.get(ip, None)
if pinger and pinger.isAlive():
status = pinger.get_status()
if status != printer['status']:
if status != printer["status"]:
# todo: use a lock?
printer['status'] = status
printer["status"] = status
self.update_driver_status()
else:
self.start_pinging(ip)
error = False
except Exception as e:
self.set_status('error', str(e))
errmsg = str(e) + '\n' + '-'*60+'\n' + traceback.format_exc() + '-'*60 + '\n'
self.set_status("error", str(e))
errmsg = (
str(e)
+ "\n"
+ "-" * 60
+ "\n"
+ traceback.format_exc()
+ "-" * 60
+ "\n"
)
_logger.error(errmsg)
finally:
if error:
Expand All @@ -158,25 +175,25 @@ def run(self):
# original driver runs in parallel and deals with USB printers
network_driver = EscposNetworkDriver()

hw_proxy.drivers['escpos_network'] = network_driver
hw_proxy.drivers["escpos_network"] = network_driver

# this will also start the message handling loop
network_driver.push_task('printstatus')
network_driver.push_task("printstatus")


class UpdatedEscposProxy(EscposProxy):
@http.route('/hw_proxy/print_xml_receipt', type='json', auth='none', cors='*')
@http.route("/hw_proxy/print_xml_receipt", type="json", auth="none", cors="*")
def print_xml_receipt(self, receipt, proxy=None):
if proxy:
network_driver.push_task('xml_receipt', (receipt, proxy))
network_driver.push_task("xml_receipt", (receipt, proxy))
else:
super(UpdatedEscposProxy, self).print_xml_receipt(receipt)

@http.route('/hw_proxy/network_printers', type='json', auth='none', cors='*')
@http.route("/hw_proxy/network_printers", type="json", auth="none", cors="*")
def network_printers(self, network_printers=None):
for printer in network_printers:
network_driver.get_network_printer(printer['ip'], name=printer['name'])
network_driver.get_network_printer(printer["ip"], name=printer["name"])

@http.route('/hw_proxy/status_network_printers', type='json', auth='none', cors='*')
@http.route("/hw_proxy/status_network_printers", type="json", auth="none", cors="*")
def network_printers_status(self):
return network_driver.network_printers
1 change: 0 additions & 1 deletion oca_dependencies.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
OCA_web https://github.com/it-projects-llc/web
misc-addons https://github.com/it-projects-llc/misc-addons
stock-logistics-barcode https://github.com/it-projects-llc/stock-logistics-barcode

32 changes: 8 additions & 24 deletions pos_cashbox/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,46 +5,30 @@
"summary": """The module allows to open Cashbox/Cashdrawer from Backend""",
"category": "Point of Sale",
# "live_test_url": "http://apps.it-projects.info/shop/product/pos-cashbox?version=10.0",
"images": ['images/pos_cashbox_main.png'],
"images": ["images/pos_cashbox_main.png"],
"version": "10.0.1.0.0",
"application": False,

"author": "IT-Projects LLC, Dinar Gabbasov",
"support": "[email protected]",
"website": "https://it-projects.info/team/GabbasovDinar",
"license": "LGPL-3",
"price": 25.00,
"currency": "EUR",

"depends": [
"point_of_sale",
],
"depends": ["point_of_sale"],
"external_dependencies": {"python": [], "bin": []},
"data": [
"views/pos_cashbox_template.xml",
"views/pos_cashbox_view.xml",
],
"qweb": [
],
"demo": [
],

"data": ["views/pos_cashbox_template.xml", "views/pos_cashbox_view.xml"],
"qweb": [],
"demo": [],
"post_load": None,
"pre_init_hook": None,
"post_init_hook": None,
"uninstall_hook": None,

"auto_install": False,
"installable": False,

"demo_title": "Open CashBox from Backend",
"demo_addons": [
],
"demo_addons_hidden": [
],
"demo_addons": [],
"demo_addons_hidden": [],
"demo_url": "pos-cashbox",
"demo_summary": "The module allows to open the CashBox from Backend",
"demo_images": [
"images/pos_cashbox_main.png",
]
"demo_images": ["images/pos_cashbox_main.png"],
}
2 changes: 1 addition & 1 deletion pos_cashbox/doc/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Usage
=====

* Go to ``Point of Sale >> Orders >> Sessions``

* Open POS session form
* Check that the session state is ``Opening Control`` or ``Closing Control``
* Click on ``Open CashBox``
Expand Down
8 changes: 4 additions & 4 deletions pos_cashbox/models/pos_cashbox_model.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
# Copyright 2018 Dinar Gabbasov <https://it-projects.info/team/GabbasovDinar>
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html).
from odoo import api, fields, models
from odoo import fields, models


class PosSession(models.Model):
_inherit = 'pos.session'
_inherit = "pos.session"

iface_cashdrawer = fields.Boolean(related='config_id.iface_cashdrawer')
proxy_ip = fields.Char(related='config_id.proxy_ip')
iface_cashdrawer = fields.Boolean(related="config_id.iface_cashdrawer")
proxy_ip = fields.Char(related="config_id.proxy_ip")

def open_backend_cashbox(self):
pass
Loading

0 comments on commit 70883cb

Please sign in to comment.