Moved methods to Front
This commit is contained in:
parent
b3e322638f
commit
c143ab440a
|
@ -3,12 +3,13 @@ import os
|
|||
import time
|
||||
import logging
|
||||
from pathlib import Path
|
||||
|
||||
from collections import OrderedDict
|
||||
from PyQt5.QtWidgets import QMainWindow, QDesktopWidget, QLabel, QLineEdit
|
||||
from PyQt5.QtCore import QTimer, QThread, pyqtSignal, Qt
|
||||
|
||||
from .commons.dialogs import QuickDialog
|
||||
from .commons.dblogin import safe_reconnect
|
||||
from .proxy import FastModel
|
||||
from .constants import SCREENS
|
||||
from .dialogs import (
|
||||
Help, ControlPanel, SearchSale, SearchParty, SearchProduct, Position,
|
||||
|
@ -20,7 +21,6 @@ from .dialogs import (
|
|||
DialogTableDeliveryParty, DialogTableSaleConsumer, SaleConsumerSelected
|
||||
)
|
||||
|
||||
|
||||
__all__ = ['FrontWindow', 'ClearUi']
|
||||
|
||||
parent = Path(__file__).parent
|
||||
|
@ -69,10 +69,6 @@ class FrontWindow(QMainWindow):
|
|||
self.timeout = _DEFAULT_TIMEOUT
|
||||
self.set_stack_messages()
|
||||
|
||||
# if show_mode == 'fullscreen':
|
||||
# self.window().showFullScreen()
|
||||
# else:
|
||||
# self.window().show()
|
||||
self.setFocus()
|
||||
self.global_timer = 0
|
||||
print('Screen Size: > ', self.screen_size)
|
||||
|
@ -86,6 +82,14 @@ class FrontWindow(QMainWindow):
|
|||
self.label_color_2 = 'orange'
|
||||
self.window().showMaximized()
|
||||
|
||||
def filter_cache(self, data, filter, target):
|
||||
res = []
|
||||
for d in data:
|
||||
for t in target:
|
||||
if t in d[filter]:
|
||||
res.append(d)
|
||||
return res
|
||||
|
||||
def get_geometry(self):
|
||||
screen = QDesktopWidget().screenGeometry()
|
||||
return screen.width(), screen.height()
|
||||
|
@ -110,7 +114,6 @@ class FrontWindow(QMainWindow):
|
|||
if theme_css:
|
||||
theme_css = os.path.join(str(parent), 'css', theme_css + '.css')
|
||||
for style in [theme_css or file_base_css, file_css]:
|
||||
print('style...', style)
|
||||
with open(style, 'r') as infile:
|
||||
styles.append(infile.read())
|
||||
self.setStyleSheet(''.join(styles))
|
||||
|
@ -247,6 +250,158 @@ class FrontWindow(QMainWindow):
|
|||
Help(self).show()
|
||||
|
||||
|
||||
def resize_window_tablet_dev(self):
|
||||
self.resize(690, self.get_geometry()[1])
|
||||
|
||||
def load_modules(self):
|
||||
self._sale_pos_restaurant = None
|
||||
self.Module = FastModel('ir.module', self.ctx)
|
||||
self.Config = FastModel('sale.configuration', self.ctx)
|
||||
self._config, = self.Config.find([('id', '=', 1)])
|
||||
self.discount_method = self._config.get('discount_pos_method')
|
||||
|
||||
self._commission_activated = self.Module.find([
|
||||
('name', '=', 'commission'),
|
||||
('state', '=', 'activated'),
|
||||
])
|
||||
self._web_channel = self.Module.find([
|
||||
('name', '=', 'sale_web_channel'),
|
||||
('state', '=', 'activated'),
|
||||
])
|
||||
self._credit_limit_activated = self.Module.find([
|
||||
('name', '=', 'account_credit_limit'),
|
||||
('state', '=', 'activated'),
|
||||
])
|
||||
|
||||
_product = {
|
||||
'name': 'product.product',
|
||||
'fields': [
|
||||
'template.name', 'code', 'barcode', 'write_date',
|
||||
'description', 'template.sale_price_w_tax',
|
||||
'template.account_category'
|
||||
]
|
||||
}
|
||||
self.cache_local = self._config.get('cache_products_local')
|
||||
|
||||
if self._config['show_location_pos']:
|
||||
_product['fields'].append('location_')
|
||||
|
||||
if self._config['show_stock_pos'] in ('value', 'icon'):
|
||||
if self._config['show_stock_pos'] == 'value':
|
||||
_product['fields'].append('quantity')
|
||||
if self._config['show_brand']:
|
||||
_product['fields'].append('brand.name')
|
||||
|
||||
if self._config['encoded_sale_price']:
|
||||
_product['fields'].extend(['image', 'image_icon', 'encoded_sale_price'])
|
||||
|
||||
if self.enviroment == 'restaurant':
|
||||
self._sale_pos_restaurant = self.Module.find([
|
||||
('name', '=', 'sale_pos_frontend_rest'),
|
||||
('state', '=', 'activated'),
|
||||
])
|
||||
if self._sale_pos_restaurant:
|
||||
self.PartyConsumer = FastModel('party.consumer', self.ctx)
|
||||
if self._config['delivery_product']:
|
||||
self._delivery_product = 0
|
||||
|
||||
self.User = FastModel('res.user', self.ctx)
|
||||
self._user, = self.User.find([('login', '=', self.user)])
|
||||
self.Company = FastModel('company.company', self.ctx)
|
||||
self._company, = self.Company.find([('id', '=', 1)])
|
||||
self.logo = self._company['logo']
|
||||
|
||||
if not self._user['sale_device']:
|
||||
return 'user_not_permissions_device'
|
||||
|
||||
self.ctx['user'] = self._user['id']
|
||||
|
||||
self.Sale = FastModel('sale.sale', self.ctx)
|
||||
self.SaleLine = FastModel('sale.line', self.ctx)
|
||||
self.Product = FastModel('product.product', self.ctx)
|
||||
self.Journal = FastModel('account.statement.journal', self.ctx)
|
||||
self.Employee = FastModel('company.employee', self.ctx)
|
||||
self.Shop = FastModel('sale.delivery_party', self.ctx)
|
||||
self.SaleDiscont = FastModel('sale.discount', self.ctx)
|
||||
self.Device = FastModel('sale.device', self.ctx)
|
||||
self.Category = FastModel('product.category', self.ctx)
|
||||
self.PaymentTerm = FastModel('account.invoice.payment_term', self.ctx)
|
||||
self.Party = FastModel('party.party', self.ctx)
|
||||
self.DeliveryParty = FastModel('sale.delivery_party', self.ctx)
|
||||
self.Taxes = FastModel('account.tax', self.ctx)
|
||||
self.ActionReport = FastModel('ir.action.report', self.ctx)
|
||||
if self._commission_activated:
|
||||
self.Agent = FastModel('commission.agent', self.ctx)
|
||||
self.Comission = FastModel('commission', self.ctx)
|
||||
if self._sale_pos_restaurant:
|
||||
self.RestTables = FastModel('sale.shop.table', self.ctx)
|
||||
self.Consumer = FastModel('party.consumer', self.ctx)
|
||||
|
||||
self.device, = self.Device.find([
|
||||
('id', '=', self._user['sale_device']['id']),
|
||||
])
|
||||
|
||||
self.shop = self.device['shop']
|
||||
self.shop_taxes = self.shop['taxes']
|
||||
self.company = self.shop['company']
|
||||
self._journals = dict([(j['id'], j) for j in self.device['journals']])
|
||||
self.salesman_ids = [s['id'] for s in self.shop.get('salesmans', [])]
|
||||
|
||||
dom_salesman = [
|
||||
('company', '=', self.company['id']),
|
||||
]
|
||||
if self.salesman_ids:
|
||||
dom_salesman.append(('id', 'in', self.salesman_ids))
|
||||
self.employees = self.Employee.find(dom_salesman)
|
||||
|
||||
self.discounts = self.shop.get('discounts', [])
|
||||
self.delivery_man_table = self.shop.get('delivery_man', [])
|
||||
self.delivery_man = [d for d in self.delivery_man_table if d['active']]
|
||||
self._payment_terms = self.PaymentTerm.get_payment_term_pos()
|
||||
self.type_pos_user = self._context.get('type_pos_user')
|
||||
|
||||
if not self.type_pos_user:
|
||||
return 'user_without_permission'
|
||||
self.user_can_delete = self.type_pos_user in ('frontend_admin', 'cashier')
|
||||
|
||||
self.product_categories = self.device['shop']['product_categories']
|
||||
self.salesman_required = self.device['shop']['salesman_pos_required']
|
||||
|
||||
self.default_party = self.shop['party']
|
||||
if not self.default_party:
|
||||
return 'missing_party_configuration'
|
||||
|
||||
self.default_journal = self.device['journal']
|
||||
if not self.default_journal:
|
||||
return 'missing_journal_device'
|
||||
|
||||
self.default_payment_term = self.shop['payment_term']
|
||||
self._password_admin = self._config.get('password_admin_pos')
|
||||
self._password_force_assign = self._config.get('password_force_assign')
|
||||
|
||||
self._action_report, = self.ActionReport.find([
|
||||
('report_name', '=', 'account.invoice'),
|
||||
])
|
||||
if self._config['show_stock_pos'] in ('value', 'icon'):
|
||||
self.stock_context = {
|
||||
'stock_date_end': date.today(),
|
||||
'locations': [self.shop['warehouse']['id']],
|
||||
}
|
||||
if self._web_channel:
|
||||
self.Channel = FastModel('sale.web_channel', self.ctx)
|
||||
return True
|
||||
|
||||
def create_statusbar(self):
|
||||
values = OrderedDict([
|
||||
('stb_shop', {'name': self.tr('SHOP'), 'value': self.shop['name']}),
|
||||
('stb_device', {'name': self.tr('DEVICE'), 'value': self.device['name']}),
|
||||
('stb_database', {'name': self.tr('DATABASE'), 'value': self.database}),
|
||||
('stb_user', {'name': self.tr('USER'), 'value': self.user}),
|
||||
('stb_printer', {'name': self.tr('PRINTER'), 'value': self.printer_sale_name})
|
||||
])
|
||||
self.set_statusbar(values)
|
||||
|
||||
|
||||
class ClearUi(QThread):
|
||||
sigActionClear = pyqtSignal()
|
||||
state = None
|
||||
|
|
|
@ -6,10 +6,9 @@ import logging
|
|||
import base64
|
||||
from decimal import Decimal
|
||||
from datetime import datetime, timedelta, date
|
||||
|
||||
from collections import OrderedDict
|
||||
from PyQt5.QtCore import Qt, QDate
|
||||
from .tools import get_icon, to_float, to_numeric
|
||||
from collections import OrderedDict
|
||||
from PyQt5.QtWidgets import (
|
||||
QLabel, QHBoxLayout, QVBoxLayout, QWidget, QLineEdit
|
||||
)
|
||||
|
@ -21,7 +20,6 @@ from app.commons.image import Image
|
|||
from app.commons.table import TableView
|
||||
from app.commons.model import TableModel, TableModelEdit
|
||||
from app.commons.menu_buttons import MenuDash
|
||||
from .proxy import FastModel
|
||||
from .localdb import LocalStore
|
||||
from .reporting import Receipt
|
||||
from .buttonpad import Buttonpad, ButtonsFunction
|
||||
|
@ -107,14 +105,6 @@ class MainWindow(FrontWindow):
|
|||
('account_category', 'in', self.shop['product_categories'])
|
||||
)
|
||||
|
||||
def filter_cache(self, data, filter, target):
|
||||
res = []
|
||||
for d in data:
|
||||
for t in target:
|
||||
if t in d[filter]:
|
||||
res.append(d)
|
||||
return res
|
||||
|
||||
def set_cache_company(self):
|
||||
self.store = LocalStore()
|
||||
self.store.create_table_config()
|
||||
|
@ -176,150 +166,6 @@ class MainWindow(FrontWindow):
|
|||
if self._sale['id']:
|
||||
self.Sale.cancel_sale(self._sale['id'])
|
||||
|
||||
def resize_window_tablet_dev(self):
|
||||
self.resize(690, self.get_geometry()[1])
|
||||
|
||||
def load_modules(self):
|
||||
self._sale_pos_restaurant = None
|
||||
self.Module = FastModel('ir.module', self.ctx)
|
||||
self.Config = FastModel('sale.configuration', self.ctx)
|
||||
self._config, = self.Config.find([('id', '=', 1)])
|
||||
self.discount_method = self._config.get('discount_pos_method')
|
||||
|
||||
self._commission_activated = self.Module.find([
|
||||
('name', '=', 'commission'),
|
||||
('state', '=', 'activated'),
|
||||
])
|
||||
self._web_channel = self.Module.find([
|
||||
('name', '=', 'sale_web_channel'),
|
||||
('state', '=', 'activated'),
|
||||
])
|
||||
self._credit_limit_activated = self.Module.find([
|
||||
('name', '=', 'account_credit_limit'),
|
||||
('state', '=', 'activated'),
|
||||
])
|
||||
|
||||
_product = {
|
||||
'name': 'product.product',
|
||||
'fields': [
|
||||
'template.name', 'code', 'barcode', 'write_date',
|
||||
'description', 'template.sale_price_w_tax',
|
||||
'template.account_category'
|
||||
]
|
||||
}
|
||||
self.cache_local = self._config.get('cache_products_local')
|
||||
|
||||
if self._config['show_location_pos']:
|
||||
_product['fields'].append('location_')
|
||||
|
||||
if self._config['show_stock_pos'] in ('value', 'icon'):
|
||||
if self._config['show_stock_pos'] == 'value':
|
||||
_product['fields'].append('quantity')
|
||||
if self._config['show_brand']:
|
||||
_product['fields'].append('brand.name')
|
||||
|
||||
if self._config['encoded_sale_price']:
|
||||
_product['fields'].extend(['image', 'image_icon', 'encoded_sale_price'])
|
||||
|
||||
if self.enviroment == 'restaurant':
|
||||
self._sale_pos_restaurant = self.Module.find([
|
||||
('name', '=', 'sale_pos_frontend_rest'),
|
||||
('state', '=', 'activated'),
|
||||
])
|
||||
if self._sale_pos_restaurant:
|
||||
self.PartyConsumer = FastModel('party.consumer', self.ctx)
|
||||
if self._config['delivery_product']:
|
||||
self._delivery_product = 0
|
||||
|
||||
# if self._commission_activated:
|
||||
# _PosSale['fields'].extend(['agent', 'agent.party.name', 'commission'])
|
||||
|
||||
self.User = FastModel('res.user', self.ctx)
|
||||
self._user, = self.User.find([('login', '=', self.user)])
|
||||
|
||||
self.Company = FastModel('company.company', self.ctx)
|
||||
self._company, = self.Company.find([('id', '=', 1)])
|
||||
self.logo = self._company['logo']
|
||||
|
||||
if not self._user['sale_device']:
|
||||
return 'user_not_permissions_device'
|
||||
|
||||
self.ctx['user'] = self._user['id']
|
||||
|
||||
self.Sale = FastModel('sale.sale', self.ctx)
|
||||
self.SaleLine = FastModel('sale.line', self.ctx)
|
||||
self.Product = FastModel('product.product', self.ctx)
|
||||
self.Journal = FastModel('account.statement.journal', self.ctx)
|
||||
self.Employee = FastModel('company.employee', self.ctx)
|
||||
self.Shop = FastModel('sale.delivery_party', self.ctx)
|
||||
self.SaleDiscont = FastModel('sale.discount', self.ctx)
|
||||
self.Device = FastModel('sale.device', self.ctx)
|
||||
self.Category = FastModel('product.category', self.ctx)
|
||||
self.PaymentTerm = FastModel('account.invoice.payment_term', self.ctx)
|
||||
self.Party = FastModel('party.party', self.ctx)
|
||||
self.DeliveryParty = FastModel('sale.delivery_party', self.ctx)
|
||||
self.Taxes = FastModel('account.tax', self.ctx)
|
||||
self.ActionReport = FastModel('ir.action.report', self.ctx)
|
||||
if self._commission_activated:
|
||||
self.Agent = FastModel('commission.agent', self.ctx)
|
||||
self.Comission = FastModel('commission', self.ctx)
|
||||
if self._sale_pos_restaurant:
|
||||
self.RestTables = FastModel('sale.shop.table', self.ctx)
|
||||
self.Consumer = FastModel('party.consumer', self.ctx)
|
||||
|
||||
self.device, = self.Device.find([
|
||||
('id', '=', self._user['sale_device']['id']),
|
||||
])
|
||||
|
||||
self.shop = self.device['shop']
|
||||
self.shop_taxes = self.shop['taxes']
|
||||
self.company = self.shop['company']
|
||||
self._journals = dict([(j['id'], j) for j in self.device['journals']])
|
||||
self.salesman_ids = [s['id'] for s in self.shop['salesmans']] \
|
||||
if self.shop.get('salesmans') else []
|
||||
|
||||
dom_salesman = [
|
||||
('company', '=', self.company['id']),
|
||||
]
|
||||
if self.salesman_ids:
|
||||
dom_salesman.append(('id', 'in', self.salesman_ids))
|
||||
self.employees = self.Employee.find(dom_salesman)
|
||||
|
||||
self.discounts = self.shop['discounts'] if self.shop.get('discounts') else []
|
||||
self.delivery_man_table = self.shop['delivery_man'] if self.shop.get('delivery_man') else []
|
||||
self.delivery_man = [d for d in self.delivery_man_table if d['active']]
|
||||
self._payment_terms = self.PaymentTerm.get_payment_term_pos()
|
||||
self.type_pos_user = self._context.get('type_pos_user')
|
||||
|
||||
if not self.type_pos_user:
|
||||
return 'user_without_permission'
|
||||
self.user_can_delete = self.type_pos_user in ('frontend_admin', 'cashier')
|
||||
|
||||
self.product_categories = self.device['shop']['product_categories']
|
||||
self.salesman_required = self.device['shop']['salesman_pos_required']
|
||||
|
||||
self.default_party = self.shop['party']
|
||||
if not self.default_party:
|
||||
return 'missing_party_configuration'
|
||||
|
||||
self.default_journal = self.device['journal']
|
||||
if not self.default_journal:
|
||||
return 'missing_journal_device'
|
||||
|
||||
self.default_payment_term = self.shop['payment_term']
|
||||
self._password_admin = self._config.get('password_admin_pos')
|
||||
self._password_force_assign = self._config.get('password_force_assign')
|
||||
|
||||
self._action_report, = self.ActionReport.find([
|
||||
('report_name', '=', 'account.invoice'),
|
||||
])
|
||||
if self._config['show_stock_pos'] in ('value', 'icon'):
|
||||
self.stock_context = {
|
||||
'stock_date_end': date.today(),
|
||||
'locations': [self.shop['warehouse']['id']],
|
||||
}
|
||||
return True
|
||||
|
||||
def set_printing_context(self):
|
||||
# Printing invoice context
|
||||
if self.printer_sale_name:
|
||||
|
@ -405,7 +251,6 @@ class MainWindow(FrontWindow):
|
|||
|
||||
left_head = QHBoxLayout()
|
||||
left_invoice = QHBoxLayout()
|
||||
left_table = None
|
||||
|
||||
# LEFT HEAD COMPONENTS
|
||||
self.message_bar = MessageBar()
|
||||
|
@ -510,7 +355,6 @@ class MainWindow(FrontWindow):
|
|||
]
|
||||
|
||||
if self._web_channel:
|
||||
self.Channel = FastModel('sale.web_channel', self.ctx)
|
||||
self.channels = self.Channel.find([])
|
||||
|
||||
info_fields.append(
|
||||
|
@ -690,16 +534,6 @@ class MainWindow(FrontWindow):
|
|||
widget.setLayout(panels)
|
||||
self.setCentralWidget(widget)
|
||||
|
||||
def create_statusbar(self):
|
||||
values = OrderedDict([
|
||||
('stb_shop', {'name': self.tr('SHOP'), 'value': self.shop['name']}),
|
||||
('stb_device', {'name': self.tr('DEVICE'), 'value': self.device['name']}),
|
||||
('stb_database', {'name': self.tr('DATABASE'), 'value': self.database}),
|
||||
('stb_user', {'name': self.tr('USER'), 'value': self.user}),
|
||||
('stb_printer', {'name': self.tr('PRINTER'), 'value': self.printer_sale_name})
|
||||
])
|
||||
self.set_statusbar(values)
|
||||
|
||||
def button_plus_pressed(self):
|
||||
error = False
|
||||
if self._input_text == '' and self._amount_text == '0':
|
||||
|
@ -2799,7 +2633,6 @@ class MainWindow(FrontWindow):
|
|||
self.button_history_customer.setVisible(False)
|
||||
|
||||
def set_consumer(self):
|
||||
# self._consumer = {}
|
||||
self.row_field_phone.setText(self._consumer['phone'])
|
||||
self.row_field_consumer.setText(self._consumer['name'])
|
||||
self.row_field_address.setText(self._consumer['address'])
|
||||
|
|
Loading…
Reference in New Issue