AddCustomer, AddContact finished
This commit is contained in:
@@ -34,6 +34,7 @@ class ConfigLoader(QObject):
|
|||||||
# print(f"In {__file__} file, __init__()")
|
# print(f"In {__file__} file, __init__()")
|
||||||
self.config_dir = user_config_dir() + '/pyqcrm'
|
self.config_dir = user_config_dir() + '/pyqcrm'
|
||||||
config_dir = Path(self.config_dir)
|
config_dir = Path(self.config_dir)
|
||||||
|
|
||||||
if config_dir.exists():
|
if config_dir.exists():
|
||||||
self.__configLoad()
|
self.__configLoad()
|
||||||
if self.__config:
|
if self.__config:
|
||||||
@@ -41,6 +42,7 @@ class ConfigLoader(QObject):
|
|||||||
else:
|
else:
|
||||||
config_dir.mkdir(0o750, True, True)
|
config_dir.mkdir(0o750, True, True)
|
||||||
|
|
||||||
|
|
||||||
@Slot(dict, result= bool)
|
@Slot(dict, result= bool)
|
||||||
def setConfig(self, app_config):
|
def setConfig(self, app_config):
|
||||||
# print(f"In {__file__} file, setConfig()")
|
# print(f"In {__file__} file, setConfig()")
|
||||||
@@ -212,3 +214,7 @@ class ConfigLoader(QObject):
|
|||||||
self.__config['pyqcrm']['ENCRYPTION_KEY'] = enc_key
|
self.__config['pyqcrm']['ENCRYPTION_KEY'] = enc_key
|
||||||
self.__saveConfig()
|
self.__saveConfig()
|
||||||
|
|
||||||
|
def getKey(self):
|
||||||
|
|
||||||
|
return self.__config['pyqcrm']['ENCRYPTION_KEY']
|
||||||
|
|
||||||
|
|||||||
@@ -8,14 +8,14 @@ class BusinessDAO:
|
|||||||
self.__con = DbManager().getConnection()
|
self.__con = DbManager().getConnection()
|
||||||
self.__cur = self.__con.cursor()
|
self.__cur = self.__con.cursor()
|
||||||
|
|
||||||
def getBusiness(self, criterion = "Alle"):
|
def getBusiness(self, key, criterion = "Alle"):
|
||||||
self.__cur.callproc("getCustomerView", (criterion,))
|
self.__cur.callproc("getCustomerView", (key, criterion,))
|
||||||
self.__all_cols = [desc[0] for desc in self.__cur.description]
|
self.__all_cols = [desc[0] for desc in self.__cur.description]
|
||||||
return self.__cur.fetchall(), self.__all_cols
|
return self.__cur.fetchall(), self.__all_cols
|
||||||
|
|
||||||
def addBusiness(self, data, contact_id):
|
def addBusiness(self, key, data, contact_id):
|
||||||
try:
|
try:
|
||||||
self.__cur.callproc("addBusiness", (json.dumps(data), contact_id))
|
self.__cur.callproc("addBusiness", (key, json.dumps(data), contact_id))
|
||||||
self.__con.commit()
|
self.__con.commit()
|
||||||
|
|
||||||
except mariadb.Error as e:
|
except mariadb.Error as e:
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
from PySide6.QtCore import QAbstractTableModel, QModelIndex, Qt, Slot, Signal
|
from PySide6.QtCore import QAbstractTableModel, QModelIndex, Qt, Slot, Signal
|
||||||
from .BusinessDAO import BusinessDAO
|
from .BusinessDAO import BusinessDAO
|
||||||
from ..PyqcrmFlags import PyqcrmFlags
|
from ..PyqcrmFlags import PyqcrmFlags
|
||||||
|
from ..ConfigLoader import ConfigLoader
|
||||||
|
|
||||||
# USERS TABLE
|
# USERS TABLE
|
||||||
# CUSTOMER_COLUMN_NAMES = \
|
# CUSTOMER_COLUMN_NAMES = \
|
||||||
@@ -66,11 +67,15 @@ class BusinessModel(QAbstractTableModel):
|
|||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
super().__init__()
|
super().__init__()
|
||||||
|
self.__key = ConfigLoader().getKey()
|
||||||
self.__getData()
|
self.__getData()
|
||||||
|
|
||||||
|
|
||||||
def __getData(self, criterion = "Alle"):
|
def __getData(self, criterion = "Alle"):
|
||||||
self.beginResetModel()
|
self.beginResetModel()
|
||||||
rows, self.__visible_columns = BusinessDAO().getBusiness(criterion)
|
rows, self.__visible_columns = BusinessDAO().getBusiness(self.__key, criterion)
|
||||||
|
|
||||||
|
print(rows)
|
||||||
self.__data = rows
|
self.__data = rows
|
||||||
self.endResetModel()
|
self.endResetModel()
|
||||||
|
|
||||||
@@ -78,17 +83,21 @@ class BusinessModel(QAbstractTableModel):
|
|||||||
return len (self.__data)
|
return len (self.__data)
|
||||||
|
|
||||||
def columnCount(self, parent= QModelIndex()):
|
def columnCount(self, parent= QModelIndex()):
|
||||||
return len(self.__visible_columns) - 1
|
#return len(self.__visible_columns) - 1
|
||||||
|
return len(self.__visible_columns)
|
||||||
|
|
||||||
|
|
||||||
def data(self, index, role= Qt.DisplayRole):
|
def data(self, index, role= Qt.DisplayRole):
|
||||||
if role == Qt.DisplayRole:
|
if role == Qt.DisplayRole:
|
||||||
row = self.__data[index.row()]
|
row = self.__data[index.row()]
|
||||||
return row[index.column() + 1]
|
#return row[index.column() + 1]
|
||||||
|
return row[index.column()]
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def headerData(self, section, orientation, role= Qt.DisplayRole):
|
def headerData(self, section, orientation, role= Qt.DisplayRole):
|
||||||
if orientation == Qt.Horizontal and role ==Qt.DisplayRole:
|
if orientation == Qt.Horizontal and role ==Qt.DisplayRole:
|
||||||
self.__col_name = self.__visible_columns[section + 1]
|
#self.__col_name = self.__visible_columns[section + 1]
|
||||||
|
self.__col_name = self.__visible_columns[section]
|
||||||
return self.__col_name
|
return self.__col_name
|
||||||
return super().headerData(section, orientation, role)
|
return super().headerData(section, orientation, role)
|
||||||
|
|
||||||
@@ -116,7 +125,7 @@ class BusinessModel(QAbstractTableModel):
|
|||||||
|
|
||||||
@Slot(dict, int)
|
@Slot(dict, int)
|
||||||
def addBusiness(self, business, contact_id):
|
def addBusiness(self, business, contact_id):
|
||||||
BusinessDAO().addBusiness(business, contact_id)
|
BusinessDAO().addBusiness(self.__key, business, contact_id)
|
||||||
self.__getData()
|
self.__getData()
|
||||||
|
|
||||||
@Slot(dict)
|
@Slot(dict)
|
||||||
|
|||||||
@@ -12,9 +12,9 @@ class ContactDAO:
|
|||||||
def getContacts(self):
|
def getContacts(self):
|
||||||
print(f"*** File: {__file__}, getContacts()")
|
print(f"*** File: {__file__}, getContacts()")
|
||||||
|
|
||||||
def addContact(self, contact):
|
def addContact(self, key, contact):
|
||||||
try:
|
try:
|
||||||
self.__cur.callproc("addContactPerson", (json.dumps(contact),))
|
self.__cur.callproc("addContactPerson", (key, json.dumps(contact),))
|
||||||
self.__con.commit()
|
self.__con.commit()
|
||||||
self.__cur.callproc("getLastInsertId")
|
self.__cur.callproc("getLastInsertId")
|
||||||
contact_id = self.__cur.fetchone()
|
contact_id = self.__cur.fetchone()
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
from PySide6.QtCore import QAbstractTableModel, QModelIndex, Qt, Slot, QObject, Signal
|
from PySide6.QtCore import QAbstractTableModel, QModelIndex, Qt, Slot, QObject, Signal
|
||||||
from .ContactDAO import ContactDAO
|
from .ContactDAO import ContactDAO
|
||||||
|
from ..ConfigLoader import ConfigLoader
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
class ContactModel(QObject):
|
class ContactModel(QObject):
|
||||||
@@ -7,6 +8,7 @@ class ContactModel(QObject):
|
|||||||
def __init__(self):
|
def __init__(self):
|
||||||
super().__init__()
|
super().__init__()
|
||||||
#self.logger = logging.getLogger()
|
#self.logger = logging.getLogger()
|
||||||
|
self.__key = ConfigLoader().getKey()
|
||||||
print(f"*** File: {__file__}, __init__()")
|
print(f"*** File: {__file__}, __init__()")
|
||||||
self.__data = self.__getData()
|
self.__data = self.__getData()
|
||||||
|
|
||||||
@@ -21,7 +23,9 @@ class ContactModel(QObject):
|
|||||||
|
|
||||||
@Slot(dict)
|
@Slot(dict)
|
||||||
def addContact(self, contact):
|
def addContact(self, contact):
|
||||||
i = ContactDAO().addContact(contact)
|
print(len(self.__key))
|
||||||
|
print(self.__key)
|
||||||
|
i = ContactDAO().addContact(self.__key, contact)
|
||||||
self.contactIdReady.emit(i)
|
self.contactIdReady.emit(i)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user