From e4cbbd89958e3c26e869de360cc06cab92c370bc Mon Sep 17 00:00:00 2001 From: Wilson Gomez Date: Wed, 25 Oct 2023 10:29:13 -0500 Subject: [PATCH] add option for test printers --- app/buttonpad.py | 5 +- app/commons/dialogs.py | 2 +- app/commons/search_window.py | 2 +- app/constants.py | 14 ++++ app/dialogs.py | 147 ++++++++++++++++++++++++++++++---- app/frontwindow.py | 5 +- app/main.py | 149 +++++++++++++---------------------- app/reporting.py | 68 ++++++++-------- app/share/test_print.svg | 7 ++ app/stack_messages.py | 3 +- tests/__init__.py | 0 11 files changed, 253 insertions(+), 149 deletions(-) create mode 100644 app/share/test_print.svg create mode 100644 tests/__init__.py diff --git a/app/buttonpad.py b/app/buttonpad.py index 5fd5363..b207bb0 100644 --- a/app/buttonpad.py +++ b/app/buttonpad.py @@ -35,7 +35,7 @@ class StartButtons(QVBoxLayout): grid.rowStretch(1) grid.parent = parent columns = 4 - rows = 3 + rows = 4 values = [] values_extend = values.extend @@ -75,7 +75,8 @@ class StartButtons(QVBoxLayout): values_extend([ ['button_help', 'AYUDA', 'action_help', 'help'], - ['button_product_info', 'INFO. PRODUCTO', 'action_info_product', 'product_info'] + ['button_product_info', 'INFO. PRODUCTO', 'action_info_product', 'product_info'], + ['button_test_print', 'TEST IMPRESION', 'action_test_print', 'test_print'] ]) positions = [(i, j) for i in range(rows) for j in range(columns)] diff --git a/app/commons/dialogs.py b/app/commons/dialogs.py index fb1ce7a..eb00d6b 100644 --- a/app/commons/dialogs.py +++ b/app/commons/dialogs.py @@ -132,7 +132,7 @@ class QuickDialog(QDialog): if kind in ('info', 'error'): self.show() - def exec_(self, args=None): + def exec(self, args=None): res = None res = super(QuickDialog, self).exec() if hasattr(self, 'data_widget') and isinstance(self.data_widget, GridForm): diff --git a/app/commons/search_window.py b/app/commons/search_window.py index 129b94e..b31cf4c 100644 --- a/app/commons/search_window.py +++ b/app/commons/search_window.py @@ -218,7 +218,7 @@ class SearchWindow(QDialog): def execute(self): self.current_row = None self.filter_field.setFocus() - return self.exec_() + return self.exec() def show(self): self.clear_filter() diff --git a/app/constants.py b/app/constants.py index 9c0aa6c..520a1ae 100644 --- a/app/constants.py +++ b/app/constants.py @@ -97,3 +97,17 @@ TYPE_VEHICLE = [ ('bicycle', 'Bicycle'), ('car', 'Car'), ] + +TYPE_PRINTER = [ + ('', ''), + ('usb', 'USB'), + ('network', 'RED'), +] + +ROW_CHARACTERS = [ + ('', ''), + ('28', '28'), + ('33', '33'), + ('42', '42'), + ('48', '48'), +] \ No newline at end of file diff --git a/app/dialogs.py b/app/dialogs.py index 2502af2..47bc44b 100644 --- a/app/dialogs.py +++ b/app/dialogs.py @@ -15,7 +15,8 @@ from PySide6.QtWidgets import ( from .proxy import Report from .buttonpad import ButtonsFunction -from .constants import alignCenter, alignLeft, FRACTIONS, TYPE_VEHICLE, MONEY +from .constants import (alignCenter, alignLeft, FRACTIONS, TYPE_VEHICLE, + MONEY, TYPE_PRINTER, ROW_CHARACTERS) from .commons.forms import FieldMoney, ComboBox, GridForm from .commons.search_window import SearchWindow from collections import OrderedDict @@ -25,6 +26,7 @@ from app.commons.table import TableView from app.commons.model import TableEdit from .commons.custom_button import CustomButton from .tools import get_icon, get_screen +from .reporting import Receipt __all__ = [ 'ControlPanel', 'SearchSale', 'SearchParty', 'SearchProduct', 'Position', @@ -37,7 +39,7 @@ __all__ = [ 'DialogCancelInvoice', 'DialogForceAssign', 'CombineProduct', 'DialogReports', 'DialogFixedDiscounts', 'DialogFixedDiscountsManual', 'DialogExpenses', 'DialogInfoProduct', 'DialogAdvance', - 'DialogDeleteProduct', 'DialogCollection' + 'DialogDeleteProduct', 'DialogCollection', 'DialogTestPrinter' ] WIZARDS = { @@ -965,7 +967,7 @@ class DialogMoneyCount(QuickDialog): def exec(self, kind): self.kind = kind - self.exec_() + self.exec() def set_total(self, row): _row = self.model._data[row] @@ -1550,7 +1552,7 @@ class DialogComboProduct(QuickDialog): if qty_req: if not qty_add or int(qty_req) - int(qty_add) > 0: dialog = self.parent.dialog('qty_combo_min_req', extra_message=f"cantidad minima {qty_req} has agregado {qty_add}") - dialog.exec_() + dialog.exec() return False return True @@ -1582,12 +1584,12 @@ class DialogSplitSale(QuickDialog): msg = 'DESEA CREAR UN PEDIDO CON LOS PRODUCTOS SELECCIONADOS?' self.label.setText(msg) self.label_number.setText('') - return self.exec_() + return self.exec() def info(self, number): self.label.setText('PEDIDO CREADO EXITOSAMENTE!') self.label_number.setText(number) - self.exec_() + self.exec() class Help(HelpDialog): @@ -1629,6 +1631,128 @@ class DialogListProduct(QuickDialog): grid.addWidget(self.input_code, 1, 2) +class DialogTestPrinter(QuickDialog): + + def __init__(self, parent): + self._parent = parent + width, height = get_screen() + grid = QGridLayout() + if parent.environment == 'restaurant': + _sizes = (100, 210, 210, 100) + fields = ( + {'name': 'id', 'label': 'ID', 'type': 'integer', 'invisible': True}, + {'name': 'name', 'label': 'NOMBRE', 'type': 'char', 'readonly': True}, + {'name': 'interface', 'label': 'INTERFACE', 'type': 'char', 'readonly': True}, + {'name': 'server', 'label': 'SERVIDOR', 'type': 'char', 'readonly': True}, + {'name': 'row_characters', 'label': 'CARACTERES POR FILA', 'type': 'integer', 'readonly': True}, + ) + self.model = TableEdit(self, [], fields) + self.table = TableView('model_printers', self.model, _sizes, self.fill_fields) + self.table.hideColumn(0) + + grid.addWidget(self.table, 0, 0, 2, 7) + + label_interface = QLabel('INTERFACE:') + label_interface.setObjectName('label_interface') + grid.addWidget(label_interface, 3, 1) + self.combo_interface = ComboBox(parent, 'type_printer', {'values': TYPE_PRINTER}) + grid.addWidget(self.combo_interface, 3, 2) + + label_server = QLabel('SERVIDOR:') + label_server.setObjectName('label_server') + grid.addWidget(label_server, 3, 3) + self.input_server = QLineEdit() + self.input_server.setObjectName('input_server') + grid.addWidget(self.input_server, 3, 4) + + label_row_characters = QLabel('CARACTERES POR FILA:') + label_row_characters.setObjectName('label_row_characters') + grid.addWidget(label_row_characters, 3, 5) + self.combo_row_characters = ComboBox( + parent, 'row_characters', {'values': ROW_CHARACTERS} + ) + grid.addWidget(self.combo_row_characters, 3, 6) + + super(DialogTestPrinter, self).__init__( + parent, 'action', widgets=[grid] + ) + self.setWindowTitle('TEST IMPRESORA') + self.setFixedSize(int(width * 0.4), int(height * 0.3)) + + def load(self): + printers_shop = self.parent.printers_shop + if getattr(self, 'table', None) and printers_shop: + model_add = self.model.add_record + for k, v in printers_shop.items(): + data = [ + k, + v.get('name', ''), + v['interface'], + v['host'], + v['row_characters'], + ] + model_add(data) + + def exec(self): + self.clear() + self.load() + super(DialogTestPrinter, self).exec() + + def clear(self): + self.model.clearData() + self.input_server.setText("") + self.combo_interface.set_from_id("") + self.combo_row_characters.set_from_id("") + + def test_printer(self): + print('configure test') + server = self.input_server.text() + interface = self.combo_interface.get_id() + row_characters = self.combo_row_characters.get_id() + + printer_test = { + 'interface': interface, + 'device': str(server), + 'profile': 'TM-P80', + 'row_characters': row_characters, + } + + ctx_printing = {} + ctx_printing['company'] = 'OSCORP INC' + ctx_printing['sale_device'] = 'CAJA-10' + ctx_printing['shop'] = 'Shop Wall Boulevard' + ctx_printing['street'] = 'Cll 21 # 172-81. Central Park' + ctx_printing['user'] = 'Charles Chapplin' + ctx_printing['city'] = 'Dallas' + ctx_printing['zip'] = '0876' + ctx_printing['phone'] = '591 5513 455' + ctx_printing['id_number'] = '123456789-0' + ctx_printing['tax_regime'] = 'none' + receipt = Receipt(ctx_printing) + receipt.config_printer(printer_test) + return receipt.test_printer() + + def dialog_accepted(self): + result = self.test_printer() + if result: + msg = 'Impresion Exitosa ✔' + else: + msg = '''\n\n Test de impresión ha fallado, + es posible que haya un problema con la conexión de energía, USB o red. + Para solucionar el problema, asegúrese de que la impresora esté conectada + correctamente a la fuente de alimentación y que el cable USB o Ethernet + esté conectado correctamente a la impresora y + al dispositivo desde el que está intentando imprimir.''' + self._parent.dialog('test_printer', extra_message=msg) + if result: + super(DialogTestPrinter, self).dialog_accepted() + + def fill_fields(self, data): + self.input_server.setText(data[3]) + self.combo_interface.set_from_id(data[2]) + self.combo_row_characters.set_from_id(str(data[4])) + + class DialogInfoProduct(QuickDialog): def __init__(self, parent): self._parent = parent @@ -1710,16 +1834,7 @@ class DialogInfoProduct(QuickDialog): ]) if self.parent._onebarcode_activated: domain.append(('barcode', 'ilike', '%' + filter + '%')) - # if self._parent.cache_local: - # clause = [ - # 'OR', - # ('barcode', 'ilike', '%{:}%'.format(filter)), - # ('code', 'ilike', '%{:}%'.format(filter)), - # ('code', 'ilike', '%{:}%'.format(filter)), - # ] - # domain = [clause] - # products = self._parent.local_db.find_product_elastic(domain, limit=100) - # else: + products = self._parent.Product.find(domain, ctx=self._parent.stock_context, fields=['name', 'code', 'description', 'id', 'list_price', diff --git a/app/frontwindow.py b/app/frontwindow.py index 23dc640..dc4bd7a 100644 --- a/app/frontwindow.py +++ b/app/frontwindow.py @@ -20,7 +20,7 @@ from .dialogs import ( DialogDeliveryParty, TipAmount, DeliveryAmount, DialogSalesmanCode, DialogFixedDiscounts, DialogFixedDiscountsManual, DialogComboProduct, DialogSplitSale, DialogExpenses, DialogInfoProduct, DialogAdvance, - DialogDeleteProduct, DialogCollection + DialogDeleteProduct, DialogCollection, DialogTestPrinter, ) from .constants import DIALOG_REPLY_YES from .version import __version__ @@ -105,7 +105,7 @@ class FrontWindow(QMainWindow): def closeEvent(self, event): dialog = self.dialog('confirm_exit', response=True) - response = dialog.exec_() + response = dialog.exec() if response == DIALOG_REPLY_YES: # self.check_empty_sale() This function cancels sale if it has not number logout(self.ctx) @@ -167,6 +167,7 @@ class FrontWindow(QMainWindow): self.dialog_split_sale = DialogSplitSale(self) self.dialog_expenses = DialogExpenses(self) self.dialog_info_product = DialogInfoProduct(self) + self.dialog_test_printer = DialogTestPrinter(self) if self._commission_activated: self.dialog_agent = DialogAgent(self) if self.environment == 'restaurant' and self._sale_pos_restaurant: diff --git a/app/main.py b/app/main.py index 3944609..99069ff 100644 --- a/app/main.py +++ b/app/main.py @@ -72,7 +72,7 @@ class AppWindow(FrontWindow): response = self.load_modules() if response is not True: d = self.dialog(response) - d.exec_() + d.exec() super(AppWindow, self).close() return self.setup_sale_line() @@ -134,7 +134,6 @@ class AppWindow(FrontWindow): orders = [] tasks = [] version = compare_versions(self.modules['sale_pos_frontend_rest']['version'], '6.0.7') - print('pasa por esta new query') if version in ('equal', 'higher'): if self.tasks_station: result = self.SaleLine.get_data_command_and_task(args) @@ -150,10 +149,7 @@ class AppWindow(FrontWindow): for record in records: orders += record['orders'].values() tasks += record['tasks'].values() - # print('ingresa a impresion orders') - # pprint(orders) - # print('ingresa a impresion tasks') - # pprint(tasks) + try: result = self.receipt_order.print_orders(orders) if result: @@ -165,7 +161,6 @@ class AppWindow(FrontWindow): receipt = Receipt(context={}, environment='restaurant') result_print = receipt.print_tasks(tasks) if any(result_print): - print(result_print, 'validate print') self.SaleLine.mark_tasks_printed({'task_ids': result_print}) except Exception: traceback.print_exc() @@ -173,41 +168,6 @@ class AppWindow(FrontWindow): # timer.singleShot(30000, self.verify_print_order_automatic) # self.verify_command_order_th.exit(0) - # def set_domains(self): - # self.domain_search_product = [ - # ('code', '!=', None), - # ('active', '=', True), - # ('template.salable', '=', True), - # ('template.account_category', '!=', None), - # ] - - # if self.shop['product_categories.']: - # self.domain_search_product.append( - # ('account_category', 'in', self.shop['product_categories.']) - # ) - - # def set_cache_company(self): - # self.local_db = LocalDB() - # self.local_db.create_table_config() - # self._local_config = self.local_db.get_config() - # if not self._local_config: - # company_id = self.company - # self._local_config = self.local_db.set_config([company_id]) - - # def set_cache_products(self): - # self.local_db.create_table_product() - # local_products = self.local_db.get_local_products() - - # config = self.local_db.get_config() - # _sync_date = config[1] - # products = self.Product.sync_get_products({ - # 'write_date': _sync_date, - # 'shop_id': self.ctx['shop'] - # }) - # self.local_db.update_products(products, local_products) - # now = datetime.now() - # self.local_db.set_config_sync(str(now)) - def set_printers_usb(self, PATH_PRINTERS): for usb_dev in os.listdir(PATH_PRINTERS): # # fix me return for set printer default usb @@ -303,7 +263,7 @@ class AppWindow(FrontWindow): msg = 'Agente: ' + result.get('agent.').get('rec_name') + \ "\n Comision: " + str(result['commission']) + "%" dialog = self.dialog('confirm_agent', response=True, widgets=[], extra_message=msg) - response = dialog.exec_() + response = dialog.exec() if response == DIALOG_REPLY_NO: self.Sale.write([sale_id], {'state': 'draft'}) return @@ -891,8 +851,8 @@ class AppWindow(FrontWindow): if hasattr(self, 'field_list_price') and self._config.get('use_price_list'): ctx = {'price_list': self.field_list_price.get_id()} rec = self.SaleLine.faster_set_quantity(args, ctx=ctx) - except Exception as e: - print(e) + except Exception: + logger.exception('Error al procesar cantidad de linea producto') return self.message_bar.set('quantity_not_valid') self.message_bar.set('system_ready') @@ -1119,7 +1079,7 @@ class AppWindow(FrontWindow): sales = self.Sale.find(dom, fields=_SALE_HISTORIC, limit=10) for record in sales: self.model_sale_historic.add_record(record) - self.dialog_historic_sales.exec_() + self.dialog_historic_sales.exec() def check_all_commanded(self): return all([ @@ -1214,11 +1174,11 @@ class AppWindow(FrontWindow): def action_tables(self): if self.environment == 'restaurant': self.dialog_manage_tables.open_tables() - self.dialog_manage_tables.exec_() + self.dialog_manage_tables.exec() def action_release_table(self, table_id): dialog = self.dialog('release_table', response=True) - response = dialog.exec_() + response = dialog.exec() if response == DIALOG_REPLY_NO: return to_drop = {'state': 'available', 'sale': None} @@ -1248,7 +1208,7 @@ class AppWindow(FrontWindow): value = int((self._config['tip_rate'] / 100) * total_amount) self.field_tip_amount_ask.setText(str(value)) - result = self.dialog_tip_amount.exec_() + result = self.dialog_tip_amount.exec() if result == 0: self.field_tip_amount_invoice.setChecked(False) return @@ -1268,7 +1228,7 @@ class AppWindow(FrontWindow): def action_delivery(self): if self._state in ['finished']: return - result = self.dialog_delivery_amount.exec_() + result = self.dialog_delivery_amount.exec() if result == 0: self.field_delivery_amount_invoice.setChecked(False) return @@ -1288,7 +1248,7 @@ class AppWindow(FrontWindow): def action_salesman_code(self): if self._state in ['checkout']: return - result = self.dialog_salesman_code.exec_() + result = self.dialog_salesman_code.exec() code = self.field_salesman_code_ask.text() if result == 0: # Cancelled the action @@ -1302,17 +1262,17 @@ class AppWindow(FrontWindow): return salesman_list[0] def action_delivery_party(self): - self.dialog_delivery_party.exec_() + self.dialog_delivery_party.exec() def action_delivery_party_panel(self): self.dialog_control_panel.close() - self.dialog_table_delivery_party.exec_() + self.dialog_table_delivery_party.exec() def action_control_panel(self): - self.dialog_control_panel.exec_() + self.dialog_control_panel.exec() def action_reports(self): - self.dialog_reports.exec_() + self.dialog_reports.exec() def dialog_money_count_accepted(self): return True @@ -1426,16 +1386,16 @@ class AppWindow(FrontWindow): self.set_amounts() def action_table_discount(self): - self.dialog_auth_discount.exec_() + self.dialog_auth_discount.exec() def action_tax(self): - self.dialog_tax.exec_() + self.dialog_tax.exec() def button_payment_pressed(self): if self._state not in ('checkout', 'payment'): self.dialog('add_payment_sale_draft') return - self.dialog_payment.exec_() + self.dialog_payment.exec() def _check_credit_capacity(self, party): if party['credit_limit_amount']: @@ -1526,12 +1486,12 @@ class AppWindow(FrontWindow): self.load_sale(sale_id) if sale.get('state') == 'quotation': - self.dialog_payment.exec_() + self.dialog_payment.exec() flag = True # dialog_advance.addAction while flag: self.dialog_advance.clean() - res = self.dialog_advance.exec_() + res = self.dialog_advance.exec() amount = self.field_amount_ask.text() reservation = self.field_reservation_ask.isChecked() if res == 0 or (res == 1 and amount.isdigit()): @@ -1540,7 +1500,7 @@ class AppWindow(FrontWindow): journal = self.journal voucher_number = None if journal.get('require_voucher'): - res = self.dialog_voucher.exec_() + res = self.dialog_voucher.exec() if res == 0: self.dialog_voucher.close() return @@ -1580,7 +1540,7 @@ class AppWindow(FrontWindow): if number: self.field_invoice_number_ask.setText(number) self.field_type_ask.set_from_id(type_doc) - res = self.dialog_print_invoice.exec_() + res = self.dialog_print_invoice.exec() if res == DIALOG_REPLY_NO: return number = self.field_invoice_number_ask.text() @@ -1664,18 +1624,18 @@ class AppWindow(FrontWindow): report.open(result) def action_comment(self): - self.dialog_comment.exec_() + self.dialog_comment.exec() comment = self.field_comment.toPlainText() self.store.update({'comment': comment}) def action_position(self): self.field_position_ask.setText(self.store.get('position')) - self.dialog_position.exec_() + self.dialog_position.exec() position = self.field_position_ask.text() self.store.update({'position': position}) def action_agent(self): - self.dialog_agent.exec_() + self.dialog_agent.exec() res = self.field_commission_ask.text() commission = float(res or 0) self.field_agent_id = self.field_agent_ask.get_id() @@ -1709,7 +1669,7 @@ class AppWindow(FrontWindow): 'cashier', 'frontend_admin'): self.dialog('user_without_permission') return - self.dialog_global_discount.exec_() + self.dialog_global_discount.exec() discount = self.field_global_discount_ask.text() if discount and discount.isdigit(): rec = { @@ -1834,7 +1794,7 @@ class AppWindow(FrontWindow): if self.model_sale_lines.rowCount() == 0 or not sale_id: return - res = self.dialog_order.exec_() + res = self.dialog_order.exec() if res == DIALOG_REPLY_NO: return False result = None @@ -1903,7 +1863,6 @@ class AppWindow(FrontWindow): if not reversion and ln['order_sended'] in (True, '✔'): continue pd_id = ln['product.']['id'] - print(pd_id, 'njnj') try: printers, cat_id = self.products_printers.get(str(pd_id)) cat_id = str(cat_id[0]) @@ -1973,26 +1932,23 @@ class AppWindow(FrontWindow): data_station = self.Sale.method_instance('get_data_for_stations', self.sale_id) receipt = Receipt(context={}, environment='restaurant') receipt.print_tasks(data_station.values()) - print(orders, 'validate') - return - # result = self.receipt_order.print_orders(orders.values(), reversion) - # lines_sended = result + lines_ids - # print(lines_sended, 'this is lines printed') - # if not reversion and lines_sended: - # for line in lines: - # if line['id'] in lines_sended: - # line['order_sended'] = '✔' - # self.model_sale_lines.update_record(line) - # self.Sale.mark_commanded({'lines_ids': lines_sended}) - # return result + result = self.receipt_order.print_orders(orders.values(), reversion) + lines_sended = result + lines_ids + if not reversion and lines_sended: + for line in lines: + if line['id'] in lines_sended: + line['order_sended'] = '✔' + self.model_sale_lines.update_record(line) + self.Sale.mark_commanded({'lines_ids': lines_sended}) + return result def action_source(self): if self._state != 'checkout' and self.sources: - self.dialog_source.exec_() + self.dialog_source.exec() def action_payment_term(self): if self._state == 'payment' or self.type_pos_user == 'salesman': - self.dialog_payment_term.exec_() + self.dialog_payment_term.exec() def action_new_sale(self): if self._state in ['checkout']: @@ -2011,7 +1967,7 @@ class AppWindow(FrontWindow): def _ask_new_sale(self): dialog = self.dialog('new_sale', response=True) - res = dialog.exec_() + res = dialog.exec() if res == DIALOG_REPLY_NO: return False return True @@ -2021,7 +1977,7 @@ class AppWindow(FrontWindow): if self._state == 'disabled': return if self.type_pos_user == 'cashier': - self.dialog_cancel_invoice.exec_() + self.dialog_cancel_invoice.exec() password = self.field_password_for_cancel_ask.text() if password != self._password_admin: return self.dialog('not_permission_for_cancel') @@ -2034,7 +1990,7 @@ class AppWindow(FrontWindow): sale.get('invoice_number'): return self.dialog('not_permission_delete_sale') dialog = self.dialog('cancel_sale', response=True) - response = dialog.exec_() + response = dialog.exec() if response == DIALOG_REPLY_NO: return self.Sale.cancel_sale({'id': sale['id']}) @@ -2078,7 +2034,7 @@ class AppWindow(FrontWindow): self._sale_historic = sales for record in sales: self.model_sale_historic.add_record(record) - self.dialog_historic_sales.exec_() + self.dialog_historic_sales.exec() def action_search_sale(self): if hasattr(self, 'activate_scale_sync') and self.activate_scale_sync: @@ -2516,7 +2472,7 @@ class AppWindow(FrontWindow): if self._state == 'payment': dialog = self.dialog('cant_add_discount') - dialog.exec_() + dialog.exec() return if discount: self.validate_discount(discount, _line) @@ -2879,7 +2835,7 @@ class AppWindow(FrontWindow): salesman = self.store.get('salesman') if self.salesman_required and not salesman: dialog = self.dialog('missing_salesman') - dialog.exec_() + dialog.exec() return False return True @@ -2939,7 +2895,7 @@ class AppWindow(FrontWindow): if self._password_force_assign: if (request_qty and qty_ < request_qty) or (qty_ <= 0): self.message_bar.set('without_stock_quantity', product['name']) - self.dialog_force_assign.exec_() + self.dialog_force_assign.exec() password = self.field_password_force_assign_ask.text() self.field_password_force_assign_ask.setText('') if password != self._password_force_assign: @@ -3217,7 +3173,7 @@ class AppWindow(FrontWindow): 'cashier', 'frontend_admin'): self.dialog('user_without_permission') return - self.dialog_fixed_discount.exec_() + self.dialog_fixed_discount.exec() if self.environment == 'restaurant': self.dialog_combine_product.close() @@ -3227,7 +3183,7 @@ class AppWindow(FrontWindow): self.dialog('user_without_permission') return self.field_bono_discount_manual.setText('') - self.dialog_fixed_discount_manual.exec_() + self.dialog_fixed_discount_manual.exec() if self.environment == 'restaurant': self.dialog_combine_product.close() discount = self.field_bono_discount_manual.text() @@ -3264,7 +3220,7 @@ class AppWindow(FrontWindow): if qty_min_req: self.dialog_combo_product.label_qty_min_req.setText(str(qty_min_req)) self.dialog_combo_product.set_buttons(products_mix) - self.dialog_combo_product.exec_() + self.dialog_combo_product.exec() self.dialog_combo_product.close() def action_combine_line(self): @@ -3282,7 +3238,7 @@ class AppWindow(FrontWindow): ('categories', 'in', categories), ], fields=['id', 'name', 'code', 'categories', 'rec_name', 'list_price']) self.dialog_combine_product.set_buttons(mixables) - self.dialog_combine_product.exec_() + self.dialog_combine_product.exec() self.dialog_combine_product.filter_field.clear() self.dialog_combine_product.close() @@ -3308,7 +3264,7 @@ class AppWindow(FrontWindow): return self.dialog('user_without_permission') if order_sended: - res = self.dialog_delete_product.exec_() + res = self.dialog_delete_product.exec() if res == 0: self.dialog_delete_product.close() return @@ -3383,7 +3339,7 @@ class AppWindow(FrontWindow): journal = self.journal if journal.get('require_voucher'): - res = self.dialog_voucher.exec_() + res = self.dialog_voucher.exec() if res == 0: self.dialog_voucher.close() return @@ -3753,3 +3709,6 @@ class AppWindow(FrontWindow): self.change_view_to('order_front') self.load_sale(sale) self.dialog_manage_tables.hide() + + def action_test_print(self): + self.dialog_test_printer.exec() diff --git a/app/reporting.py b/app/reporting.py index 5fcaa7c..ec5bd37 100755 --- a/app/reporting.py +++ b/app/reporting.py @@ -133,38 +133,44 @@ class Receipt(object): return self._printer def test_printer(self): - if self._interface == 'usb': - if OS_NAME == 'posix': - self._printer = printer.File( - self._device, profile=self._profile) - elif OS_NAME == 'nt': - self._printer = printer.Win32Raw(self._device) - self._printer.open() - elif self._interface == 'network': - try: - host, port = self._device.split(":") - except Exception: - host, port = self._device, None - if port: - self._printer = printer.Network(host, port=int(port), timeout=15) - else: - self._printer = printer.Network(host, timeout=15) - elif self._interface == 'ssh': - self._printer = FileSSH(*self._device.split('@')) - self._printer.open() - if not self._printer: - return - self.print_enter() try: - self._printer.image(image_test_file, center=True) - except Exception as e: - print(e, 'error') - self.print_enter() - self.print_header() - self._printer.ln(3) - self._printer.cut() - self._printer.cashdraw(2) - self._printer.close() + if self._interface == 'usb': + if OS_NAME == 'posix': + self._printer = printer.File( + self._device, profile=self._profile) + elif OS_NAME == 'nt': + self._printer = printer.Win32Raw(self._device) + self._printer.open() + elif self._interface == 'network': + try: + host, port = self._device.split(":") + except Exception: + host, port = self._device, None + if port: + self._printer = printer.Network(host, port=int(port), timeout=15) + else: + self._printer = printer.Network(host, timeout=15) + elif self._interface == 'ssh': + self._printer = FileSSH(*self._device.split('@')) + self._printer.open() + if not self._printer: + return + self.print_enter() + try: + self._printer.image(image_test_file, center=True) + except Exception as e: + print(e, 'error') + self.print_enter() + self.print_header() + self._printer.ln(3) + self._printer.cut() + self._printer.cashdraw(2) + self._printer.close() + result = True + except Exception: + logging.exception(f'Error test impresion; interface: {self._interface} device: {self._device}') + result = False + return result # self._printer.beep() def config_printer(self, printer): diff --git a/app/share/test_print.svg b/app/share/test_print.svg new file mode 100644 index 0000000..0e1289a --- /dev/null +++ b/app/share/test_print.svg @@ -0,0 +1,7 @@ + + + + + Svg Vector Icons : http://www.onlinewebfonts.com/icon + + \ No newline at end of file diff --git a/app/stack_messages.py b/app/stack_messages.py index 66a9a79..ec9fd32 100644 --- a/app/stack_messages.py +++ b/app/stack_messages.py @@ -69,5 +69,6 @@ class StackMessages(QWidget): 'confirm_agent': ('question', 'Confirmar comision de agente'), 'qty_combo_min_req': ('error', 'Cantidad minima requerida!'), 'error_server': ('error', 'Error'), - 'print_error': ('error', 'Error de Impresión') + 'print_error': ('error', 'Error de Impresión'), + 'test_printer': ('error', 'Resultado Test: ') } diff --git a/tests/__init__.py b/tests/__init__.py new file mode 100644 index 0000000..e69de29