def setupDB(self, filename): try: databaseschema.setupDatabase(filename) self.filename = filename except NotImplementedError: QMessageBox.information(self, 'Log In - Open production file', 'Wrong file!!!', QMessageBox.Ok) return False except exc.ArgumentError: QMessageBox.information(self, '%s - Open database', 'Could not successfully open new database.', QMessageBox.Ok) return False db_version = functions.dLookup(databaseschema.Settings.value_1, databaseschema.Settings.setting == '__version__') if not db_version: QMessageBox.information(self, 'Open Database', 'v: %s, db: %s \n Wrong Database File, ' \ 'please contact administrator' % (__version__, db_version), QMessageBox.Ok) self.closeDB() return False elif db_version != __version__: progress = QProgressDialog('Updating File', 'Cancel', 0, 100) progress.setCancelButton(None) progress.show() progress.setValue(50) functions.updateDb(progress, __version__, db_version) return True else: return True
def showLogIn(self, filename): """ decide whether to whow the log in dialog based if there are users setup in the database.""" # // check if there is a filename to open the database, if not we are done if not filename: return # // now even if there is a filename we still need to check if that file exists # // otherwise sqlalchemy will just create a new database, and we like control try: with open(filename) : pass except: self.filename = None return # // if we are all happy, there is a filename and it exists, lets go ahead and connect to database. ok = self.setupDB(filename) if not ok: return # // now lets check if there are any users in the database, to decide whether we should show log in users = orm.Session().query(databaseschema.Users).count() if users < 1: self.setGoAhead(True) else: self.logIn() # // the log will give the go ahead if user id and password match # // no we want to setup the rest of the ui for the main window, # // provided we have a go ahead, and the ui has not yet been setup self.setWindowTitle('%s - (%s), (%s)' % (TITLE, ntpath.basename(self.filename), functions.dLookup(databaseschema.Users.user_name, databaseschema.Users.user_id==self.user_id))) if self.go_ahead and self.ui_setup: self.setupUi() self.ui_setup = False
def helpAbout(self): db_v = functions.dLookup(databaseschema.Settings.value_1, databaseschema.Settings.setting=='__version__') QMessageBox.about(self, "About Production Program", """<b>Production Program</b> v {0}, db_v {1} <p>Copyright © 2013 YF Consulting Inc. All rights reserved. <p>This application should be used to calculate Costs of manufactured products and for Bill of material Inventory Control. <p>Python {2} - Qt {3} - PyQt {4} - SQLAlchemy {5} on {6}""".format( __version__, db_v, platform.python_version(), QT_VERSION_STR, PYQT_VERSION_STR, sqlalchemy.__version__, platform.system()))
def reportSettings(self, report, parent=None): dialog = reports.ReportDialog(self.bomModel) from_date = self.from_date if self.from_date else QDate().currentDate() to_date = self.to_date if self.to_date else QDate().currentDate() dialog.from_date.setDate(from_date) dialog.to_date.setDate(to_date) bom_no = functions.dLookup(databaseschema.BOM.bom_no, databaseschema.BOM.bom_id==self.report_bomId) bom_index = dialog.bom_comboBox.findText(str(bom_no), Qt.MatchExactly) \ if self.report_bomId else -1 dialog.bom_comboBox.setCurrentIndex(bom_index) if dialog.exec_(): self.from_date = dialog.from_date.date().toPyDate() self.to_date = dialog.to_date.date().toPyDate() if dialog.range_comboBox.currentText() == 'All': self.from_date = None self.to_date = None bom_no = str(dialog.bom_comboBox.currentText()) self.report_bomId = functions.dLookup(databaseschema.BOM.bom_id, databaseschema.BOM.bom_no==bom_no) if parent: parent.refresh()
def setupUi(self): # setup Models self.supplierModel = modelsandviews.SupplierModel() self.bomModel = modelsandviews.ItemModel('BOM') self.itemModel = modelsandviews.ItemModel('Items') self.baseListModel = modelsandviews.BaseListModel() self.batchListModel = modelsandviews.BatchListModel() self.prepListModel = modelsandviews.PrepListModel() # prepare form variables self.home_form = None self.supplier_form = None self.item_form = None self.receive_form = None self.batch_form = None self.prodprep_form = None self.production_form = None self.inventoryAdj_form = None self.batchAdj_form = None self.findItem_form = None self.find_form = None self.settings_form = None # // prepare other variables self.from_date = QDate().currentDate().toPyDate() self.to_date = QDate().currentDate().toPyDate() self.report_bomId = None accounts = functions.dLookup(databaseschema.Settings.value_1, databaseschema.Settings.setting == 'export_accounts') accounts = accounts.split('|') self.ap_account = accounts[0].strip() self.ap_usAccount = accounts[1].strip() self.inv_account = accounts[2].strip() self.exp_class = accounts[3].strip() self.openWindowDock.show() self.openWindowDock.setObjectName('OpenWindowDock') self.openWindowDock.setAllowedAreas(Qt.LeftDockWidgetArea| Qt.RightDockWidgetArea) self.openWindowList = QListWidget() self.openWindowDock.setWidget(self.openWindowList) self.addDockWidget(Qt.LeftDockWidgetArea, self.openWindowDock) self.openWindowList.clicked.connect(self.dockWindow) importSupplierAction = self.createAction('Import Supplier List', self.importSupplier, None, ':/icons/import', 'Import supplier list from excel') importBOMAction = self.createAction('Import BOM List', self.importBOM, None, ':/icons/import', 'Import Bill Of Material list from excel') importBaseAction = self.createAction('Import Base', self.importBase, None, ':/icons/import', 'Import Bases from excel') importItemAction = self.createAction('Import Item List', self.importItem, None, ':/icons/import', 'Import item list from excel') importReceiveAction = self.createAction('Import Receive', self.importReceive, None, ':/icons/import', 'Import inventory receiving from excel') exportReceiveAction = self.createAction('Export IIF', self.exportReceive, None, ':/icons/export', 'Export receive reports to an IIF file.') setupUserAction = self.createAction('Setup User', self.userSetup, None, ':/icons/settings', 'Setup new user name and password') settingsAction = self.createAction('Preferences', self.settingsForm, None, ':/icons/settings', 'Settings and Tools') utilitiesMenu = self.fileMenu.addMenu('Utilities') self.addActions(utilitiesMenu, (importSupplierAction, importBOMAction, importBaseAction, importItemAction, importReceiveAction, None, exportReceiveAction, None, setupUserAction, settingsAction)) self.fileMenu.insertMenu(self.fileQuitAction, utilitiesMenu) self.fileMenu.insertSeparator(self.fileQuitAction) formHomeAction = self.createAction("Home", self.homeForm, 'Ctrl+H', ":/icons/home", "Go To Home") formSupplierAction = self.createAction("New Supplier", self.supplierForm, None, ":/icons/account", "Add New Supplier") formItemAction = self.createAction("New Item", self.itemForm, None, ":/icons/item", "Add New Item") formReceiveAction = self.createAction("Receive Inventory", self.receiveForm, None, ":/icons/inventory", "Receive Inventory") formProdprepAction = self.createAction('Prepare Production', self.prodprepForm, None, ":/icons/prep", "Prepare A Production") formBatchAction = self.createAction('Create Batch', self.batchForm, None, ':/icons/batch', 'Create A Batch') formBaseAction = self.createAction('Record Base', self.baseForm, None, ':/icons/batch', 'Record A New Base') formProduction = self.createAction('Production', self.productionForm, None, ':/icons/production', 'Record A Production') formInvAdjustment = self.createAction('Adjust Inventory', self.invAdjustment, None, ':/icons/journal', 'Adjust Inventory') formBatchAdjAction = self.createAction('Adjust Batch RM', self.batchAdjForm, None, ':/icons/settings', 'Adjust Raw Materials on a batch before production') formMenu = self.menuBar().addMenu("Form") self.addActions(formMenu, (formHomeAction, formSupplierAction, formItemAction, formReceiveAction, formProdprepAction, formBatchAction, formBaseAction, formProduction, formInvAdjustment, formBatchAdjAction)) findMenu = self.menuBar().addMenu('Find') findItemAction = self.createAction('Find Item', self.findItem, None, ':/icons/find', 'Find Item') findAction = self.createAction('&Find', self.findForm, 'Ctrl+F', ':/icons/search', 'Find Transaction') self.addActions(findMenu, (findItemAction, findAction)) reportInventorySumAction = self.createAction('Inventory Evaluation', self.inventorySumReport, None, ':/icons/report', 'Invenatory Report') reportInventoryDetailAction = self.createAction('Inventory Detail', self.inventoryDetReport, None, ':/icons/report', 'Inventory Detail Report') reportMenu = self.menuBar().addMenu('Reports') self.addActions(reportMenu, (reportInventorySumAction, reportInventoryDetailAction)) self.windowNextAction = self.createAction("&Next", self.mdi.activateNextWindow, QKeySequence.NextChild) self.windowPrevAction = self.createAction("&Previous", self.mdi.activatePreviousWindow, QKeySequence.PreviousChild) self.windowCascadeAction = self.createAction("Casca&de", self.mdi.cascade) self.windowTileAction = self.createAction("&Tile", self.mdi.tile) self.windowRestoreAction = self.createAction("&Restore All", self.windowRestoreAll) self.windowMinimizeAction = self.createAction("&Iconize All", self.windowMinimizeAll) self.windowArrangeIconsAction = self.createAction("&Arrange Icons", self.mdi.arrangeIcons) self.windowCloseAction = self.createAction("&Close", self.mdi.closeActiveWindow, QKeySequence.Close) self.showDockAction = self.createAction('Show Dock Window', self.showDockWindow) formToolBar = self.addToolBar('Forms Toolbar') formToolBar.setObjectName('FormToolBar') self.addActions(formToolBar, (formHomeAction, formSupplierAction, formItemAction, formReceiveAction, formProdprepAction, formBatchAction, formProduction, formBatchAdjAction, formInvAdjustment)) findToolBar = self.addToolBar('Find Toolbar') findToolBar.setObjectName('FindToolBar') self.addActions(findToolBar, (findItemAction, findAction)) self.windowMapper = QSignalMapper(self) self.connect(self.windowMapper, SIGNAL("mapped(QWidget*)"), self.mdi, SLOT("setActiveWindow(QWidget*)")) self.windowMenu = self.menuBar().addMenu("&Window") self.connect(self.windowMenu, SIGNAL("aboutToShow()"), self.updateWindowMenu) helpMenu = self.menuBar().addMenu('Help') aboutAction = self.createAction('&About Production Program', self.helpAbout) self.addActions(helpMenu, (aboutAction,)) self.homeForm() self.updateWindowMenu()