presik_pos/app/dialogs.py

1713 lines
62 KiB
Python
Raw Normal View History

2021-03-14 16:37:35 +01:00
from decimal import Decimal
2022-04-21 16:15:52 +02:00
from datetime import datetime
from operator import itemgetter, attrgetter
2020-07-27 06:17:17 +02:00
from .commons.dialogs import HelpDialog, QuickDialog
2022-12-28 00:09:58 +01:00
# from PyQt5.QtCore import Qt, QSize
# from PyQt5.QtWidgets import (
# QCheckBox, QTextEdit, QVBoxLayout, QGridLayout, QLineEdit, QPlainTextEdit,
# QScrollArea, QHBoxLayout, QDoubleSpinBox, QLabel, QMessageBox
# )
from PySide6.QtCore import Qt, QSize
from PySide6.QtWidgets import (
2021-01-10 03:25:24 +01:00
QCheckBox, QTextEdit, QVBoxLayout, QGridLayout, QLineEdit, QPlainTextEdit,
2021-05-07 23:01:00 +02:00
QScrollArea, QHBoxLayout, QDoubleSpinBox, QLabel, QMessageBox
2020-12-20 12:14:56 +01:00
)
2021-01-13 23:14:57 +01:00
from .proxy import Report
2021-01-12 07:16:07 +01:00
from .buttonpad import ButtonsFunction
2021-03-17 00:15:47 +01:00
from .constants import alignCenter, alignLeft, FRACTIONS, TYPE_VEHICLE, MONEY
2021-01-27 05:26:20 +01:00
from .commons.forms import FieldMoney, ComboBox, GridForm
2020-07-27 06:17:17 +02:00
from .commons.search_window import SearchWindow
from collections import OrderedDict
from .manage_tables import ManageTables
2020-09-03 06:00:57 +02:00
from app.commons.menu_buttons import GridButtons
2020-09-15 04:53:44 +02:00
from app.commons.table import TableView
2022-12-08 15:21:43 +01:00
from app.commons.model import TableEdit
2020-09-17 04:41:10 +02:00
from .commons.custom_button import CustomButton
2021-01-26 21:45:15 +01:00
from .tools import get_icon, get_screen
2020-09-17 04:41:10 +02:00
2020-12-20 12:14:56 +01:00
__all__ = [
2022-12-08 15:21:43 +01:00
'ControlPanel', 'SearchSale', 'SearchParty', 'SearchProduct', 'Position',
'DialogPayment', 'DialogSource', 'DialogSplitSale', 'DialogTaxes', 'Help',
2021-03-17 00:15:47 +01:00
'DialogMoneyCount', 'DialogTableDeliveryParty', 'DialogDeliveryParty',
'DeliveryPartySelected', 'DialogPrintInvoice', 'DialogStock', 'Comment',
2021-03-14 16:37:35 +01:00
'DialogAuthDiscounts', 'DialogSalesmanCode', 'DialogAgent', 'ProductEdit',
2020-12-20 12:14:56 +01:00
'DialogOrder', 'DialogGlobalDiscount', 'DialogVoucher', 'DialogConsumer',
2021-03-20 18:22:28 +01:00
'DialogManageTables', 'DialogHistoricSales', 'DialogSaleForm',
2021-03-15 18:15:03 +01:00
'DialogCancelInvoice', 'DialogForceAssign', 'CombineProduct',
2022-12-08 15:21:43 +01:00
'DialogReports', 'DialogFixedDiscounts', 'DialogFixedDiscountsManual',
'DialogExpenses', 'DialogInfoProduct', 'DialogAdvance',
'DialogDeleteProduct'
2020-12-20 12:14:56 +01:00
]
2021-01-12 07:16:07 +01:00
WIZARDS = {
2021-01-14 16:56:21 +01:00
'square_box_report': {
'name': 'sale_pos_frontend.sale_square_box_report',
'fields': [
('date', {
'name': 'FECHA',
'type': 'date',
2022-04-21 16:15:52 +02:00
'default': datetime.now().strftime("%Y-%m-%d"),
2021-01-14 16:56:21 +01:00
}),
('turn', {
'name': 'TURNO',
'type': 'selection',
2021-01-14 17:06:26 +01:00
'values': [('', ''), ('1', '1'), ('2', '2'), ('3', '3')],
2021-01-14 16:56:21 +01:00
}),
],
2021-02-03 02:52:03 +01:00
},
'delivery_report': {
'fields': [
('date', {
'name': 'FECHA',
'type': 'date',
'default': datetime.now().strftime("%Y-%m-%d"),
2021-02-03 02:52:03 +01:00
}),
],
2021-01-14 16:56:21 +01:00
}
2021-01-12 07:16:07 +01:00
}
2020-09-03 06:00:57 +02:00
2021-01-29 05:45:43 +01:00
def create_vbox(parent, values, method, columns=4):
2020-09-03 06:00:57 +02:00
vbox_ = QVBoxLayout()
2021-01-28 02:20:29 +01:00
2020-09-03 06:00:57 +02:00
grid = QGridLayout()
2020-12-06 05:09:41 +01:00
grid.setSpacing(2)
2020-12-30 21:51:52 +01:00
if isinstance(method, str):
method = getattr(parent, method)
2020-12-06 05:09:41 +01:00
grid_buttons = GridButtons(parent, values, columns, action=method,
style='standard_button')
2020-09-03 06:00:57 +02:00
2020-12-06 05:09:41 +01:00
vbox_.setObjectName('grid_buttons')
2020-09-03 06:00:57 +02:00
scroll_area = QScrollArea()
scroll_area.setWidgetResizable(True)
scroll_area.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOn)
scroll_area.setWidget(grid_buttons)
grid.addWidget(scroll_area)
vbox_.addLayout(grid)
return vbox_
2021-01-10 03:25:24 +01:00
class ControlPanel(QuickDialog):
2021-01-10 18:02:30 +01:00
def __init__(self, parent):
2020-09-03 06:00:57 +02:00
vbox_ = QVBoxLayout()
grid = QGridLayout()
2021-03-16 16:14:28 +01:00
values = self.get_control_panel()
2021-03-17 00:15:47 +01:00
control_panel = ButtonsFunction(parent, values=values)
2021-03-16 16:14:28 +01:00
2020-09-03 06:00:57 +02:00
scroll_area = QScrollArea()
2021-03-16 16:14:28 +01:00
scroll_area.setLayout(control_panel)
2020-09-03 06:00:57 +02:00
grid.addWidget(scroll_area)
vbox_.addLayout(grid)
2020-12-20 12:14:56 +01:00
width, height = get_screen()
2021-01-10 03:25:24 +01:00
super(ControlPanel, self).__init__(parent, 'action', widgets=[vbox_])
self.setFixedSize(int(width * 0.5), int(height * 0.5))
2021-01-10 03:25:24 +01:00
self.setWindowTitle('PANEL DE CONTROL')
2020-07-27 06:17:17 +02:00
2021-03-16 16:14:28 +01:00
def get_control_panel(self):
2023-01-02 20:06:27 +01:00
menu_dash = (
2021-03-16 16:14:28 +01:00
('button_open', 'ABRIR ESTADOS DE CUENTA', 'action_open_statement'),
2021-03-17 00:15:47 +01:00
('button_closed', 'CERRAR ESTADOS DE CUENTA', 'action_close_statement'),
('button_expenses', 'GASTOS', 'action_expenses'),
2021-03-16 16:14:28 +01:00
('button_discount', 'DESCUENTOS AUTORIZADOS', 'action_table_discount'),
('button_delivery_party', 'CREAR DOMICILIARIO', 'action_delivery_party_panel'),
2023-01-02 20:06:27 +01:00
)
2021-03-16 16:14:28 +01:00
return menu_dash
2020-07-27 06:17:17 +02:00
2021-01-12 07:16:07 +01:00
class DialogReports(QuickDialog):
def __init__(self, parent):
super(DialogReports, self).__init__(parent, 'action')
vbox = QVBoxLayout()
grid = QGridLayout()
scroll_area = QScrollArea()
2023-01-02 20:06:27 +01:00
_reports = (
2021-01-14 17:06:26 +01:00
('button_square_box', 'CUADRE DE CAJA', 'action_square_box_report'),
('button_terminal_journal', 'PAGOS ELECTRONICOS', 'action_terminal_journal_report'),
2021-02-02 15:18:10 +01:00
('button_delivery_report', 'ENTREGA DOMICILIARIOS', 'action_delivery_report'),
2023-01-02 20:06:27 +01:00
)
2021-01-12 07:16:07 +01:00
self.reports = ButtonsFunction(parent, values=_reports)
2021-01-13 23:14:57 +01:00
self.parent = parent
2021-01-12 07:16:07 +01:00
scroll_area.setLayout(self.reports)
grid.addWidget(scroll_area)
vbox.addLayout(grid)
width, height = get_screen()
self.setFixedSize(int(width * 0.5), int(height * 0.5))
2021-01-12 07:16:07 +01:00
self.setWindowTitle('REPORTES')
self.add_widget(vbox)
2022-04-21 16:15:52 +02:00
def open_wizard(self, report, add_fields=None, open_print=True):
2021-01-12 07:16:07 +01:00
vbox = QVBoxLayout()
2021-01-14 16:56:21 +01:00
wiz_report = WIZARDS[report]
2021-02-03 02:52:03 +01:00
fields = wiz_report['fields']
if add_fields:
fields.append(add_fields)
fields = OrderedDict(fields)
2021-01-14 16:56:21 +01:00
self.form = GridForm(self, fields, col=2)
vbox.addLayout(self.form)
dialog = QuickDialog(self, 'action', widgets=[vbox])
result = dialog.exec()
store = self.form.getStore()
values = {}
values.update(store)
2022-05-06 23:23:13 +02:00
report_name = wiz_report.get('name')
2021-01-12 07:16:07 +01:00
if result == 1:
2022-04-21 16:15:52 +02:00
if not open_print:
return values, report_name
2021-02-03 02:52:03 +01:00
else:
self.open_report(report_name, values)
2021-01-12 07:16:07 +01:00
def open_report(self, report_name, data):
report = Report(self.parent.ctx)
2021-01-13 23:14:57 +01:00
values = {
2021-01-14 16:56:21 +01:00
'report_name': report_name,
2021-01-13 23:14:57 +01:00
'args': data,
}
2021-01-14 16:56:21 +01:00
result = report.get(values)
report.open(result)
2021-01-12 07:16:07 +01:00
2021-01-10 03:25:24 +01:00
class SearchSale(SearchWindow):
2020-07-27 06:17:17 +02:00
def __init__(self, parent):
self.parent = parent
self.screen_size = 'small'
2020-07-27 06:17:17 +02:00
headers = OrderedDict()
2021-01-10 03:25:24 +01:00
headers['id'] = {'desc': 'ID', 'type': 'char'}
headers['number'] = {'desc': 'NUMERO', 'type': 'char'}
headers['invoice_number'] = {'desc': 'FACTURA', 'type': 'char'}
headers['salesman.rec_name'] = {'desc': 'VENDEDOR', 'type': 'char'}
2021-02-24 05:02:35 +01:00
widths = [20, 115, 115, 160]
2023-01-02 20:06:27 +01:00
widths_append = widths.append
2021-01-10 03:25:24 +01:00
if parent._sale_pos_restaurant:
2022-12-19 17:40:42 +01:00
headers['kind'] = {'desc': 'CLASE', 'type': 'char'}
2023-01-02 20:06:27 +01:00
widths_append(110)
2021-01-10 03:25:24 +01:00
headers['consumer.rec_name'] = {'desc': 'CONSUMIDOR', 'type': 'char'}
2023-01-02 20:06:27 +01:00
widths_append(300)
2021-02-24 05:02:35 +01:00
headers['table_assigned.rec_name'] = {'desc': 'MESA', 'type': 'char'}
2023-01-02 20:06:27 +01:00
widths_append(100)
2021-02-24 05:02:35 +01:00
headers['source.name'] = {'desc': 'FUENTE', 'type': 'char'}
2023-01-02 20:06:27 +01:00
widths_append(150)
2021-02-23 20:46:28 +01:00
headers['create_date'] = {'desc': 'HORA', 'type': 'time'}
2023-01-02 20:06:27 +01:00
widths_append(120)
2021-01-26 21:45:15 +01:00
else:
2021-02-24 05:02:35 +01:00
headers['party.name'] = {'desc': 'CLIENTE', 'type': 'char'}
2023-01-02 20:06:27 +01:00
widths_append(160)
2021-01-26 21:45:15 +01:00
headers['sale_date'] = {'desc': 'FECHA', 'type': 'char'}
2023-01-02 20:06:27 +01:00
widths_append(80)
2020-12-21 17:03:44 +01:00
2021-01-10 03:25:24 +01:00
headers['position'] = {'desc': 'POSICION', 'type': 'char'}
2023-01-02 20:06:27 +01:00
widths_append(130)
2021-01-12 07:16:07 +01:00
headers['total_amount_cache'] = {'desc': 'VALOR TOTAL', 'type': 'number'}
2023-01-02 20:06:27 +01:00
widths_append(90)
2020-07-27 06:17:17 +02:00
2021-02-24 05:02:35 +01:00
title = ('BUSCAR PEDIDOS...')
2020-07-27 06:17:17 +02:00
methods = {
'on_selected_method': 'on_selected_sale',
'on_return_method': 'on_selected_sale'
}
self.buttons_layout_filter = QHBoxLayout()
self.pushButtonCash = CustomButton(
id='button_search_sale_cash',
parent=self,
# icon=get_icon('history'),
title='CONTADO',
name_style='start',
record='cash',
method='action_search_sale',
size='mini_button',
)
self.pushButtonCredit = CustomButton(
id='button_search_sale_credit',
parent=self,
# icon=get_icon('history'),
title='CREDITO',
name_style='start',
record='credit',
method='action_search_sale',
size='mini_button',
)
self.pushButtonReservation = CustomButton(
id='button_search_sale_reservation',
parent=self,
# icon=get_icon('history'),
title='RESERVA',
name_style='start',
record='reservation',
method='action_search_sale',
size='mini_button',
)
self.buttons_layout_filter.addWidget(self.pushButtonCash)
self.buttons_layout_filter.addWidget(self.pushButtonCredit)
self.buttons_layout_filter.addWidget(self.pushButtonReservation)
widgets_to_create = self.buttons_layout_filter
2021-01-10 03:25:24 +01:00
super(SearchSale, self).__init__(parent, headers, None, methods,
2023-02-02 23:29:33 +01:00
filter_column=(1, 2, 3, 4, 5, 6, 7), cols_width=widths,
title=title, fill=True, widgets=[widgets_to_create])
def action_search_sale(self, _type):
self.parent.search_sales_by_domain(_type)
2020-07-27 06:17:17 +02:00
2021-01-10 03:25:24 +01:00
class SearchParty(SearchWindow):
2020-07-27 06:17:17 +02:00
def __init__(self, parent):
headers = OrderedDict()
2021-01-10 03:25:24 +01:00
headers['id'] = {'desc': 'ID', 'type': 'char'}
headers['id_number'] = {'desc': 'NUMERO ID', 'type': 'char'}
headers['name'] = {'desc': 'NOMBRE', 'type': 'char'}
2022-03-02 20:39:13 +01:00
headers['phone'] = {'desc': 'TELEFONO', 'type': 'char'}
2021-01-10 03:25:24 +01:00
headers['street'] = {'desc': 'DIRECCION', 'type': 'char'}
2021-03-16 04:39:28 +01:00
show_party_cats = parent._config.get('show_party_categories', None)
if show_party_cats:
headers['categories_string'] = {'desc': 'CATEGORIA', 'type': 'char'}
2021-01-10 03:25:24 +01:00
title = 'BUSCAR CLIENTE'
2020-07-27 06:17:17 +02:00
methods = {
'on_selected_method': 'on_selected_party',
'on_return_method': 'on_search_party',
# 'street': parent.on_selected_street_party
2020-07-27 06:17:17 +02:00
}
2021-01-10 03:25:24 +01:00
super(SearchParty, self).__init__(parent, headers, None, methods,
2020-07-28 23:54:15 +02:00
filter_column=[], cols_width=[60, 120, 270, 190, 90],
title=title, fill=True)
2020-07-27 06:17:17 +02:00
2021-01-10 03:25:24 +01:00
class SearchProduct(SearchWindow):
2020-07-27 06:17:17 +02:00
def __init__(self, parent):
_cols_width = [10, 80]
2023-01-02 20:06:27 +01:00
_cols_width_append = _cols_width.append
2020-07-27 06:17:17 +02:00
headers = OrderedDict()
2021-01-10 03:25:24 +01:00
headers['id'] = {'desc': ('ID'), 'type': 'char'}
2021-01-12 07:16:07 +01:00
headers['code'] = {'desc': ('COD'), 'type': 'char'}
2021-01-10 03:25:24 +01:00
if parent._config.get('show_stock_pos') in ['icon', 'value']:
headers['quantity'] = {'desc': ('STOCK'), 'type': 'char'}
2021-01-12 16:32:04 +01:00
if parent._config['show_stock_pos'] == 'icon':
2020-07-27 06:17:17 +02:00
headers['quantity']['icon'] = 'stock'
headers['quantity']['type'] = 'icon'
2023-01-02 20:06:27 +01:00
_cols_width_append(60)
2020-07-27 06:17:17 +02:00
2021-01-10 03:25:24 +01:00
if not parent.cache_local:
2021-01-12 07:16:07 +01:00
headers['name'] = {'desc': 'NOMBRE', 'type': 'char'}
2020-09-07 04:19:19 +02:00
else:
2021-01-12 07:16:07 +01:00
headers['template.name'] = {'desc': 'NOMBRE', 'type': 'char'}
2020-09-07 04:19:19 +02:00
2023-01-02 20:06:27 +01:00
_cols_width_append(350)
2020-07-27 06:17:17 +02:00
2021-01-10 03:25:24 +01:00
if parent._config.get('show_description_pos'):
2021-01-12 07:16:07 +01:00
headers['description'] = {'desc': 'DESCRIPCION', 'type': 'char'}
2023-01-02 20:06:27 +01:00
_cols_width_append(300)
2020-07-27 06:17:17 +02:00
2021-01-10 03:25:24 +01:00
if parent._config.get('show_brand'):
2021-01-12 07:16:07 +01:00
headers['template.brand'] = {'desc': 'BRAND', 'type': 'char'}
2023-01-02 20:06:27 +01:00
_cols_width_append(100)
2020-07-27 06:17:17 +02:00
2021-01-10 03:25:24 +01:00
price = {'desc': ('PRICE'), 'type': 'number'}
if not parent._config.get('encoded_sale_price'):
2020-07-27 06:17:17 +02:00
headers['template.sale_price_w_tax'] = price
else:
price['type'] = 'char'
headers['encoded_sale_price'] = price
2023-01-02 20:06:27 +01:00
_cols_width_append(100)
2020-07-27 06:17:17 +02:00
2021-01-10 03:25:24 +01:00
if parent._config.get('show_location_pos'):
2021-01-12 07:16:07 +01:00
headers['location.name'] = {'desc': 'BODEGA', 'type': 'char'}
2023-01-02 20:06:27 +01:00
_cols_width_append(100)
2020-07-27 06:17:17 +02:00
2021-01-10 03:25:24 +01:00
if parent._config['show_product_image']:
2021-01-12 07:16:07 +01:00
headers['image'] = {'desc': 'IMAGEN', 'icon': 'image', 'type': 'icon'}
2023-01-02 20:06:27 +01:00
_cols_width_append(30)
2020-07-27 06:17:17 +02:00
methods = {
'on_selected_method': 'on_selected_product',
'on_return_method': 'on_search_product',
2021-01-10 03:25:24 +01:00
'image': parent.on_selected_icon_product,
'quantity': parent.on_selected_stock_product
2020-07-27 06:17:17 +02:00
}
2020-12-15 06:04:21 +01:00
fields_names = list(headers.keys())
2020-12-16 22:42:39 +01:00
try:
fields_names.remove('image')
except:
pass
2021-01-10 03:25:24 +01:00
self.fields_names = fields_names
super(SearchProduct, self).__init__(parent, headers, None, methods,
cols_width=_cols_width, fill=True)
2020-07-27 06:17:17 +02:00
2021-01-10 03:25:24 +01:00
class DialogManageTables(QuickDialog):
2020-07-28 23:54:15 +02:00
def __init__(self, parent):
2021-01-10 03:25:24 +01:00
self.parent = parent
if not parent._sale_pos_restaurant:
return
tables = parent.RestTables.find([
('shop', '=', parent.shop['id'])
])
self.manager = ManageTables(parent, tables)
width, height = get_screen()
super(DialogManageTables, self).__init__(parent, 'action',
widgets=[self.manager])
self.setFixedSize(int(width / 1.5), int(height / 1.5))
2020-07-27 06:17:17 +02:00
2023-01-02 20:06:27 +01:00
def exec(self):
2020-12-20 18:21:17 +01:00
self.open_tables()
2023-01-02 20:06:27 +01:00
super(DialogManageTables, self).exec()
2020-12-20 18:21:17 +01:00
def open_tables(self):
2021-01-10 03:25:24 +01:00
tables = self.parent.RestTables.find([
('shop', '=', self.parent.shop['id'])
2020-12-20 18:21:17 +01:00
])
self.manager.update_records(tables)
2020-09-22 17:36:52 +02:00
2021-01-10 03:25:24 +01:00
class DialogConsumer(QuickDialog):
2020-07-28 23:54:15 +02:00
def __init__(self, parent):
self._parent = parent
self._parent._consumer = None
2020-07-27 06:17:17 +02:00
vbox_consumer = QVBoxLayout()
grid = QGridLayout()
2021-03-11 04:36:03 +01:00
self.consumer = {}
2021-01-10 03:25:24 +01:00
label_phone = QLabel('TELEFONO:')
2020-07-27 06:17:17 +02:00
label_phone.setObjectName('label_phone')
grid.addWidget(label_phone, 1, 1)
2021-03-11 04:36:03 +01:00
self.form_phone = QLineEdit()
self.form_phone.setObjectName('form_consumer_phone')
self.form_phone.textChanged.connect(
2021-03-08 02:24:09 +01:00
lambda: self.update('phone'))
2021-03-11 04:36:03 +01:00
self.form_phone.editingFinished.connect(lambda: self.search())
self.form_phone.returnPressed.connect(lambda: self.search())
grid.addWidget(self.form_phone, 1, 2)
2020-07-27 06:17:17 +02:00
2021-01-10 03:25:24 +01:00
label_consumer = QLabel('CONSUMIDOR:')
2020-07-27 06:17:17 +02:00
label_consumer.setObjectName('label_consumer')
grid.addWidget(label_consumer, 2, 1)
2021-03-11 04:36:03 +01:00
self.form_name = QLineEdit()
self.form_name.setFocus()
self.form_name.setObjectName('form_consumer_name')
self.form_name.textChanged.connect(
lambda: self.update('name'))
grid.addWidget(self.form_name, 2, 2)
2020-07-27 06:17:17 +02:00
2021-01-10 03:25:24 +01:00
label_address = QLabel('DIRECCION:')
2020-07-27 06:17:17 +02:00
label_address.setObjectName('label_address')
grid.addWidget(label_address, 3, 1)
2021-03-11 04:36:03 +01:00
self.form_address = QLineEdit()
self.form_address.setObjectName('form_consumer_address')
self.form_address.textChanged.connect(
lambda: self.update('address'))
grid.addWidget(self.form_address, 3, 2)
2020-07-27 06:17:17 +02:00
2021-01-10 03:25:24 +01:00
label_id_number = QLabel('NUMERO ID:')
2020-07-27 06:17:17 +02:00
label_id_number.setObjectName('label_id_number')
grid.addWidget(label_id_number, 4, 1)
2021-03-11 04:36:03 +01:00
self.form_id_number = QLineEdit()
self.form_id_number.setObjectName('form_consumer_id_number')
self.form_id_number.textChanged.connect(
lambda: self.update('id_number'))
grid.addWidget(self.form_id_number, 4, 2)
2020-07-27 06:17:17 +02:00
label_delivery = QLabel('DOMICILO:')
label_delivery.setObjectName('label_delivery')
grid.addWidget(label_delivery, 5, 1)
self.form_delivery = QLineEdit()
self.form_delivery.setObjectName('form_consumer_delivery')
self.form_delivery.textChanged.connect(
lambda: self.update('delivery'))
grid.addWidget(self.form_delivery, 5, 2)
2021-01-10 03:25:24 +01:00
label_notes = QLabel('NOTAS:')
2020-12-21 17:03:44 +01:00
label_notes.setObjectName('label_notes')
grid.addWidget(label_notes, 6, 1)
2021-03-11 04:36:03 +01:00
self.form_notes = QPlainTextEdit()
self.form_notes.setObjectName('form_consumer_notes')
self.form_notes.textChanged.connect(
lambda: self.update('notes')
2020-09-03 06:00:57 +02:00
)
2021-03-11 04:36:03 +01:00
grid.addWidget(self.form_notes, 6, 2)
2020-09-17 04:41:10 +02:00
grid.setVerticalSpacing(15)
2021-03-13 00:27:48 +01:00
self.label_msg = QLabel('Faltan campos requeridos!')
2021-03-13 00:30:28 +01:00
grid.addWidget(self.label_msg, 7, 2)
2021-03-13 00:27:48 +01:00
self.label_msg.setVisible(False)
grid.addWidget(self.get_button(), 8, 1, 1, 2)
2020-09-03 06:00:57 +02:00
2020-07-27 06:17:17 +02:00
vbox_consumer.addLayout(grid)
2021-03-08 02:24:09 +01:00
super(DialogConsumer, self).__init__(parent, 'form', widgets=[
2021-02-24 22:20:11 +01:00
vbox_consumer])
2021-01-10 03:25:24 +01:00
self.setWindowTitle('CONSUMIDOR')
2021-03-08 02:24:09 +01:00
self.ok_button.setDefault(False)
2020-12-20 12:14:56 +01:00
width, height = get_screen()
self.setGeometry(0, 0, int(width * 0.4), int(height * 0.7))
2020-07-28 23:54:15 +02:00
2020-09-17 04:41:10 +02:00
def get_button(self):
2021-03-11 04:36:03 +01:00
self.button_history_customer = CustomButton(
2020-09-17 04:41:10 +02:00
id='button_history_customer',
parent=self._parent,
icon=get_icon('history'),
2021-01-10 03:25:24 +01:00
title='HISTORIAL DE VENTAS',
2020-09-17 04:41:10 +02:00
name_style='toolbar',
method='button_sale_consumer_history'
)
2021-03-11 04:36:03 +01:00
self.button_history_customer.setVisible(False)
return self.button_history_customer
def fill(self, values):
self.consumer = values
self.form_phone.setText(values['phone'])
self.form_name.setText(values['name'])
2022-02-08 17:28:31 +01:00
self.form_delivery.setText(values.get('delivery', None))
2021-03-11 04:36:03 +01:00
self.form_address.setText(values['address'])
2021-03-12 22:18:20 +01:00
id_number = values.get('id_number', None)
if id_number:
self.form_id_number.setText(id_number)
notes = values.get('notes', None)
2021-03-20 18:22:28 +01:00
if not notes:
notes = ''
self.form_notes.setPlainText(notes)
2021-03-12 22:18:20 +01:00
self.button_history_customer.setVisible(True)
2020-09-17 04:41:10 +02:00
2021-03-08 02:24:09 +01:00
def update(self, field):
2021-03-13 00:27:48 +01:00
self.label_msg.setVisible(False)
2021-03-11 04:36:03 +01:00
field_wid = getattr(self, 'form_' + field)
if hasattr(field_wid, 'text'):
value = field_wid.text()
else:
value = field_wid.toPlainText()
self.consumer[field] = value.upper()
2021-03-08 02:24:09 +01:00
2021-03-11 04:36:03 +01:00
def search(self):
self.ok_button.setDefault(False)
phone = self.form_phone.text()
res = self.parent.search_consumer(phone)
if res:
self.button_history_customer.setVisible(True)
def show(self):
super(DialogConsumer, self).show()
self.form_phone.setFocus()
def dialog_accepted(self):
if self.consumer and len(self.consumer['phone']) > 6:
2021-03-13 00:20:29 +01:00
if self.consumer.get('address') and self.consumer.get('name'):
self.parent.save_consumer(self.consumer)
else:
# Add dialog error missing required fields
2021-03-13 00:27:48 +01:00
self.label_msg.setVisible(True)
return
super(DialogConsumer, self).dialog_accepted()
2021-03-11 04:36:03 +01:00
def clear(self):
self.consumer = {}
self.form_phone.setText('')
self.form_name.setText('')
self.form_address.setText('')
self.form_id_number.setText('')
self.form_delivery.setText('')
2021-03-11 04:36:03 +01:00
self.form_notes.clear()
self.button_history_customer.setVisible(False)
self.ok_button.setDefault(False)
2021-01-23 14:16:49 +01:00
2020-09-17 04:41:10 +02:00
2021-03-20 18:22:28 +01:00
class DialogHistoricSales(QuickDialog):
2020-09-17 04:41:10 +02:00
def __init__(self, parent):
2021-01-24 18:21:59 +01:00
width, height = get_screen()
2023-01-02 20:06:27 +01:00
col_sizes = (fd['width'] for fd in parent.fields_sales_query)
2020-09-17 04:41:10 +02:00
vbox_ = QVBoxLayout()
2021-03-20 18:22:28 +01:00
table = TableView(
'model_sale_historic', parent.model_sale_historic,
col_sizes, method_selected_row=parent.sale_form_selected
)
2020-09-17 04:41:10 +02:00
2021-03-20 18:22:28 +01:00
vbox_.addWidget(table)
2020-09-17 04:41:10 +02:00
vbox_.addSpacing(10)
2021-03-20 18:22:28 +01:00
super(DialogHistoricSales, self).__init__(parent, 'action', widgets=[vbox_])
self.setWindowTitle('-- VENTA --')
self.setFixedSize(int(width * 0.8), int(height * 0.7))
2020-09-17 04:41:10 +02:00
2021-03-20 18:22:28 +01:00
class DialogSaleForm(QuickDialog):
2020-09-17 04:41:10 +02:00
def __init__(self, parent):
self._parent = parent
vbox_ = QVBoxLayout()
2021-01-27 05:26:20 +01:00
_fields = [
('party', {
'name': 'CLIENTE',
'readonly': True,
}),
('number', {
'name': 'NUMERO',
'readonly': True,
}),
('sale_date', {
'name': 'FECHA',
'readonly': True,
}),
('invoice_number', {
'name': 'FACTURA',
'readonly': True,
}),
('total_amount_cache', {
'name': 'TOTAL',
'readonly': True,
'type': 'money',
}),
]
fields = OrderedDict(_fields)
self.grid = GridForm(self, fields, col=2)
2023-01-02 20:06:27 +01:00
col_sizes = (field['width'] for field in parent.fields_sale_line)
self.table = TableView(
'model_sale_lines',
2021-03-20 18:22:28 +01:00
parent.model_sale_lines_simple, col_sizes
2020-12-20 12:14:56 +01:00
)
2021-01-27 05:26:20 +01:00
self.grid.addWidget(self.table, 4, 1, 1, 4)
vbox_.addLayout(self.grid)
2021-03-20 18:22:28 +01:00
super(DialogSaleForm, self).__init__(parent, 'action', widgets=[vbox_])
2021-01-27 05:26:20 +01:00
self.grid.addWidget(self.get_button(), 5, 3, 3, 4)
2020-12-20 12:14:56 +01:00
width, height = get_screen()
self.setFixedSize(int(width * 0.5), int(height * 0.6))
2021-01-27 05:26:20 +01:00
def start(self, data):
2023-01-02 20:06:27 +01:00
elements = (
'id', 'party.', 'number', 'sale_date',
'total_amount_cache', 'invoice_number', 'lines.'
)
id, party, number, sale_date, total_amount_cache, invoice_number, lines = itemgetter(*elements)(data)
self.sale_customer_selected = id
self.field_party.setText(party['name'])
self.field_number.setText(number)
self.field_sale_date.setText(sale_date)
self.field_total_amount_cache.setText(str(total_amount_cache))
self.field_invoice_number.setText(str(invoice_number))
2021-01-27 05:26:20 +01:00
self.table.model.reset()
2023-01-02 20:06:27 +01:00
for line in lines:
2021-01-27 05:26:20 +01:00
self.table.model.add_record(line)
2023-01-02 20:06:27 +01:00
self.exec()
2020-09-17 04:41:10 +02:00
def get_button(self):
2021-01-27 05:26:20 +01:00
button_duplicate_sale = CustomButton(
2020-09-17 04:41:10 +02:00
id='button_duplicate_sale',
2021-01-27 05:26:20 +01:00
parent=self,
2020-09-17 04:41:10 +02:00
icon=get_icon('duplicate_sale'),
2021-01-27 05:26:20 +01:00
title=('DUPLICAR VENTA'),
2020-09-17 04:41:10 +02:00
name_style='toolbar',
method='button_duplicate_sale'
)
2021-01-27 05:26:20 +01:00
return button_duplicate_sale
def button_duplicate_sale(self):
if self.sale_customer_selected:
res = self._parent.Sale.duplicate_sale({
'sale_id': self.sale_customer_selected,
})
2023-01-26 22:56:12 +01:00
self.parent.dialog_consumer.close()
self.parent.dialog_historic_sales.close()
self.close()
2021-01-27 05:26:20 +01:00
return res
2020-09-17 04:41:10 +02:00
2020-07-28 23:54:15 +02:00
2021-01-10 03:25:24 +01:00
class DialogAgent(QuickDialog):
2020-07-28 23:54:15 +02:00
def __init__(self, parent):
2023-01-02 20:06:27 +01:00
view = (
2020-07-27 06:17:17 +02:00
('agent_ask', {
2021-01-10 03:25:24 +01:00
'name': 'AGENTE',
2020-07-27 06:17:17 +02:00
'type': 'relation',
2021-01-10 03:25:24 +01:00
'model': parent.Agent,
2020-07-27 06:17:17 +02:00
'domain': [],
'fields': [
2021-01-10 03:25:24 +01:00
('id', 'ID'),
('party.rec_name', 'NOMBRE'),
('party.id_number', 'NUMERO ID'),
]
}),
('commission_ask', {'name': 'COMISION'}),
('commission_amount', {'name': 'VALOR', 'readonly': True}),
2023-01-02 20:06:27 +01:00
)
2021-01-10 03:25:24 +01:00
super(DialogAgent, self).__init__(parent, 'action', data=view)
2020-07-27 06:17:17 +02:00
2021-01-10 03:25:24 +01:00
class DialogCancelInvoice(QuickDialog):
2020-07-28 23:54:15 +02:00
def __init__(self, parent):
2023-01-02 20:06:27 +01:00
view = (
2020-07-27 06:17:17 +02:00
('password_for_cancel_ask', {
2021-01-10 03:25:24 +01:00
'name': 'INGRESE LA CONTRASEÑA',
2020-07-27 06:17:17 +02:00
'password': True
}),
2023-01-02 20:06:27 +01:00
)
2021-01-10 03:25:24 +01:00
super(DialogCancelInvoice, self).__init__(parent, 'action', data=view)
2020-07-27 06:17:17 +02:00
2021-01-10 03:25:24 +01:00
class DialogForceAssign(QuickDialog):
2020-07-28 23:54:15 +02:00
def __init__(self, parent):
2020-07-27 06:17:17 +02:00
field = 'password_force_assign_ask'
2021-01-10 03:25:24 +01:00
data = (field, {'name': 'CONTRASEÑA DE FORZAR ASIGNACION'})
super(DialogForceAssign, self).__init__(parent, 'action', data=[data])
2020-07-28 23:54:15 +02:00
2020-07-27 06:17:17 +02:00
2021-01-10 03:25:24 +01:00
class DialogOrder(QuickDialog):
2020-07-28 23:54:15 +02:00
def __init__(self, parent):
2021-01-10 03:25:24 +01:00
string = 'DESEA CONFIRMAR EL ENVIO DE LA ORDEN?'
super(DialogOrder, self).__init__(parent, 'action', string, data=[])
2020-07-27 06:17:17 +02:00
2021-01-10 03:25:24 +01:00
class DialogStock(QuickDialog):
2020-07-28 23:54:15 +02:00
def __init__(self, parent):
2020-07-27 06:17:17 +02:00
data = {
'name': 'stock',
'values': [],
2023-01-02 20:06:27 +01:00
'heads': ('BODEGA', 'CANTIDAD', 'POSICION'),
2020-07-27 06:17:17 +02:00
}
2021-01-10 03:25:24 +01:00
label = 'STOCK POR PRODUCTO:'
2022-02-01 21:20:11 +01:00
width, height = get_screen()
2021-01-10 03:25:24 +01:00
super(DialogStock, self).__init__(parent, 'selection', label,
data, readonly=True)
self.setFixedSize(int(width * 0.4), int(height * 0.3))
2022-02-01 21:20:11 +01:00
2020-07-27 06:17:17 +02:00
2021-01-10 03:25:24 +01:00
class DialogGlobalDiscount(QuickDialog):
2020-07-28 23:54:15 +02:00
def __init__(self, parent):
2020-07-27 06:17:17 +02:00
field = 'global_discount_ask'
2021-01-10 03:25:24 +01:00
data = (field, {'name': 'DESCUENTO GLOBAL'})
super(DialogGlobalDiscount, self).__init__(parent, 'action', data=[data])
2020-07-28 23:54:15 +02:00
2020-07-27 06:17:17 +02:00
2021-01-10 03:25:24 +01:00
class DialogPrintInvoice(QuickDialog):
2020-07-28 23:54:15 +02:00
def __init__(self, parent):
2023-01-02 20:06:27 +01:00
view = (
2021-01-25 21:21:51 +01:00
('invoice_number_ask', {'name': 'ORDEN / FACTURA'}),
2020-07-27 06:17:17 +02:00
('type_ask', {
2021-01-10 03:25:24 +01:00
'name': 'TIPO',
2020-07-27 06:17:17 +02:00
'type': 'selection',
'values': [
2021-01-10 03:25:24 +01:00
('invoice', 'FACTURA'),
2021-01-25 21:21:51 +01:00
('order', 'ORDEN'),
2021-01-10 03:25:24 +01:00
# ('delivery', ('DELIVERY'))
2020-07-27 06:17:17 +02:00
],
}),
2020-12-30 20:07:15 +01:00
('printer_ask', {
2021-01-10 03:25:24 +01:00
'name': 'IMPRESORA',
2020-12-30 20:07:15 +01:00
'type': 'selection',
'values': [
(1, 'POS'),
(2, 'LASER')
],
}),
2021-12-10 16:17:22 +01:00
('resend_dian_ask', {
'name': 'REENVIO DIAN',
'type': 'checkbox',
'placeholder': 'REENVIO DIAN',
}),
2023-01-02 20:06:27 +01:00
)
2021-01-10 03:25:24 +01:00
super(DialogPrintInvoice, self).__init__(parent, 'action', data=view)
2020-07-27 06:17:17 +02:00
class DialogAdvance(QuickDialog):
def __init__(self, parent):
2023-01-02 20:06:27 +01:00
data = (
('amount_ask', {'name': 'VALOR'}),
('reservation_ask', {
'name': 'RESERVA',
'type': 'checkbox',
'placeholder': 'RESERVA',
}),
2023-01-02 20:06:27 +01:00
)
super(DialogAdvance, self).__init__(parent, 'action', data=data)
def clean(self):
self.parent.field_amount_ask.clear()
self.parent.field_reservation_ask.setChecked(False)
2022-12-08 15:21:43 +01:00
2021-01-10 03:25:24 +01:00
class DialogVoucher(QuickDialog):
2020-07-28 23:54:15 +02:00
def __init__(self, parent):
2021-01-10 03:25:24 +01:00
data = ('voucher_ask', {'name': 'NUMERO DE COMPROBANTE'})
super(DialogVoucher, self).__init__(parent, 'action', data=[data])
2020-07-27 06:17:17 +02:00
class DialogDeleteProduct(QuickDialog):
def __init__(self, parent):
data = ('note_ask', {'name': 'OBSERVACION', 'type': 'text_area'})
super(DialogDeleteProduct, self).__init__(parent, 'action', data=[data])
2021-01-24 18:21:59 +01:00
class DialogAuthDiscounts(QuickDialog):
def __init__(self, parent):
vbox_discounts = create_vbox(
parent,
parent.discounts,
parent.on_selected_discount
)
width, height = get_screen()
super(DialogAuthDiscounts, self).__init__(parent, 'action',
2021-01-26 01:21:24 +01:00
size=(width * 0.8, height * 0.8), widgets=[vbox_discounts])
2021-01-24 18:21:59 +01:00
self.setWindowTitle('DESCUENTOS AUTORIZADOS')
class DialogFixedDiscounts(QuickDialog):
def __init__(self, parent):
2021-01-24 18:21:59 +01:00
widgets = create_vbox(
parent,
parent.discounts_fixed,
2021-01-10 03:25:24 +01:00
parent.on_selected_discount
2020-12-29 22:58:21 +01:00
)
2021-01-24 18:21:59 +01:00
width, height = get_screen()
super(DialogFixedDiscounts, self).__init__(parent, 'action',
widgets=[widgets])
self.setFixedSize(int(width * 0.8), int(height * 0.7))
2021-01-24 18:21:59 +01:00
self.setWindowTitle('DESCUENTO/BONO')
2020-09-03 06:00:57 +02:00
2021-05-28 17:09:00 +02:00
class DialogFixedDiscountsManual(QuickDialog):
def __init__(self, parent):
field = 'bono_discount_manual'
2021-05-29 00:14:32 +02:00
data = (field, {'name': 'BONO ABIERTO'})
2021-05-28 17:09:00 +02:00
super(DialogFixedDiscountsManual, self).__init__(parent, 'action', data=[data])
2021-05-29 00:14:32 +02:00
self.setWindowTitle('BONO ABIERTO')
2021-05-28 17:09:00 +02:00
2021-01-10 03:25:24 +01:00
class DialogDeliveryParty(QuickDialog):
2020-09-03 06:00:57 +02:00
def __init__(self, parent):
vbox_ = create_vbox(
2021-01-10 03:25:24 +01:00
parent,
parent.delivery_parties,
parent.on_selected_delivery_party,
2020-12-29 23:09:28 +01:00
)
2021-01-24 18:21:59 +01:00
width, height = get_screen()
2021-01-10 03:25:24 +01:00
super(DialogDeliveryParty, self).__init__(parent, 'action',
widgets=[vbox_])
2021-01-10 03:25:24 +01:00
self.setWindowTitle('ESCOJE EL DOMICILIARIO')
self.setFixedSize(int(width * 0.8), int(height * 0.7))
2020-07-27 06:17:17 +02:00
2021-01-10 03:25:24 +01:00
class DeliveryPartySelected(QuickDialog):
2020-09-15 04:53:44 +02:00
def __init__(self, parent):
2021-01-10 03:25:24 +01:00
parent.state_delivery_party = {}
2020-09-15 04:53:44 +02:00
vbox_ = QVBoxLayout()
grid = QGridLayout()
2021-01-10 03:25:24 +01:00
label_delivery_party = QLabel('DOMICILIARIO:')
2020-12-29 20:32:42 +01:00
label_delivery_party.setAlignment(alignCenter)
label_delivery_party.setObjectName('label_delivery_party')
grid.addWidget(label_delivery_party, 1, 1)
2021-01-10 03:25:24 +01:00
parent.row_delivery_party = QLineEdit()
parent.row_delivery_party.setObjectName('row_delivery_party')
parent.row_delivery_party.textChanged.connect(
lambda: parent.update_delivery_party('delivery_party'))
grid.addWidget(parent.row_delivery_party, 1, 2)
2020-09-15 04:53:44 +02:00
2021-01-25 21:21:51 +01:00
label_id_number = QLabel('NUMERO ID:')
2020-09-17 04:41:10 +02:00
label_id_number.setAlignment(alignCenter)
label_id_number.setObjectName('label_id_number')
grid.addWidget(label_id_number, 2, 1)
2021-01-10 03:25:24 +01:00
parent.row_id_number = QLineEdit()
parent.row_id_number.setObjectName('row_id_number')
parent.row_id_number.textChanged.connect(
lambda: parent.update_delivery_party('id_number'))
grid.addWidget(parent.row_id_number, 2, 2)
2020-09-17 04:41:10 +02:00
2021-01-10 03:25:24 +01:00
label_number_plate = QLabel('PLACA:')
2020-09-15 04:53:44 +02:00
label_number_plate.setAlignment(alignCenter)
label_number_plate.setObjectName('label_number_plate')
2020-09-17 04:41:10 +02:00
grid.addWidget(label_number_plate, 3, 1)
2021-01-10 03:25:24 +01:00
parent.row_number_plate = QLineEdit()
parent.row_number_plate.setObjectName('row_number_plate')
parent.row_number_plate.textChanged.connect(
lambda: parent.update_delivery_party('number_plate'))
grid.addWidget(parent.row_number_plate, 3, 2)
2020-09-15 04:53:44 +02:00
2021-01-10 03:25:24 +01:00
label_phone = QLabel('TELEFONO:')
label_phone.setAlignment(alignCenter)
label_phone.setObjectName('label_phone')
grid.addWidget(label_phone, 4, 1)
2021-01-10 03:25:24 +01:00
parent.row_phone = QLineEdit()
parent.row_phone.setObjectName('row_phone')
parent.row_phone.textChanged.connect(
lambda: parent.update_delivery_party('row_phone'))
grid.addWidget(parent.row_phone, 4, 2)
2021-01-10 03:25:24 +01:00
label_type_vehicle = QLabel('TIPO DE VEHICULO:')
2020-09-15 04:53:44 +02:00
label_type_vehicle.setAlignment(alignCenter)
label_type_vehicle.setObjectName('label_type_vehicle')
grid.addWidget(label_type_vehicle, 5, 1)
2021-01-10 03:25:24 +01:00
parent.row_type_vehicle = ComboBox(parent,
'TIPO DE VEHICULO', {'values': TYPE_VEHICLE})
parent.row_type_vehicle.setObjectName('row_type_vehicle')
parent.row_type_vehicle.currentIndexChanged.connect(
lambda: parent.update_delivery_party('type_vehicle'))
grid.addWidget(parent.row_type_vehicle, 5, 2)
label_delivery_party_active = QLabel('ACTIVO:')
2020-12-29 20:32:42 +01:00
label_delivery_party_active.setAlignment(alignCenter)
label_delivery_party_active.setObjectName('label_delivery_party_active')
grid.addWidget(label_delivery_party_active, 6, 1)
2021-01-10 03:25:24 +01:00
parent.row_delivery_party_active = QCheckBox()
parent.row_delivery_party_active.setObjectName('row_delivery_party_active')
parent.row_delivery_party_active.stateChanged.connect(
lambda: parent.update_delivery_party('delivery_party_active'))
grid.addWidget(parent.row_delivery_party_active, 6, 2)
2020-09-15 04:53:44 +02:00
vbox_.addLayout(grid)
2021-01-10 03:25:24 +01:00
super(DeliveryPartySelected, self).__init__(parent, 'action',
widgets=[vbox_])
self.accepted.connect(parent.dialog_delivery_party_accepted)
2020-09-15 04:53:44 +02:00
2021-01-10 03:25:24 +01:00
class DialogTableDeliveryParty(QuickDialog):
2020-09-15 04:53:44 +02:00
def __init__(self, parent):
self._parent = parent
2023-01-02 20:06:27 +01:00
col_sizes_tlines = (field['width'] for field in parent.fields_delivery_party)
table = TableView(
'model_delivery_party',
parent.model_delivery_party, col_sizes_tlines,
method_selected_row=parent.delivery_party_selected
2020-12-20 12:14:56 +01:00
)
width, height = get_screen()
table.setFixedSize(int(width/2.2), int(height/2.2))
2020-09-15 04:53:44 +02:00
vbox_ = QVBoxLayout()
2020-09-17 04:41:10 +02:00
grid = QGridLayout()
grid.addWidget(table, 1, 1, 1, 2)
grid.setVerticalSpacing(20)
grid.addWidget(self.get_button(), 2, 1, 1, 2)
grid.setAlignment(alignCenter)
2020-09-15 04:53:44 +02:00
2020-09-17 04:41:10 +02:00
vbox_.addLayout(grid)
2021-01-10 03:25:24 +01:00
super(DialogTableDeliveryParty, self).__init__(parent, 'action',
widgets=[vbox_])
2020-12-20 12:14:56 +01:00
width, height = get_screen()
self.setGeometry(0, 0, int(width / 1.8), int(height / 1.5))
2021-01-10 03:25:24 +01:00
self.setWindowTitle('DOMICILIARIO')
2020-09-15 04:53:44 +02:00
2020-09-17 04:41:10 +02:00
def get_button(self):
self._parent.button_create_delivery_party = CustomButton(
id='button_create_delivery_party',
parent=self._parent,
2020-12-29 20:32:42 +01:00
icon=get_icon('delivery_party'),
2021-01-10 03:25:24 +01:00
title='NUEVO DOMICILIARIO',
2020-09-17 04:41:10 +02:00
name_style='toolbar',
method='button_create_delivery_party'
)
return self._parent.button_create_delivery_party
2020-09-15 04:53:44 +02:00
2021-03-17 00:15:47 +01:00
class DialogMoneyCount(QuickDialog):
2020-09-09 21:22:35 +02:00
def __init__(self, parent):
self._parent = parent
2021-03-17 00:15:47 +01:00
self.kind = None
2020-12-20 12:14:56 +01:00
width, height = get_screen()
2021-03-17 00:15:47 +01:00
grid = QGridLayout()
2023-01-02 20:06:27 +01:00
_sizes = (160, 120, 240)
fields = (
2021-03-17 19:34:12 +01:00
{'label': 'MONEDA', 'type': 'integer', 'readonly': True},
2021-03-19 18:03:02 +01:00
{'label': 'CANTIDAD', 'type': 'integer', 'change': 'set_total'},
2021-03-17 19:34:12 +01:00
{'label': 'SUBTOTAL', 'type': 'integer', 'readonly': True},
2023-01-02 20:06:27 +01:00
)
2021-03-17 19:34:12 +01:00
self.model = TableEdit(self, MONEY, fields)
table = TableView('model', self.model, _sizes, editable=True)
table.setFixedSize(int(width * 0.35), int(height * 0.4))
2021-03-17 00:15:47 +01:00
grid.addWidget(table, 1, 0, 1, 2)
label_total = QLabel('TOTAL DINERO:')
label_total.setObjectName('label_total_money')
grid.addWidget(label_total, 2, 0)
self.field_total_money = FieldMoney(self, 'field_total_money')
self.field_total_money.setObjectName('field_total_money')
self.field_total_money.setAlignment(alignLeft)
grid.addWidget(self.field_total_money, 2, 1)
2021-03-17 15:42:23 +01:00
self.screen_size = parent.screen_size
self.button_print = CustomButton(
self,
id='button_print_count_money',
size='small',
icon=get_icon('print_sale'),
title='IMPRIMIR',
method='action_print_count_money',
name_style='mini_button',
)
grid.addWidget(self.button_print, 3, 0)
2021-03-17 00:15:47 +01:00
grid.setRowStretch(0, 1)
grid.setSpacing(10)
super(DialogMoneyCount, self).__init__(parent, 'action',
widgets=[grid])
self.setWindowTitle('CONTEO DE DINERO')
def exec(self, kind):
self.kind = kind
self.exec_()
2021-03-19 18:03:02 +01:00
def set_total(self, row):
2021-03-17 19:34:12 +01:00
_row = self.model._data[row]
2021-03-17 00:15:47 +01:00
money, value = _row[0], _row[1]
_row[2] = int(value) * int(money)
2021-03-18 23:41:30 +01:00
self.field_total_money.setText(str(self.model.get_sum(2)))
2021-03-17 00:15:47 +01:00
def dialog_accepted(self):
super(DialogMoneyCount, self).dialog_accepted()
val = self.field_total_money.text().replace(',', '')
if self.kind == 'open':
self.parent.open_statement_accepted(val)
else:
2021-03-17 19:34:12 +01:00
values = self.model._data
2021-03-17 00:15:47 +01:00
self.parent.close_statement_accepted(values)
def clear(self):
self.field_total_money.setText('0')
2021-03-17 15:42:23 +01:00
def action_print_count_money(self):
2021-03-17 17:57:23 +01:00
kind = 'CIERRE'
if self.kind == 'open':
kind = 'APERTURA'
2023-01-02 20:06:27 +01:00
_data = ((str(d[0]), str(d[1]), str(d[2])) for d in self.model._data)
2021-03-17 17:57:23 +01:00
data = {
'type': kind,
'total': self.field_total_money.text(),
'lines': _data,
}
self.parent.action_print_count_money(data)
2021-03-17 15:42:23 +01:00
2021-03-17 00:15:47 +01:00
class DialogExpenses(QuickDialog):
def __init__(self, parent):
self._parent = parent
2020-12-20 12:14:56 +01:00
width, height = get_screen()
2021-03-17 00:15:47 +01:00
grid = QGridLayout()
2021-03-17 19:34:12 +01:00
self.screen_size = parent.screen_size
self.button_add = CustomButton(
self,
id='button_add_expense',
size='small',
icon=get_icon('plus'),
title='AGREGAR',
method='action_add_expense',
name_style='mini_button',
)
grid.addWidget(self.button_add, 1, 0)
2021-03-19 18:03:02 +01:00
# self.button_test = CustomButton(
# self,
# id='button_add_expense',
# size='small',
# icon=get_icon('plus'),
# title='BORRAR',
# method='test_delete',
# name_style='mini_button',
# )
# grid.addWidget(self.button_test, 1, 1)
2021-03-17 19:34:12 +01:00
2023-01-02 20:06:27 +01:00
_sizes = (140, 290, 210, 150)
fields = (
2021-03-18 23:41:30 +01:00
{'name': 'id', 'label': 'ID', 'type': 'integer', 'invisible': True},
{'name': 'invoice_number', 'label': 'FACTURA', 'type': 'char'},
{'name': 'description', 'label': 'DESCRIPCION', 'type': 'char'},
{'name': 'reference', 'label': 'REFERENCIA', 'type': 'char'},
{'name': 'amount', 'label': 'VALOR', 'type': 'float', 'change': 'set_total'},
2023-01-02 20:06:27 +01:00
)
2021-03-18 23:41:30 +01:00
self.model = TableEdit(self, [], fields)
2021-03-19 18:03:02 +01:00
self.table = TableView('model_expenses', self.model, _sizes, editable=True)
self.table.hideColumn(0)
grid.addWidget(self.table, 2, 0, 1, 2)
2021-03-17 00:15:47 +01:00
label_total = QLabel('TOTAL:')
label_total.setObjectName('label_total_expenses')
label_total.setAlignment(alignCenter)
2021-03-17 19:34:12 +01:00
grid.addWidget(label_total, 3, 0)
2021-03-17 00:15:47 +01:00
self.field_total = FieldMoney(self, 'field_total_expenses')
self.field_total.setObjectName('field_total_expenses')
self.field_total.setAlignment(alignLeft)
2021-03-17 19:34:12 +01:00
grid.addWidget(self.field_total, 3, 1)
2021-03-17 00:15:47 +01:00
grid.setSpacing(10)
super(DialogExpenses, self).__init__(parent, 'action', widgets=[grid])
self.setGeometry(0, 0, int(width * 0.5), int(height * 0.7))
2021-03-17 00:15:47 +01:00
self.setWindowTitle('GASTOS')
2021-03-18 23:41:30 +01:00
self.id_count = -1
self.load()
def exec(self):
self.clear()
self.load()
super(DialogExpenses, self).exec()
2021-03-18 23:41:30 +01:00
def load(self):
2021-03-19 18:03:02 +01:00
if not self.parent.data_expenses:
2021-03-19 00:16:45 +01:00
return
2023-01-02 20:06:27 +01:00
model_add = self.model.add_record
2021-03-18 23:41:30 +01:00
for rec in self.parent.data_expenses:
2023-01-02 20:06:27 +01:00
data = (
2021-03-18 23:41:30 +01:00
rec['id'],
rec['invoice_number'],
rec['description'],
rec['reference'],
rec['amount']
2023-01-02 20:06:27 +01:00
)
model_add(data)
2021-03-18 23:41:30 +01:00
self.field_total.setText(str(self.model.get_sum(4)))
2021-03-19 18:03:02 +01:00
def set_total(self, args=None):
2021-03-18 23:41:30 +01:00
self.field_total.setText(str(self.model.get_sum(4)))
def save(self):
for d in self.model._data:
args = {
'statement': self.parent.statement_cash['id'],
'invoice_number': d[1],
'description': d[2],
'reference': d[3],
2023-01-07 01:18:13 +01:00
'amount': d[4].replace(',', '') if isinstance(d[4], str) else d[4],
2021-03-18 23:41:30 +01:00
}
obj_id = d[0]
if d[0] > 0:
self.parent.Expenses.write([obj_id], args)
else:
args['id'] = obj_id
rec = self.parent.Expenses.create(args)
for d in self.model._data:
if obj_id == d[0]:
d[0] = rec[0]
2021-03-17 19:34:12 +01:00
def action_add_expense(self):
2021-03-20 19:07:43 +01:00
record = [self.id_count, '', '', '', 0]
2021-03-18 23:41:30 +01:00
self.id_count += -1
self.model.add_record(record)
2021-03-19 18:03:02 +01:00
self.set_total()
2021-03-17 19:34:12 +01:00
2021-03-18 23:41:30 +01:00
def dialog_accepted(self):
self.save()
super(DialogExpenses, self).dialog_accepted()
2021-03-17 19:34:12 +01:00
def clear(self):
2021-03-19 18:03:02 +01:00
self.model.clearData()
self.set_total()
2020-09-09 21:22:35 +02:00
2020-12-20 12:14:56 +01:00
2021-01-10 03:25:24 +01:00
class DialogTaxes(QuickDialog):
2020-07-28 23:54:15 +02:00
def __init__(self, parent):
2021-01-10 03:25:24 +01:00
if parent.shop_taxes:
2023-01-02 20:06:27 +01:00
taxes = ((str(e['id']), e['name']) for e in parent.shop_taxes)
2020-07-27 06:17:17 +02:00
else:
taxes = []
data = {
'name': 'tax',
'values': taxes,
2021-01-10 03:25:24 +01:00
'heads': ['ID', 'VALOR'],
2020-07-27 06:17:17 +02:00
}
2021-01-10 03:25:24 +01:00
string = 'ESCOJA EL IMPUESTO'
super(DialogTaxes, self).__init__(parent, 'selection', string, data)
2020-07-27 06:17:17 +02:00
2021-02-24 05:02:35 +01:00
class DialogSource(QuickDialog):
def __init__(self, parent):
2021-02-24 05:02:35 +01:00
vbox_ = create_vbox(parent, parent.sources, parent.on_selected_source)
super(DialogSource, self).__init__(parent, 'action', widgets=[vbox_],
2021-01-27 15:09:12 +01:00
buttons=False)
2021-01-10 03:25:24 +01:00
self.setWindowTitle('SELECCIONE EL CANAL')
2021-01-27 15:09:12 +01:00
width, height = get_screen()
self.setFixedSize(int(width * 0.6), int(height * 0.7))
2020-12-20 12:14:56 +01:00
2021-01-10 03:25:24 +01:00
class DialogPaymentTerm(QuickDialog):
2020-07-28 23:54:15 +02:00
def __init__(self, parent):
2021-01-10 03:25:24 +01:00
vbox_ = create_vbox(parent, parent._payment_terms,
2021-01-13 00:36:15 +01:00
parent.on_selected_payment_term)
2021-01-10 03:25:24 +01:00
super(DialogPaymentTerm, self).__init__(parent, 'action', widgets=[vbox_])
2021-02-08 04:46:33 +01:00
self.setWindowTitle('PLAZO DE PAGO')
2020-07-28 23:54:15 +02:00
2020-07-27 06:17:17 +02:00
2021-01-10 03:25:24 +01:00
class DialogPayment(QuickDialog):
2020-07-28 23:54:15 +02:00
def __init__(self, parent):
2021-01-10 03:25:24 +01:00
vbox_ = create_vbox(parent, parent._journals, parent.on_selected_payment)
2021-01-12 19:22:15 +01:00
width, height = get_screen()
2021-01-10 03:25:24 +01:00
super(DialogPayment, self).__init__(parent, 'action', widgets=[vbox_])
2021-02-08 04:46:33 +01:00
self.setWindowTitle('EL MEDIO DE PAGO:')
self.setFixedSize(int(width * 0.8), int(height * 0.7))
2020-07-27 06:17:17 +02:00
2021-01-10 03:25:24 +01:00
class Position(QuickDialog):
2020-07-28 23:54:15 +02:00
def __init__(self, parent):
2021-01-10 03:25:24 +01:00
field = 'position_ask'
data = (field, {'name': 'POSICION'})
super(Position, self).__init__(parent, 'action', data=[data])
2020-07-28 23:54:15 +02:00
2020-07-27 06:17:17 +02:00
2021-01-10 03:25:24 +01:00
class Comment(QuickDialog):
2020-07-28 23:54:15 +02:00
def __init__(self, parent):
2021-01-10 03:25:24 +01:00
field = 'comment'
data = (field, {'name': 'COMENTARIO', 'type': 'text'})
super(Comment, self).__init__(parent, 'action', data=[data])
2020-07-27 06:17:17 +02:00
2021-01-10 03:25:24 +01:00
class TipAmount(QuickDialog):
2020-12-30 01:02:54 +01:00
def __init__(self, parent):
vbox_ = QVBoxLayout()
grid = QGridLayout()
label_tip_amount_ask = QLabel('VALOR PROPINA:')
label_tip_amount_ask.setAlignment(alignCenter)
label_tip_amount_ask.setObjectName('label_tip_amount_ask')
grid.addWidget(label_tip_amount_ask, 1, 1)
parent.field_tip_amount_ask = QLineEdit()
parent.field_tip_amount_ask.setObjectName('field_delivery_amount_ask')
grid.addWidget(parent.field_tip_amount_ask, 1, 2)
vbox_.addLayout(grid)
parent.field_tip_amount_invoice = QCheckBox()
parent.field_tip_amount_invoice.setText('INCLUIR EN FACTURA')
vbox_.addWidget(parent.field_tip_amount_invoice)
super(TipAmount, self).__init__(parent, 'action', widgets=[vbox_])
2020-12-30 01:02:54 +01:00
2021-01-10 03:25:24 +01:00
class DeliveryAmount(QuickDialog):
2020-12-30 01:02:54 +01:00
def __init__(self, parent):
2021-07-02 23:42:53 +02:00
vbox_ = QVBoxLayout()
grid = QGridLayout()
label_delivery_amount_ask = QLabel('VALOR DEL DOMICILO:')
label_delivery_amount_ask.setAlignment(alignCenter)
label_delivery_amount_ask.setObjectName('label_delivery_amount_ask')
grid.addWidget(label_delivery_amount_ask, 1, 1)
parent.field_delivery_amount_ask = QLineEdit()
parent.field_delivery_amount_ask.setObjectName('field_delivery_amount_ask')
grid.addWidget(parent.field_delivery_amount_ask, 1, 2)
vbox_.addLayout(grid)
parent.field_delivery_amount_invoice = QCheckBox()
parent.field_delivery_amount_invoice.setText('INCLUIR EN FACTURA')
vbox_.addWidget(parent.field_delivery_amount_invoice)
super(DeliveryAmount, self).__init__(parent, 'action', widgets=[vbox_])
2020-12-30 01:02:54 +01:00
2021-01-06 20:25:09 +01:00
class DialogSalesmanCode(QuickDialog):
def __init__(self, parent):
field = 'salesman_code_ask'
2021-01-10 03:25:24 +01:00
data = (field, {'name': 'CODIGO VENDEDOR', 'password': True})
2021-01-06 20:25:09 +01:00
super(DialogSalesmanCode, self).__init__(parent, 'action', data=[data])
2021-03-14 16:37:35 +01:00
class ProductEdit(QuickDialog):
2020-07-28 23:54:15 +02:00
def __init__(self, parent):
self._parent = parent
2021-03-14 16:37:35 +01:00
self.store = {}
self.active_line = {}
2020-07-27 06:17:17 +02:00
vbox_product = QVBoxLayout()
grid = QGridLayout()
2021-03-14 16:37:35 +01:00
2021-01-24 18:21:59 +01:00
width, height = get_screen()
2021-03-14 16:37:35 +01:00
self.label_product = QLabel()
self.label_product.setAlignment(alignCenter)
self.label_product.setObjectName('label_product')
vbox_product.addWidget(self.label_product)
2020-07-27 06:17:17 +02:00
2021-01-10 03:25:24 +01:00
if parent._config.get('show_fractions'):
2021-03-14 16:37:35 +01:00
self.field_description = QLineEdit()
self.field_description.setObjectName('field_description')
self.field_description.textChanged.connect(
lambda: self.update_line('description')
)
grid.addWidget(self.field_description, 1, 1, 1, 2)
2021-01-10 03:25:24 +01:00
label_fraction = QLabel('FRACCION:')
2020-07-27 06:17:17 +02:00
label_fraction.setObjectName('label_fraction')
grid.addWidget(label_fraction, 2, 1)
2021-03-14 16:37:35 +01:00
self.field_combobox_fraction = ComboBox(
parent, 'fraction', {'values': FRACTIONS}
)
grid.addWidget(self.field_combobox_fraction, 2, 2)
self.field_combobox_fraction.currentIndexChanged.connect(
lambda: self.update_line('qty_fraction')
2020-07-27 06:17:17 +02:00
)
2021-01-10 03:25:24 +01:00
label_qty = QLabel('CANTIDAD:')
2020-07-27 06:17:17 +02:00
label_qty.setObjectName('label_qty')
grid.addWidget(label_qty, 3, 1)
2021-03-14 16:37:35 +01:00
self.field_qty = QDoubleSpinBox()
self.field_qty.setObjectName('field_qty')
self.field_qty.setMinimum(0)
self.field_qty.setMaximum(100000)
decimals = 2
2021-01-10 03:25:24 +01:00
if parent._config.get('decimals_digits_quantity'):
2021-03-14 16:37:35 +01:00
decimals = parent._config['decimals_digits_quantity']
2021-01-10 03:25:24 +01:00
2021-03-14 16:37:35 +01:00
self.field_qty.setDecimals(decimals)
self.field_qty.setAlignment(alignCenter)
grid.addWidget(self.field_qty, 3, 2)
self.field_qty.valueChanged.connect(
lambda: self.update_line('quantity')
2020-07-27 06:17:17 +02:00
)
2021-01-10 03:25:24 +01:00
label_price = QLabel('PRECIO:')
2020-07-27 06:17:17 +02:00
label_price.setObjectName('label_price')
grid.addWidget(label_price, 4, 1)
2021-03-17 00:15:47 +01:00
self.field_price = FieldMoney(self, 'field_price', {}, readonly=False)
self.field_price.setObjectName('field_price')
2021-03-14 16:37:35 +01:00
grid.addWidget(self.field_price, 4, 2)
self.field_price.textChanged.connect(
lambda: self.update_line('unit_price')
2020-07-27 06:17:17 +02:00
)
2021-03-14 16:37:35 +01:00
self.field_note = QTextEdit('')
self.field_note.setObjectName('row_field_note')
grid.addWidget(self.field_note, 5, 1, 5, 2)
self.field_note.textChanged.connect(lambda: self.update_line('note'))
2020-12-22 21:20:39 +01:00
button_delete = CustomButton(
2021-01-10 03:25:24 +01:00
parent,
2020-12-22 21:20:39 +01:00
id='button_delete',
size='small',
icon=get_icon('delete_line'),
2021-01-10 03:25:24 +01:00
title='ELIMINAR',
2020-12-22 21:20:39 +01:00
method='action_delete_line',
name_style='mini_button',
)
2021-01-24 18:21:59 +01:00
button_discounts = CustomButton(
parent,
id='button_discount',
size='small',
icon=get_icon('discount'),
title=('DESCUENTO/BONO'),
method='action_discount_line',
name_style='mini_button',
)
2021-05-28 17:09:00 +02:00
button_discounts_bono = CustomButton(
parent,
id='button_discount_bono',
size='small',
icon=get_icon('discount'),
2021-05-29 00:21:49 +02:00
title=('BONO/ABIERTO'),
2021-05-28 17:09:00 +02:00
method='action_discount_bono_line',
name_style='mini_button',
)
2021-03-15 18:15:03 +01:00
button_addition = CustomButton(
parent,
id='button_addition',
size='small',
icon=get_icon('combine_product'),
title=('COMBINAR'),
method='action_combine_line',
name_style='mini_button',
)
2021-02-01 23:33:35 +01:00
button_combo = CustomButton(
parent,
id='button_combo',
size='small',
icon=get_icon('combo'),
2021-03-15 18:15:03 +01:00
title=('ELECCION'),
2021-02-01 23:33:35 +01:00
method='action_combo',
name_style='mini_button',
)
2020-12-30 21:51:52 +01:00
hbox = QHBoxLayout()
2020-12-27 01:00:48 +01:00
vbox_product.addLayout(grid, 1)
2020-12-30 21:51:52 +01:00
vbox_product.addLayout(hbox, 0)
hbox.addWidget(button_delete, 0)
2021-01-24 18:21:59 +01:00
hbox.addWidget(button_discounts, 0)
2022-01-25 14:30:01 +01:00
hbox_checkbox_base = QHBoxLayout()
vbox_product.addLayout(hbox_checkbox_base, 0)
self.checkbox_base = QCheckBox()
self.checkbox_base.setText('PRECIO BASE')
self.checkbox_base.setMaximumSize(120, 0)
2020-12-30 21:51:52 +01:00
2021-01-10 03:25:24 +01:00
if parent.enviroment == 'restaurant':
2021-05-28 17:09:00 +02:00
hbox.addWidget(button_discounts_bono, 0)
2021-03-11 04:36:03 +01:00
hbox.addWidget(button_combo, 0)
2020-12-30 21:51:52 +01:00
hbox.addWidget(button_addition, 0)
2022-01-25 14:30:01 +01:00
else:
hbox.addWidget(self.checkbox_base, 0)
2021-03-14 16:37:35 +01:00
super(ProductEdit, self).__init__(parent, 'action', widgets=[vbox_product])
self.setFixedSize(int(width * 0.5), int(height * 0.7))
2021-03-14 16:37:35 +01:00
def get(self):
return self.active_line
2021-03-26 20:47:19 +01:00
def close(self):
super(ProductEdit, self).close()
self.clear()
2021-05-27 22:48:17 +02:00
def closeEvent(self, event):
super(QuickDialog, self).closeEvent(event)
self.clear()
2021-03-14 16:37:35 +01:00
def clear(self):
self.store = {}
self.active_line = {}
2022-01-25 14:30:01 +01:00
self.checkbox_base.setChecked(False)
2021-03-14 16:37:35 +01:00
2021-05-27 22:48:17 +02:00
def dialog_rejected(self):
super(ProductEdit, self).dialog_rejected()
self.clear()
2021-03-14 16:37:35 +01:00
def dialog_accepted(self):
super(ProductEdit, self).dialog_accepted()
self.parent.dialog_product_edit_accepted(self.store, self.active_line)
def set_line(self, record):
self.active_line = record
self.show()
name = record.get('product.template.name', None)
if not name:
2023-02-02 23:29:33 +01:00
name = record['product.']['template.']['name']
2021-03-14 16:37:35 +01:00
self.label_product.setText(name)
if hasattr(self, 'field_description'):
self.field_description.setText(record['description'])
self.field_qty.setValue(float(record['quantity']))
self.field_price.setText(str(record['unit_price_w_tax']))
self.field_note.setText(str(record['note']))
self.field_note.setFocus()
def update_line(self, field):
value = None
self.store['id'] = self.active_line['id']
if field == 'quantity':
value = Decimal(self.field_qty.value())
if field == 'unit_price':
value = self.field_price.text()
value = value.replace(',', '')
if field == 'qty_fraction':
qty = self.field_combobox_fraction.get_id()
self.field_qty.setValue(float(qty))
value = self.field_combobox_fraction.get_label()
self.store['quantity'] = qty
price_ = self.parent.get_product_fraction_prices(
self.active_line['product']['id'],
2022-10-08 00:52:23 +02:00
self.active_line['sale'],
qty
2021-03-14 16:37:35 +01:00
)
if price_ and price_.get('unit_price_w_tax'):
price_list = str(price_['unit_price_w_tax'])
self.field_price.setText(price_list)
self.store['unit_price'] = price_list
if hasattr(self, 'field_description'):
if field == 'description':
value = self.field_description.text()
if field == 'note':
value = self.field_note.toPlainText()
if value:
self.store[field] = value
2020-07-27 06:17:17 +02:00
2021-03-15 18:15:03 +01:00
class CombineProduct(QuickDialog):
2020-12-30 21:51:52 +01:00
def __init__(self, parent):
2021-01-29 05:45:43 +01:00
self.box = QVBoxLayout()
2021-01-26 01:21:24 +01:00
width, height = get_screen()
2021-01-29 05:45:43 +01:00
self.method_action = getattr(parent, 'on_selected_item_mix')
self.parent = parent
2020-12-30 21:51:52 +01:00
2021-01-29 05:45:43 +01:00
self.box.setObjectName('grid_buttons')
2021-01-28 02:20:29 +01:00
self.filter_field = QLineEdit()
2021-01-29 05:45:43 +01:00
self.filter_field.setObjectName('field_filter_addition')
2021-01-29 06:22:26 +01:00
self.filter_field.setPlaceholderText('BUSCAR...')
2021-01-29 05:45:43 +01:00
self.filter_field.textChanged.connect(self.filter_products)
self.box.addWidget(self.filter_field)
2021-03-15 18:15:03 +01:00
super(CombineProduct, self).__init__(parent, 'action', widgets=[self.box])
2021-01-29 05:45:43 +01:00
self.setWindowTitle('SELECCIONE LA COMBINACION')
self.setFixedSize(int(width * 0.8), int(height * 0.9))
2021-01-29 05:45:43 +01:00
def set_buttons(self, values):
self.values = values
self.set_products(values)
def set_products(self, values):
grid_buttons = GridButtons(
self.parent,
values,
5,
action=self.method_action,
style='standard_button'
2021-01-28 02:20:29 +01:00
)
2021-01-29 05:45:43 +01:00
if hasattr(self, 'scroll_area'):
_ = self.box.removeWidget(self.scroll_area)
self.scroll_area = QScrollArea()
self.scroll_area.setWidgetResizable(True)
self.scroll_area.setWidget(grid_buttons)
self.box.addWidget(self.scroll_area)
2021-01-28 02:20:29 +01:00
2021-01-29 05:45:43 +01:00
def filter_products(self, text):
2021-01-29 06:22:26 +01:00
if len(text) == 0:
self.set_products(self.values)
return
2021-01-29 05:45:43 +01:00
if len(text) <= 2:
return
filtered = []
text_list = text.upper().split(' ')
for v in self.values:
for t in text_list:
if t in v['rec_name']:
filtered.append(v)
self.set_products(filtered)
2020-12-30 21:51:52 +01:00
2021-02-01 23:33:35 +01:00
class DialogComboProduct(QuickDialog):
def __init__(self, parent):
self.box = QVBoxLayout()
self.box.setObjectName('grid_buttons')
width, height = get_screen()
self.method_action = getattr(parent, 'on_selected_item_combo')
self.parent = parent
label = QLabel('SELECCIONE LOS PRODUCTOS')
label.setObjectName('label_combo_product')
self.box.addWidget(label)
2021-02-02 15:18:10 +01:00
super(DialogComboProduct, self).__init__(
parent, 'action', widgets=[self.box]
)
2021-02-01 23:33:35 +01:00
self.setWindowTitle('PRODUCTO EN COMBO')
self.setFixedSize(int(width * 0.7), int(height * 0.6))
2021-02-01 23:33:35 +01:00
def set_buttons(self, values):
self.values = values
self.set_products(values)
def set_products(self, values):
grid_buttons = GridButtons(
self.parent,
values,
4,
action=self.method_action,
style='standard_button'
)
if hasattr(self, 'scroll_area'):
_ = self.box.removeWidget(self.scroll_area)
self.scroll_area = QScrollArea()
self.scroll_area.setWidgetResizable(True)
self.scroll_area.setWidget(grid_buttons)
self.box.addWidget(self.scroll_area)
2021-03-01 03:24:52 +01:00
class DialogSplitSale(QuickDialog):
def __init__(self, parent):
self._parent = parent
box = QVBoxLayout()
box.setObjectName('box_sale_split')
width, height = get_screen()
self.parent = parent
2021-03-01 06:04:54 +01:00
self.label = QLabel()
self.label_number = QLabel()
box.addWidget(self.label)
box.addWidget(self.label_number)
self.label.setAlignment(alignCenter)
self.label_number.setAlignment(alignCenter)
self.label.setWordWrap(True)
self.label_number.setWordWrap(True)
2021-03-01 03:24:52 +01:00
super(DialogSplitSale, self).__init__(parent, 'action', widgets=[box])
self.setWindowTitle('DIVIDIR CUENTA')
self.setFixedSize(int(width * 0.4), int(height * 0.3))
2021-03-01 06:04:54 +01:00
self.label.setObjectName('label_h2')
self.label_number.setObjectName('label_h1')
def ask(self):
msg = 'DESEA CREAR UN PEDIDO CON LOS PRODUCTOS SELECCIONADOS?'
self.label.setText(msg)
self.label_number.setText('')
return self.exec_()
def info(self, number):
self.label.setText('PEDIDO CREADO EXITOSAMENTE!')
self.label_number.setText(number)
self.exec_()
2021-03-01 03:24:52 +01:00
2020-07-27 06:17:17 +02:00
class Help(HelpDialog):
def __init__(self, parent):
2020-07-29 19:38:27 +02:00
super(Help, self).__init__(parent)
2023-01-02 20:06:27 +01:00
shortcuts = (
2021-01-26 13:38:27 +01:00
('PANEL DE CONTROL', 'F1'),
2021-01-25 21:21:51 +01:00
('BUSCAR PRODUCTO', 'F2'),
('MEDIO DE PAGO', 'F3'),
('BUSCAR CLIENTE', 'F4'),
('DESCUENTO GLOBAL', 'F5'),
2021-02-08 04:46:33 +01:00
('ENVIAR ORDEN', 'F6'),
('IMPRIMIR ORDEN/FACTURA', 'F7'),
2021-01-25 21:21:51 +01:00
('PLAZO DE PAGO', 'F8'),
('BUSCAR ORDEN', 'F9'),
2021-02-08 04:46:33 +01:00
('CONSULTAR PRECIO', 'F10'),
2021-01-25 21:21:51 +01:00
('NUEVA VENTA', 'F11'),
2021-01-26 13:38:27 +01:00
('DOMICILIARIO', 'F12'),
2021-01-25 21:21:51 +01:00
('POSICION', 'Insert'),
('FACTURAR', 'End'),
('COMENTARIO', 'Quotation Marks'),
2023-01-02 20:06:27 +01:00
)
2020-07-27 06:17:17 +02:00
self.set_shortcuts(shortcuts)
2021-04-12 18:29:53 +02:00
2021-05-03 21:33:21 +02:00
class DialogListProduct(QuickDialog):
def __init__(self, parent):
self._parent = parent
vbox = QVBoxLayout()
grid = QGridLayout()
label_code = QLabel('CODIGO:')
label_code.setObjectName('label_info_product_code')
grid.addWidget(label_code, 1, 1)
self.input_code = QLineEdit()
self.input_code.setObjectName('input_info_product_code')
self.input_code.returnPressed.connect(lambda: self.search())
grid.addWidget(self.input_code, 1, 2)
2021-04-12 18:29:53 +02:00
class DialogInfoProduct(QuickDialog):
def __init__(self, parent):
self._parent = parent
self.products = []
2021-04-12 18:29:53 +02:00
vbox = QVBoxLayout()
grid = QGridLayout()
2021-05-07 23:01:00 +02:00
label_filter = QLabel('FILTRO:')
label_filter.setObjectName('label_info_product_filter')
grid.addWidget(label_filter, 1, 1)
self.input_filter = QLineEdit()
self.input_filter.setObjectName('input_info_product_filter')
self.input_filter.returnPressed.connect(lambda: self.search())
grid.addWidget(self.input_filter, 1, 2)
2021-04-12 18:29:53 +02:00
label_code = QLabel('CODIGO:')
label_code.setObjectName('label_info_product_code')
2021-05-07 23:01:00 +02:00
grid.addWidget(label_code, 2, 1)
2021-04-12 18:29:53 +02:00
self.input_code = QLineEdit()
2021-05-07 23:01:00 +02:00
self.input_code.setReadOnly(True)
2021-04-12 18:29:53 +02:00
self.input_code.setObjectName('input_info_product_code')
2021-05-07 23:01:00 +02:00
grid.addWidget(self.input_code, 2, 2)
2021-04-12 18:29:53 +02:00
label_name = QLabel('NOMBRE:')
label_name.setObjectName('label_info_product_name')
2021-05-07 23:01:00 +02:00
grid.addWidget(label_name, 3, 1)
2021-04-12 18:29:53 +02:00
self.input_name = QLineEdit()
2021-05-07 23:01:00 +02:00
self.input_name.setReadOnly(True)
2021-04-12 18:29:53 +02:00
self.input_name.setObjectName('input_info_product_name')
2021-05-07 23:01:00 +02:00
grid.addWidget(self.input_name, 3, 2)
2021-04-12 18:29:53 +02:00
label_price = QLabel('PRECIO:')
label_price.setObjectName('label_info_product_price')
2021-05-07 23:01:00 +02:00
grid.addWidget(label_price, 4, 1)
2021-04-12 18:29:53 +02:00
self.input_price = QLineEdit()
self.input_price.setReadOnly(True)
self.input_price.setObjectName('input_info_product_price')
2021-05-07 23:01:00 +02:00
grid.addWidget(self.input_price, 4, 2)
2021-04-12 18:29:53 +02:00
label_quantity = QLabel('CANTIDAD:')
label_quantity.setObjectName('label_info_product_quantity')
2021-05-07 23:01:00 +02:00
grid.addWidget(label_quantity, 5, 1)
2021-04-12 18:29:53 +02:00
self.input_quantity = QLineEdit()
self.input_quantity.setReadOnly(True)
self.input_quantity.setObjectName('input_info_product_quantity')
2021-05-07 23:01:00 +02:00
grid.addWidget(self.input_quantity, 5, 2)
2021-04-12 18:29:53 +02:00
vbox.addLayout(grid)
super(DialogInfoProduct, self).__init__(parent, 'help', widgets=[vbox])
self.setWindowTitle('INFO. PRODUCT')
self.ok_button.setDefault(False)
width, height = get_screen()
self.setGeometry(0, 0, int(width * 0.4), int(height * 0.7))
2021-05-07 23:01:00 +02:00
self.input_filter.setFocus()
2021-04-12 18:29:53 +02:00
def fill(self, values):
2021-05-03 21:33:21 +02:00
self.input_code.setText(values['code'])
2021-04-12 18:29:53 +02:00
self.input_name.setText(values['name'])
2022-01-26 20:25:06 +01:00
extra_tax = values['extra_tax'] if values.get('extra_tax') else 0
2023-01-23 17:05:41 +01:00
sale_price_w_tax = values['template.']['sale_price_w_tax']
2022-01-26 20:25:06 +01:00
sale_price = "{:,}".format(round(sale_price_w_tax + extra_tax, 0))
2021-04-12 18:29:53 +02:00
self.input_price.setText(sale_price)
self.input_quantity.setText(str(values['quantity']))
2021-05-03 21:33:21 +02:00
def search(self, values=None):
2021-04-12 18:29:53 +02:00
self.ok_button.setDefault(False)
2021-05-07 23:01:00 +02:00
filter = self.input_filter.text()
if not filter:
return
domain = [
('template.salable', '=', True),
('template.account_category', '!=', None),
]
domain.append([
'OR',
2023-01-08 03:15:11 +01:00
# ('barcode', 'ilike', '%' + filter + '%'),
2021-05-07 23:01:00 +02:00
('code', 'ilike', '%' + filter + '%'),
('name', 'ilike', '%' + filter + '%')
])
if self._parent.cache_local:
clause = [
'OR',
2023-01-08 03:15:11 +01:00
# ('barcode', 'ilike', '%{:}%'.format(filter)),
2021-05-07 23:01:00 +02:00
('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,
2023-01-23 17:05:41 +01:00
fields=['name', 'code', 'description',
'id', 'list_price',
'quantity', 'rec_name', 'template',
'extra_tax', 'template.sale_price_w_tax',
2023-01-08 03:15:11 +01:00
'write_date'])
2021-05-07 23:01:00 +02:00
if not products:
self.message_bar.set('product_not_found')
return False
elif len(products) > 1:
self.products = products
self.create_dialog_select_item(products)
2021-05-07 23:02:53 +02:00
else:
product = products[0]
if product:
self.fill(product)
def on_selected_product(self, row=None):
code = row[0]
for product in self.products:
if product['code'] == code:
self.fill(product)
self.dialog_select_item.hide()
break
def create_dialog_select_item(self, products):
parent = self._parent
2021-05-07 23:01:00 +02:00
width, height = get_screen()
grid = QGridLayout()
2023-01-02 20:06:27 +01:00
_sizes = (160, 320)
fields = (
{'label': 'CODIGO', 'type': 'integer', 'readonly': False},
{'label': 'NOMBRE', 'type': 'char', 'readonly': False},
2023-01-02 20:06:27 +01:00
)
self.model = TableEdit(self, [], fields)
self.table = TableView('model_info_product', self.model, _sizes, editable=False, method_selected_row=self.on_selected_product)
self.table.setFixedSize(int(width * 0.35), int(height * 0.4))
grid.addWidget(self.table, 1, 0, 1, 2)
self.dialog_select_item = QuickDialog(parent, 'action', widgets=[grid], readonly=True, buttons=True)
self.dialog_select_item.setWindowTitle('PRODUCTOS')
self.load(products)
self.dialog_select_item.show()
def load(self, products):
if not products:
return
for rec in products:
data = [
rec['code'],
rec['name'],
]
self.model.add_record(data)
2021-04-12 18:29:53 +02:00
def show(self):
super(DialogInfoProduct, self).show()
2021-05-07 23:01:00 +02:00
self.input_filter.setFocus()
2021-04-12 18:29:53 +02:00
def clear(self):
self.input_filter.setText('')
2021-04-12 18:29:53 +02:00
self.input_code.setText('')
self.input_name.setText('')
self.input_price.setText('')
self.input_quantity.setText('')
def dialog_accepted(self):
self.clear()
super(DialogInfoProduct, self).dialog_accepted()