From 8c585617b540a7ea037530cef7a68c93612ab27d Mon Sep 17 00:00:00 2001 From: Oscar Alvarez Date: Tue, 26 Jan 2021 23:26:20 -0500 Subject: [PATCH] Fix consumer sale --- app/dialogs.py | 152 +++++++++++++++++++++------------------------- app/mainwindow.py | 71 ++++++++++------------ app/models.py | 3 +- app/reporting.py | 2 +- 4 files changed, 102 insertions(+), 126 deletions(-) diff --git a/app/dialogs.py b/app/dialogs.py index 5af764a..328fbb7 100644 --- a/app/dialogs.py +++ b/app/dialogs.py @@ -3,14 +3,13 @@ from .commons.dialogs import HelpDialog, QuickDialog from PyQt5.QtCore import Qt from PyQt5.QtWidgets import ( QCheckBox, QTextEdit, QVBoxLayout, QGridLayout, QLineEdit, QPlainTextEdit, - QScrollArea, QHBoxLayout, QDoubleSpinBox, QDesktopWidget, QLabel, + QScrollArea, QHBoxLayout, QDoubleSpinBox, QLabel, ) from .proxy import FastReport -from app.commons.forms import GridForm from .buttonpad import ButtonsFunction from .constants import alignCenter, alignLeft, FRACTIONS, TYPE_VEHICLE -from .commons.forms import FieldMoney, ComboBox +from .commons.forms import FieldMoney, ComboBox, GridForm from .commons.search_window import SearchWindow from collections import OrderedDict from .manage_tables import ManageTables @@ -295,7 +294,7 @@ class DialogConsumer(QuickDialog): label_consumer.setObjectName('label_consumer') grid.addWidget(label_consumer, 2, 1) self._parent.form_consumer_name = QLineEdit() - self._parent.form_consumer_name.setObjectName('row_field_consumer') + self._parent.form_consumer_name.setObjectName('form_consumer_name') self._parent.form_consumer_name.textChanged.connect( lambda: self._parent.update_consumer('name')) grid.addWidget(self._parent.form_consumer_name, 2, 2) @@ -304,7 +303,7 @@ class DialogConsumer(QuickDialog): label_address.setObjectName('label_address') grid.addWidget(label_address, 3, 1) self._parent.form_consumer_address = QLineEdit() - self._parent.form_consumer_address.setObjectName('row_field_address') + self._parent.form_consumer_address.setObjectName('form_consumer_address') self._parent.form_consumer_address.textChanged.connect( lambda: self._parent.update_consumer('address')) grid.addWidget(self._parent.form_consumer_address, 3, 2) @@ -313,7 +312,7 @@ class DialogConsumer(QuickDialog): label_id_number.setObjectName('label_id_number') grid.addWidget(label_id_number, 4, 1) self._parent.form_consumer_id_number = QLineEdit() - self._parent.form_consumer_id_number.setObjectName('row_field_id_number') + self._parent.form_consumer_id_number.setObjectName('form_consumer_id_number') self._parent.form_consumer_id_number.textChanged.connect( lambda: self._parent.update_consumer('id_number')) grid.addWidget(self._parent.form_consumer_id_number, 4, 2) @@ -322,7 +321,7 @@ class DialogConsumer(QuickDialog): label_notes.setObjectName('label_notes') grid.addWidget(label_notes, 6, 1) self._parent.form_consumer_notes = QPlainTextEdit() - self._parent.form_consumer_notes.setObjectName('row_field_id_number') + self._parent.form_consumer_notes.setObjectName('form_consumer_notes') self._parent.form_consumer_notes.textChanged.connect( lambda: self._parent.update_consumer('notes') ) @@ -335,7 +334,7 @@ class DialogConsumer(QuickDialog): widgets=[vbox_consumer]) self.setWindowTitle('CONSUMIDOR') width, height = get_screen() - self.setGeometry(0, 0, width / 2.7, height / 1.8) + self.setGeometry(0, 0, width * 0.4, height * 0.7) self.accepted.connect(self._parent.dialog_search_consumer_accepted) def get_button(self): @@ -373,7 +372,7 @@ class DialogTableSaleConsumer(QuickDialog): ) width, height = get_screen() - table.setFixedSize(width * 0.5, height * 0.5) + table.horizontalHeader().setStretchLastSection(True) vbox_ = QVBoxLayout() layout = QVBoxLayout() @@ -385,100 +384,85 @@ class DialogTableSaleConsumer(QuickDialog): super(DialogTableSaleConsumer, self).__init__(parent, 'action', widgets=[vbox_]) self.setWindowTitle('VENTAS POR CONSUMIDOR') - self.setFixedSize(width / 1.3, height / 1.7) + self.setFixedSize(width * 0.6, height * 0.7) class SaleConsumerSelected(QuickDialog): def __init__(self, parent): self._parent = parent vbox_ = QVBoxLayout() - grid = QGridLayout() - - label_party = QLabel('TERCERO:') - label_party.setAlignment(alignLeft) - label_party.setObjectName('label_party') - grid.addWidget(label_party, 1, 1) - self._parent.row_sale_party = QLineEdit() - self._parent.row_sale_party.setObjectName('row_sale_party') - grid.addWidget(self._parent.row_sale_party, 1, 2) - - label_number = QLabel('NUMERO:') - label_number.setAlignment(alignLeft) - label_number.setObjectName('label_number') - grid.addWidget(label_number, 1, 3) - self._parent.row_sale_number = QLineEdit() - self._parent.row_sale_number.setObjectName('row_sale_number') - grid.addWidget(self._parent.row_sale_number, 1, 4) - - label_date = QLabel('FECHA:') - label_date.setAlignment(alignLeft) - label_date.setObjectName('label_date') - grid.addWidget(label_date, 2, 1) - self._parent.row_sale_date = QLineEdit() - self._parent.row_sale_date.setObjectName('row_sale_date') - grid.addWidget(self._parent.row_sale_date, 2, 2) - - label_salesman = QLabel('VENDEDOR:') - label_salesman.setAlignment(alignLeft) - label_salesman.setObjectName('label_salesman') - grid.addWidget(label_salesman, 2, 3) - self._parent.row_sale_salesman = QLineEdit() - self._parent.row_sale_salesman.setObjectName('row_sale_salesman') - grid.addWidget(self._parent.row_sale_salesman, 2, 4) - - label_lines = QLabel('LINEAS:') - label_lines.setAlignment(alignLeft) - label_lines.setObjectName('label_lines') - grid.addWidget(label_lines, 3, 1, 1, 4) + _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) col_sizes_tlines = [field['width'] for field in parent.fields_sale_line] - table = TableView('model_sale_lines', + self.table = TableView('model_sale_lines', parent.model_sale_customer_lines, col_sizes_tlines ) - grid.addWidget(table, 4, 1, 1, 4) - - label_untaxed = QLabel('VALOR BASE:') - label_untaxed.setAlignment(alignCenter) - label_untaxed.setObjectName('label_untaxed') - grid.addWidget(label_untaxed, 5, 1) - self._parent.row_sale_untaxed = QLineEdit() - self._parent.row_sale_untaxed.setObjectName('row_sale_untaxed') - grid.addWidget(self._parent.row_sale_untaxed, 5, 2) - - label_tax_amount = QLabel('IMPUESTOS:') - label_tax_amount.setAlignment(alignCenter) - label_tax_amount.setObjectName('label_tax_amount') - grid.addWidget(label_tax_amount, 6, 1) - self._parent.row_sale_tax_amount = QLineEdit() - self._parent.row_sale_tax_amount.setObjectName('row_sale_tax_amount') - grid.addWidget(self._parent.row_sale_tax_amount, 6, 2) - - label_total = QLabel('VALOR TOTAL:') - label_total.setAlignment(alignCenter) - label_total.setObjectName('label_total') - grid.addWidget(label_total, 7, 1) - self._parent.row_sale_total = QLineEdit() - self._parent.row_sale_total.setObjectName('row_sale_total') - grid.addWidget(self._parent.row_sale_total, 7, 2) - - grid.setVerticalSpacing(15) - grid.addWidget(self.get_button(), 5, 3, 3, 4) - - vbox_.addLayout(grid) + self.grid.addWidget(self.table, 4, 1, 1, 4) + vbox_.addLayout(self.grid) super(SaleConsumerSelected, self).__init__(parent, 'action', widgets=[vbox_]) + + self.grid.addWidget(self.get_button(), 5, 3, 3, 4) width, height = get_screen() - self.setFixedSize(width * 0.4, height * 0.5) + self.setFixedSize(width * 0.5, height * 0.6) + + def start(self, data): + self.sale_customer_selected = data['id'] + self.field_party.setText(data['party']['name']) + self.field_number.setText(data['number']) + self.field_sale_date.setText(data['sale_date']) + self.field_total_amount_cache.setText(str(data['total_amount_cache'])) + self.field_invoice_number.setText(str(data['invoice_number'])) + self.table.model.reset() + for line in data['lines']: + self.table.model.add_record(line) + self.exec_() def get_button(self): - self._parent.button_duplicate_sale = CustomButton( + button_duplicate_sale = CustomButton( id='button_duplicate_sale', - parent=self._parent, + parent=self, icon=get_icon('duplicate_sale'), - title=('DUPLICATE SALE'), + title=('DUPLICAR VENTA'), name_style='toolbar', method='button_duplicate_sale' ) - return self._parent.button_duplicate_sale + 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, + }) + self.dialog_search_consumer.close() + self.dialog_table_sale_consumer.close() + self.dialog_sale_consumer_selected.close() + # FIXME + # self.load_sale(res['sale_id']) + return res class DialogAgent(QuickDialog): diff --git a/app/mainwindow.py b/app/mainwindow.py index e39cc98..37b58e6 100644 --- a/app/mainwindow.py +++ b/app/mainwindow.py @@ -916,15 +916,15 @@ class MainWindow(FrontWindow): for i in range(copies): self.receipt_sale.print_sale(data, type_doc, open_box) - def button_duplicate_sale(self): - if self.sale_customer_selected: - res = self.Sale.duplicate_sale({ - 'sale_id': self.sale_customer_selected, - }) - self.load_sale(res['sale_id']) - self.dialog_search_consumer.close() - self.dialog_table_sale_consumer.close() - self.dialog_sale_consumer_selected.close() + # def button_duplicate_sale(self): + # if self.sale_customer_selected: + # res = self.Sale.duplicate_sale({ + # 'sale_id': self.sale_customer_selected, + # }) + # self.load_sale(res['sale_id']) + # self.dialog_search_consumer.close() + # self.dialog_table_sale_consumer.close() + # self.dialog_sale_consumer_selected.close() def button_create_delivery_party(self): self.clear_delivery_party() @@ -2094,17 +2094,7 @@ class MainWindow(FrontWindow): self.row_field_note.setFocus() def sale_consumer_selected(self, data): - self.sale_customer_selected = data['id'] - self.row_sale_party.setText(data['party']['name']) - self.row_sale_number.setText(data['number']) - self.row_sale_date.setText(data['sale_date']) - self.row_sale_tax_amount.setText(str(data['tax_amount'])) - self.row_sale_untaxed.setText(str(data['untaxed_amount'])) - self.row_sale_total.setText(str(data['total_amount_cache'])) - self.model_sale_customer_lines.reset() - for line in data['lines']: - self.model_sale_customer_lines.add_record(line) - self.dialog_sale_consumer_selected.exec_() + self.dialog_sale_consumer_selected.start(data) def clear_delivery_party(self): self._delivery_party_selected = None @@ -2162,6 +2152,7 @@ class MainWindow(FrontWindow): 'digits': ('unit.symbol', CONVERSION_DIGITS), 'width': 80 } + discount = { 'name': 'discount', 'format': '{0:.0%}', @@ -2212,37 +2203,34 @@ class MainWindow(FrontWindow): if self.enviroment == 'retail': self.fields_sale_line.insert(0, product_code) - if self.enviroment == 'restaurant': - self.fields_sale_line.insert(1, commanded) - if self._config.get('show_description_pos'): self.fields_sale_line.insert(2, description) if self._config.get('show_fractions'): self.fields_sale_line.insert(4, qty_fraction) + if self.enviroment == 'restaurant': + self.fields_sale_line.insert(6, commanded) + + self.model_sale_customer_lines = TableModel( + 'sale.line', [product, qty, unit_price, amount, note] + ) + self.model_sale_lines = TableModel('sale.line', self.fields_sale_line) - self.model_sale_customer_lines = TableModel('sale.line', self.fields_sale_line) def setup_sale_consumer(self): number = { 'name': 'number', 'align': alignCenter, - 'description': 'NUMERO', + 'description': 'ORDEN', 'width': 200 } invoice_number = { 'name': 'invoice_number', 'align': alignCenter, - 'description': 'FACTURA NUMERO', + 'description': 'FACTURA', 'width': 200 } - consumer = { - 'name': 'consumer.name', - 'align': alignCenter, - 'description': 'CONSUMIDOR', - 'width': 300 - } sale_date = { 'name': 'sale_date', 'align': alignCenter, @@ -2257,7 +2245,7 @@ class MainWindow(FrontWindow): } self.fields_sale_consumer = [ - number, invoice_number, consumer, sale_date, total_amount_cache + number, invoice_number, sale_date, total_amount_cache ] self.model_sale_consumer = TableModel('sale.sale', self.fields_sale_consumer) @@ -2804,12 +2792,15 @@ class MainWindow(FrontWindow): self.load_sale(sale['id']) self.dialog_manage_tables.hide() - def set_consumer(self): - self.form_consumer_notes.clear() - self.form_consumer_phone.setText(self._consumer['phone']) - self.form_consumer_name.setText(self._consumer['name']) - self.form_consumer_address.setText(self._consumer['address']) - self.form_consumer_notes.insertPlainText(self._consumer['notes']) - id_number = self._consumer.get('id_number') + def set_consumer(self, consumer=None): + _consumer = consumer or self._consumer + if not _consumer: + return + self.form_consumer_phone.setText(_consumer['phone']) + self.form_consumer_name.setText(_consumer['name']) + self.form_consumer_address.setText(_consumer['address']) + self.form_consumer_notes.setPlainText(_consumer['notes']) + id_number = _consumer.get('id_number') + self.button_history_customer.setVisible(True) if id_number: self.form_consumer_id_number.setText(id_number) diff --git a/app/models.py b/app/models.py index 5468775..d6049a5 100644 --- a/app/models.py +++ b/app/models.py @@ -34,7 +34,8 @@ MODELS = { 'state_string', 'shop', 'delivery_party', 'reference', 'comment', 'delivery_state', 'table_assigned', 'invoice_type', 'net_amount', 'tip_amount', 'delivery_amount', 'commission', 'agent', - 'payment_method', 'order_status', + 'payment_method', 'order_status', 'consumer.name', 'consumer.phone', + 'consumer.address', 'consumer.notes', ] }, 'sale.line': { diff --git a/app/reporting.py b/app/reporting.py index b863608..67a6ff5 100755 --- a/app/reporting.py +++ b/app/reporting.py @@ -699,7 +699,7 @@ class Receipt(object): self.print_enter() self._printer.text('VENDEDOR: %s' % order['salesman']) self.print_enter() - self._printer.text('AMBIENTE: %s' % order['shop']) + self._printer.text('SUCURSAL: %s' % order['shop']) self.print_enter() self._printer.text('CLIENTE: %s' % order['party']) self.print_enter()