Minor fixes

This commit is contained in:
Oscar Alvarez 2021-01-11 00:45:36 -05:00
parent 85e25af73e
commit c9b0ebf887
4 changed files with 17 additions and 100 deletions

View file

@ -77,10 +77,10 @@ class Login(QDialog):
self.field_password.textChanged.connect(self.clear_message)
box_buttons = QDialogButtonBox()
pushButtonCancel = QPushButton("C&ANCELAR"))
pushButtonCancel = QPushButton("C&ANCELAR")
pushButtonCancel.setObjectName('button_cancel')
box_buttons.addButton(pushButtonCancel, QDialogButtonBox.RejectRole)
pushButtonOk = QPushButton("&CONNECTAR"))
pushButtonOk = QPushButton("&CONNECTAR")
pushButtonOk.setAutoDefault(True)
pushButtonOk.setDefault(False)
pushButtonOk.setObjectName('button_ok')
@ -96,8 +96,7 @@ class Login(QDialog):
hbox_line.addWidget(line)
hbox_msg = QHBoxLayout()
MSG = 'Error: usuario o contraseña invalida...!')
self.error_msg = QLabel(MSG)
self.error_msg = QLabel('Error: usuario o contraseña invalida...!')
self.error_msg.setObjectName('login_msg_error')
self.error_msg.setAlignment(Qt.AlignCenter)

View file

@ -243,7 +243,7 @@ class SearchDialog(QDialog):
self.headers = headers
self.values = values
if not title:
title = 'Search Products...')
title = 'Search Products...'
self.setWindowTitle(title)
self._product_line = QLineEdit()
@ -314,7 +314,7 @@ class HelpDialog(QuickDialog):
self.treeview.setEditTriggers(QAbstractItemView.NoEditTriggers)
super(HelpDialog, self).__init__(parent, 'help', widgets=[self.treeview],
size=(400, 500))
self.set_info('Keys Shortcuts...'))
self.set_info('Keys Shortcuts...')
self.hide()
def set_shortcuts(self, shortcuts):
@ -325,8 +325,8 @@ class HelpDialog(QuickDialog):
def _help_model(self, shortcuts):
model = QStandardItemModel(0, 2, self)
model.setHeaderData(0, Qt.Horizontal, 'Action'))
model.setHeaderData(1, Qt.Horizontal, 'Shortcut'))
model.setHeaderData(0, Qt.Horizontal, 'Accion')
model.setHeaderData(1, Qt.Horizontal, 'Atajo')
for short in shortcuts:
model.insertRow(0)

View file

@ -1,8 +1,7 @@
from PyQt5.QtCore import Qt, QAbstractTableModel, QModelIndex
__all__ = ['TableModel', 'TrytonModel']
__all__ = ['TableModel']
class TableModelEdit(QAbstractTableModel):
@ -22,10 +21,16 @@ class TableModelEdit(QAbstractTableModel):
def columnCount(self, index):
return len(self._data[0])
def get_data(self, index):
pass
def setData(self, index, value, role):
if role == Qt.EditRole:
if not value:
return False
self._data[index.row()][index.column()] = value
self._data[index.row()][index.column() + 1] = int(value) * int(self._data[index.row()][index.column()-1])
money = self._data[index.row()][index.column()-1]
self._data[index.row()][index.column() + 1] = int(value) * int(money)
self._parent.row_field_total_money.setText(str(self.get_sum(2)))
return True
@ -176,91 +181,3 @@ class TableModel(QAbstractTableModel):
if section == i:
return elements[i]
return None
class TrytonModel(object):
'Model interface for Tryton'
def __init__(self, connection, model, fields, methods=None):
self._fields = fields
self._methods = methods
self._proxy = connection.get_proxy(model)
self._context = connection.context
self._data = []
if self._methods:
self.setMethods()
def setFields(self, fields):
self._fields = fields
def setMethods(self):
for name in self._methods:
if not hasattr(self._proxy, name):
continue
setattr(self, name, getattr(self._proxy, name))
def find(self, domain, limit=None, order=None, context=None):
if context:
self._context.update(context)
return self._setDomain(domain, limit, order)
def _setDomain(self, domain, limit=None, order=None):
if domain and isinstance(domain[0], int):
operator = 'in'
operand = domain
if len(domain) == 1:
operator = '='
operand = domain[0]
domain = [('id', operator, operand)]
if not order:
order = [('id', 'ASC')]
self._data = self._search_read(domain,
fields_names=self._fields, limit=limit, order=order)
return self._data
def _search_read(self, domain, offset=0, limit=None, order=None,
fields_names=None):
if order:
ids = self._proxy.search(domain, offset, limit, order, self._context)
records = self._proxy.read(ids, fields_names, self._context)
rec_dict = {}
for rec in records:
rec_dict[rec['id']] = rec
res = []
for id_ in ids:
res.append(rec_dict[id_])
else:
res = self._proxy.search_read(domain, offset, limit, order,
fields_names, self._context)
return res
def read(self, ids, fields_names=None):
records = self._proxy.read(ids, fields_names, self._context)
return records
def _search(self, domain, offset=0, limit=None, order=None):
pass
def deleteRecords(self, ids):
self._proxy.delete(ids, self._context)
def getRecord(self, id_):
records = self.setDomain([('id', '=', id_)])
if records:
return records[0]
def update(self, id, pos=False):
rec, = self._search_read([('id', '=', id)],
fields_names=[x['name'] for x in self._fields])
return rec
def create(self, values):
records = self._proxy.create([values], self._context)
return records[0]
def write(self, ids, values):
self._proxy.write(ids, values, self._context)
def method(self, name):
# TODO Add reuse self context (*values, self._context)
return getattr(self._proxy, name)

View file

@ -38,7 +38,8 @@ class TableView(QTableView):
selected_idx = self.currentIndex()
if selected_idx:
data_row = self.model.get_data(selected_idx)
self.method_selected_row(data_row)
if data_row:
self.method_selected_row(data_row)
def rowsInserted(self, index, start, end):
# Adjust scroll to last row (bottom)