parent
f792521158
commit
2796adc5ca
|
@ -4,22 +4,25 @@ import sys
|
|||
import os
|
||||
import gettext
|
||||
import logging
|
||||
import time
|
||||
from collections import OrderedDict
|
||||
from pathlib import Path
|
||||
from PySide6.QtWidgets import (QMainWindow, QDialog)
|
||||
from PySide6.QtCore import Qt
|
||||
from PySide6.QtCore import Qt, QTimer
|
||||
from PySide6.QtGui import QPixmap
|
||||
# from PyQt5.QtWidgets import (QDialogButtonBox, QPushButton,
|
||||
# QLineEdit, QHBoxLayout, QFrame, QLabel,
|
||||
# QVBoxLayout, QStyle,)
|
||||
# from PyQt5.QtGui import QPixmap, QFont
|
||||
# from PyQt5.QtCore import Qt
|
||||
|
||||
from app.commons import connection
|
||||
from app.commons import common
|
||||
from http.client import HTTPConnection, HTTPSConnection
|
||||
import orjson as json
|
||||
from app.threads import VerifyConn
|
||||
# from app.commons import connection
|
||||
# from app.commons import common
|
||||
from app.commons.config import Params
|
||||
from app.commons.dialogs import QuickDialog
|
||||
from app.commons.forms import GridForm
|
||||
from ..version import __version__
|
||||
# from app.commons.dialogs import QuickDialog
|
||||
# from app.commons.forms import GridForm
|
||||
# from ..version import __version__
|
||||
from app.commons.ui_login import Ui_Login
|
||||
# from app.css.flat_button_small import *
|
||||
|
||||
|
@ -29,8 +32,14 @@ __all__ = ['Login', 'xconnection']
|
|||
|
||||
pkg_dir = str(Path(os.path.dirname(__file__)).parents[0])
|
||||
path_logo = os.path.join(pkg_dir, 'share', 'login.png')
|
||||
path_circle_red = os.path.join(pkg_dir, 'share', 'circle_red.svg')
|
||||
path_circle_green = os.path.join(pkg_dir, 'share', 'circle_green.svg')
|
||||
file_base_css = os.path.join(pkg_dir, 'css', 'base.css')
|
||||
file_tablet_css = os.path.join(pkg_dir, 'css', 'tablet.css')
|
||||
HEADERS = {
|
||||
"Content-type": "application/json",
|
||||
"Accept": "text/plain"
|
||||
}
|
||||
|
||||
|
||||
class Login(QDialog):
|
||||
|
@ -38,8 +47,7 @@ class Login(QDialog):
|
|||
def __init__(self, parent=None, file_config=''):
|
||||
super(Login, self).__init__(parent)
|
||||
logging.info(' Start login Neox system X...')
|
||||
self.connection = None
|
||||
self.mode_conn = 'online'
|
||||
self.context = {}
|
||||
params = Params(file_config)
|
||||
self.params = params.params
|
||||
self.setObjectName('dialog_login')
|
||||
|
@ -56,7 +64,27 @@ class Login(QDialog):
|
|||
self.tablet_mode = None
|
||||
self.ui = Ui_Login()
|
||||
self.ui.setupUi(self)
|
||||
# self.init_UI()
|
||||
self.verify_conn_th = VerifyConn(self)
|
||||
self.verify_conn_th.sigVerifyConn.connect(self.verify_active)
|
||||
self.verify_conn_th.start()
|
||||
|
||||
def verify_active(self):
|
||||
conn = HTTPSConnection('google.com', timeout=5)
|
||||
try:
|
||||
conn.connect()
|
||||
conn._validate_host('google.com')
|
||||
conn.close()
|
||||
option = u"online"
|
||||
icon_conn = path_circle_green
|
||||
except:
|
||||
icon_conn = path_circle_red
|
||||
option = u"offline"
|
||||
self.ui.label_conn.setText(option)
|
||||
self.ui.label_icon_conn.setPixmap(QPixmap(icon_conn))
|
||||
self.timer = QTimer()
|
||||
self.timer.timeout.connect(self.verify_active)
|
||||
self.timer.start(10)
|
||||
self.verify_conn_th.exit(0)
|
||||
|
||||
def set_style(self, style_files):
|
||||
styles = []
|
||||
|
@ -187,16 +215,25 @@ class Login(QDialog):
|
|||
password = self.ui.field_password.text()
|
||||
server = self.params.get('server')
|
||||
database = self.ui.field_database.text()
|
||||
self.connection = xconnection(
|
||||
self.params['mode'], user, password, server, database
|
||||
result = xconnection(
|
||||
self.params['mode'], user, password, server, database, self.params['port']
|
||||
)
|
||||
if not self.connection:
|
||||
if result['status'] != 200 or result['user'] is None:
|
||||
self.ui.field_password.setText('')
|
||||
self.ui.field_password.setFocus()
|
||||
self.run()
|
||||
self.ui.label_error.setText('Error: usuario o contraseña invalida...!')
|
||||
msg = 'Error: usuario o contraseña invalida...!'
|
||||
if result['status'] == 429:
|
||||
msg = 'Error: Tiene muchos intentos de sesion, \npara desbloquear contacta con el area administrativa'
|
||||
elif result['status'] == 408:
|
||||
msg = 'Error: conexion del servidor'
|
||||
elif result['status'] == 500:
|
||||
msg = 'Error: interno del servidor \n' + result['message']
|
||||
print(msg, 'msg ,,,,', result['status'])
|
||||
self.ui.label_error.setText(msg)
|
||||
self.error_message()
|
||||
|
||||
else:
|
||||
self.context = result
|
||||
self.params['user'] = user
|
||||
self.params['password'] = password
|
||||
|
||||
|
@ -204,15 +241,54 @@ class Login(QDialog):
|
|||
self.ui.label_error.show()
|
||||
|
||||
|
||||
def xconnection(mode, user, password, host, database):
|
||||
def xconnection(mode, user, password, host, database, port):
|
||||
# Get user_id and session
|
||||
if mode == 'http':
|
||||
conn = HTTPConnection(host, port=port, timeout=10)
|
||||
else:
|
||||
conn = HTTPSConnection(host, port=port, timeout=10)
|
||||
print(conn._validate_host(host))
|
||||
print(conn._validate_method('POST'))
|
||||
url = '/' + database + '/login'
|
||||
payload = {
|
||||
'method': "common.db.login",
|
||||
'params': [
|
||||
user,
|
||||
{'device_cookie': None, 'password': password},
|
||||
"es",
|
||||
],
|
||||
'id': 0,
|
||||
'context': {},
|
||||
}
|
||||
try:
|
||||
url = '%s://%s:%s@%s:%s/%s/' % (
|
||||
mode, user, password, host, 8000, database)
|
||||
return connection.set_xmlrpc(url)
|
||||
conn.request('POST', url, body=json.dumps(payload), headers=HEADERS)
|
||||
response = conn.getresponse()
|
||||
except Exception as e:
|
||||
status = 408
|
||||
response = None
|
||||
print(e, 'error')
|
||||
|
||||
# url = '%s://%s:%s@%s:%s/%s/' % (
|
||||
# mode, user, password, host, 8000, database)
|
||||
try:
|
||||
res = json.loads(response.read())
|
||||
if not res.get('status'):
|
||||
res['status'] = response.status
|
||||
except:
|
||||
print('LOG: Data connection invalid!')
|
||||
return None
|
||||
status = status
|
||||
msg = ''
|
||||
if response:
|
||||
status = response.status
|
||||
msg = response.msg
|
||||
|
||||
res = {
|
||||
'status': status,
|
||||
'message': msg
|
||||
}
|
||||
|
||||
conn.close()
|
||||
return res
|
||||
# return connection.set_xmlrpc(url)
|
||||
|
||||
|
||||
# def safe_reconnect(main):
|
||||
|
|
|
@ -5,7 +5,7 @@ from PySide6.QtGui import (QBrush, QColor, QFont, QGradient, QIcon,
|
|||
QLinearGradient, QPalette, QPixmap)
|
||||
from PySide6.QtWidgets import (QGridLayout, QGroupBox, QLabel,
|
||||
QLayout, QPushButton, QLineEdit, QVBoxLayout, QWidget, QLineEdit,
|
||||
QDialogButtonBox, QSizePolicy)
|
||||
QDialogButtonBox, QSizePolicy, QHBoxLayout)
|
||||
|
||||
from ..version import __version__
|
||||
pkg_dir = str(Path(os.path.dirname(__file__)).parents[0])
|
||||
|
@ -170,7 +170,7 @@ class Ui_Login(object):
|
|||
self.gridLayout.addWidget(self.label_title, 0, 0, 2, 1)
|
||||
|
||||
self.vLayout_footer = QVBoxLayout()
|
||||
self.vLayout_footer.setSpacing(10)
|
||||
self.vLayout_footer.setSpacing(0)
|
||||
self.vLayout_footer.setObjectName(u"vLayout_footer")
|
||||
self.vLayout_footer.setContentsMargins(0, 0, 0, 0)
|
||||
self.label_page = QLabel(self.gridGroupBoxMain)
|
||||
|
@ -193,6 +193,21 @@ class Ui_Login(object):
|
|||
self.label_version.setAlignment(Qt.AlignCenter)
|
||||
|
||||
self.vLayout_footer.addWidget(self.label_version)
|
||||
self.hLayout_conn = QHBoxLayout()
|
||||
self.label_icon_conn = QLabel(self.gridGroupBoxMain)
|
||||
self.label_icon_conn.setAlignment(Qt.AlignRight)
|
||||
self.label_icon_conn.setObjectName(u"label_icon_conn")
|
||||
self.hLayout_conn.addWidget(self.label_icon_conn)
|
||||
|
||||
self.label_conn = QLabel(self.gridGroupBoxMain)
|
||||
self.label_conn.setObjectName(u"label_conn")
|
||||
self.label_conn.setFont(font4)
|
||||
self.label_conn.setStyleSheet(u"color: rgb(119, 118, 123);")
|
||||
self.label_conn.setAlignment(Qt.AlignLeft)
|
||||
self.hLayout_conn.addWidget(self.label_conn)
|
||||
|
||||
self.vLayout_footer.addLayout(self.hLayout_conn)
|
||||
|
||||
self.gridLayout.addLayout(self.vLayout_footer, 11, 0, 1, 1)
|
||||
self.gridLayout_2.addLayout(self.gridLayout, 1, 1, 1, 1)
|
||||
|
||||
|
|
|
@ -38,7 +38,7 @@ _DEFAULT_TIMEOUT = 60000 # on ms (100 minutes)
|
|||
|
||||
class FrontWindow(QMainWindow):
|
||||
|
||||
def __init__(self, connection, params, title=None, show_mode=None):
|
||||
def __init__(self, context, params, title=None, show_mode=None):
|
||||
super(FrontWindow, self).__init__()
|
||||
if not title:
|
||||
title = 'APLICACION'
|
||||
|
@ -47,9 +47,9 @@ class FrontWindow(QMainWindow):
|
|||
self._keyStates = {}
|
||||
self.window().setWindowTitle(title)
|
||||
self.setObjectName('WinMain')
|
||||
self.conn = connection
|
||||
# self.conn = connection
|
||||
self.version = __version__
|
||||
self._context = connection.context
|
||||
self._context = context
|
||||
self.set_params(params)
|
||||
self.logger = logging.getLogger('app_logger')
|
||||
|
||||
|
@ -109,23 +109,23 @@ class FrontWindow(QMainWindow):
|
|||
styles.append(infile.read())
|
||||
self.setStyleSheet(''.join(styles))
|
||||
|
||||
def set_timeout(self):
|
||||
if self.active_timeout != 'True':
|
||||
return
|
||||
# def set_timeout(self):
|
||||
# if self.active_timeout != 'True':
|
||||
# return
|
||||
|
||||
self.timeout = eval(self.timeout)
|
||||
if not self.timeout:
|
||||
self.timeout = _DEFAULT_TIMEOUT
|
||||
timer = QTimer(self)
|
||||
timer.timeout.connect(self.count_time)
|
||||
timer.start(1000)
|
||||
# self.timeout = eval(self.timeout)
|
||||
# if not self.timeout:
|
||||
# self.timeout = _DEFAULT_TIMEOUT
|
||||
# timer = QTimer(self)
|
||||
# timer.timeout.connect(self.count_time)
|
||||
# timer.start(1000)
|
||||
|
||||
def count_time(self):
|
||||
self.global_timer += 1
|
||||
if self.global_timer > self.timeout:
|
||||
self.global_timer = 0
|
||||
print('error esta linea no debia ejecutarse')
|
||||
# safe_reconnect()
|
||||
# def count_time(self):
|
||||
# self.global_timer += 1
|
||||
# if self.global_timer > self.timeout:
|
||||
# self.global_timer = 0
|
||||
# print('error esta linea no debia ejecutarse')
|
||||
# # safe_reconnect()
|
||||
|
||||
def close(self):
|
||||
dialog = self.dialog('confirm_exit', response=True)
|
||||
|
@ -151,14 +151,14 @@ class FrontWindow(QMainWindow):
|
|||
v = eval(v)
|
||||
setattr(self, k, v)
|
||||
|
||||
def action_block(self):
|
||||
safe_reconnect(self)
|
||||
# def action_block(self):
|
||||
# safe_reconnect(self)
|
||||
|
||||
def dialog_password_accept(self):
|
||||
self.connection()
|
||||
# def dialog_password_accept(self):
|
||||
# self.connection()
|
||||
|
||||
def dialog_password_rejected(self):
|
||||
self.connection()
|
||||
# def dialog_password_rejected(self):
|
||||
# self.connection()
|
||||
|
||||
def keyReleaseEvent(self, event):
|
||||
self._keyStates[event.key()] = False
|
||||
|
@ -285,7 +285,6 @@ class FrontWindow(QMainWindow):
|
|||
self.PartyConsumer = Model('party.consumer', self.ctx)
|
||||
if self._config['delivery_product.']:
|
||||
self._delivery_product = 0
|
||||
|
||||
self.User = Model('res.user', self.ctx)
|
||||
self._user, = self.User.find([('login', '=', self.user)])
|
||||
self.Company = Model('company.company', self.ctx)
|
||||
|
@ -348,7 +347,7 @@ class FrontWindow(QMainWindow):
|
|||
self._payment_terms = self.PaymentTerm.find([
|
||||
('active', '=', True)
|
||||
], order=[('name', 'ASC')])
|
||||
self.type_pos_user = self._context.get('type_pos_user')
|
||||
self.type_pos_user = self._user.get('type_pos_user')
|
||||
|
||||
if not self.type_pos_user:
|
||||
return 'user_without_permission'
|
||||
|
|
13
app/main.py
13
app/main.py
|
@ -50,20 +50,19 @@ _SALE_HISTORIC = [
|
|||
|
||||
class AppWindow(FrontWindow):
|
||||
|
||||
def __init__(self, connection, params, mode_conn):
|
||||
title = "PRESIK | SMART POS (○ " + mode_conn + ")"
|
||||
global CONNECTION
|
||||
CONNECTION = connection
|
||||
def __init__(self, context, params):
|
||||
title = "PRESIK | SMART POS"
|
||||
# global CONNECTION
|
||||
# CONNECTION = connection
|
||||
self.data_expenses = None
|
||||
self.mode_conn = mode_conn
|
||||
super(AppWindow, self).__init__(connection, params, title)
|
||||
super(AppWindow, self).__init__(context, params, title)
|
||||
self.payment_ctx = {}
|
||||
self.set_keys()
|
||||
time1 = time.time()
|
||||
StackMessages(self)
|
||||
self.stock_context = None
|
||||
self._sale = {}
|
||||
self.ctx = self._context
|
||||
self.ctx = context
|
||||
self.ctx['params'] = params
|
||||
response = self.load_modules()
|
||||
if response is not True:
|
||||
|
|
|
@ -15,7 +15,7 @@ MODELS = {
|
|||
},
|
||||
'res.user': {
|
||||
'rec_name': 'name',
|
||||
'fields': ['name', 'sale_device']
|
||||
'fields': ['name', 'sale_device', 'type_pos_user']
|
||||
},
|
||||
'product.category': {
|
||||
'rec_name': 'name',
|
||||
|
@ -80,7 +80,7 @@ MODELS = {
|
|||
'rec_name': 'name',
|
||||
'fields': [
|
||||
'id', 'name', 'party', 'party.invoice_address',
|
||||
'party.shipment_address'
|
||||
'party.shipment_address'
|
||||
]
|
||||
},
|
||||
'party.consumer': {
|
||||
|
|
|
@ -0,0 +1,3 @@
|
|||
<svg height="20" width="20" xmlns="http://www.w3.org/2000/svg">
|
||||
<circle cx="10" cy="10" r="5" stroke="green" stroke-width="3" fill="green" />
|
||||
</svg>
|
After Width: | Height: | Size: 150 B |
|
@ -0,0 +1,3 @@
|
|||
<svg height="20" width="20" xmlns="http://www.w3.org/2000/svg">
|
||||
<circle cx="10" cy="10" r="5" stroke="red" stroke-width="3" fill="red" />
|
||||
</svg>
|
After Width: | Height: | Size: 146 B |
|
@ -14,3 +14,16 @@ class DoInvoice(QThread):
|
|||
|
||||
def run(self):
|
||||
self.sigDoInvoice.emit()
|
||||
|
||||
|
||||
class VerifyConn(QThread):
|
||||
"""
|
||||
Verfify connection network using a thread
|
||||
"""
|
||||
sigVerifyConn = Signal()
|
||||
|
||||
def __init__(self, parent):
|
||||
QThread.__init__(self)
|
||||
|
||||
def run(self):
|
||||
self.sigVerifyConn.emit()
|
||||
|
|
|
@ -1,11 +1,8 @@
|
|||
[General]
|
||||
#Valid protocols: xml, json, local
|
||||
protocol=xml
|
||||
server=127.0.0.1
|
||||
api_url=localhost:5070
|
||||
port=8000
|
||||
# options http or https
|
||||
mode=http
|
||||
port=8000
|
||||
database=DEMO
|
||||
user=admin
|
||||
|
||||
|
|
17
pospro
17
pospro
|
@ -27,23 +27,24 @@ class Client(object):
|
|||
self.app = QApplication(sys.argv)
|
||||
|
||||
def init_login(self):
|
||||
_file_config = 'config_pos_v2.ini'
|
||||
_file_config = 'config_pos.ini'
|
||||
if args.o:
|
||||
_file_config = args.o
|
||||
login = Login(file_config=_file_config)
|
||||
while not login.connection:
|
||||
while not login.context:
|
||||
login.run()
|
||||
login.exec()
|
||||
return login.connection, login.params, login.mode_conn
|
||||
login.timer.stop()
|
||||
return login.context, login.params
|
||||
|
||||
def main(self, conn, params, mode_conn):
|
||||
_ = main.AppWindow(conn, params, mode_conn)
|
||||
def main(self, context, params):
|
||||
_ = main.AppWindow(context, params)
|
||||
self.app.exec()
|
||||
|
||||
|
||||
client = Client()
|
||||
conn, params, mode_conn = client.init_login()
|
||||
context, params = client.init_login()
|
||||
|
||||
if conn:
|
||||
client.main(conn, params, mode_conn)
|
||||
if context:
|
||||
client.main(context, params)
|
||||
sys.exit()
|
||||
|
|
Loading…
Reference in New Issue