def show_error_config_file_structure(exception): execute_critical_msg_box("Config Validation Error", ("There were errors in the structure of the " "config file. The file has been reset to " "defaults. The configuration wizard must now " "be run.\n\n{}").format(str(exception)), QMessageBox.Ok)
def _field_unique(self): '''Verify that the field is unique. Compares the field value to the values in the list of column data. If a duplicate value is found then a message box is used to display the error. Returns: :return: True if the field value is unique. False if the field value is not unique. :rtype: Boolean ''' is_unique = True for text_item in self.column_data: if text_item != self.default_text: if self.field_value == text_item: is_unique = False if not is_unique: execute_critical_msg_box( DATA_VAL_ERROR_MSG_BOX_TITLE, ("The {} you entered already exists. " "The {} field must be unique.").format( self.field_name, self.field_name), QMessageBox.Ok) return is_unique
def show_error_rows_with_zero_prices(field_name, row_numbers): '''Inform the user that there are rows with price data set to zero. Shows a message box indicating the rows that have price data set to zero. Args: :param field_name: The name of the field that has default values, e.g., "current price". :type field_name: String :param row_numbers: The row numbers where the error occurs. Note that these should correspond to row numbers that the user can see, i.e., the table row numbers as displayed in a QTableView. That means that the model row numbers should be incremented before passing to this function. :type row_numbers: List of integers ''' if len(row_numbers) == 0: raise ValueError("No row numbers were specified.") row_numbers_string = "Affected rows: " + str(row_numbers[0]) for row_number in row_numbers[1:]: row_numbers_string += ", " row_numbers_string += str(row_number) execute_critical_msg_box( DATA_VAL_ERROR_MSG_BOX_TITLE, ("The following rows contain {} fields set to zero. " "The {} must not be zero. This must be corrected " "before the table can be saved.\n\n{}").format( field_name, field_name, row_numbers_string), QMessageBox.Ok)
def _field_not_zero(self): '''Verify that the field is not equal to zero. Returns: :return: True if the field is not equal to zero. False if the field is equal to zero. :rtype: Boolean ''' if self.field_value == Decimal("0.0"): execute_critical_msg_box( DATA_VAL_ERROR_MSG_BOX_TITLE, "The {} must not be zero.".format(self.field_name), QMessageBox.Ok) return False return True
def _field_not_blank(self): '''Verify that the field is not blank. Checks if the field is composed only of white space. If it is then a message box is used to display the error. Returns: :return: True if the field is not blank. False if the field is blank. :rtype: Boolean ''' if self.field_value.isspace(): execute_critical_msg_box( DATA_VAL_ERROR_MSG_BOX_TITLE, "The {} must not be blank.".format(self.field_name), QMessageBox.Ok) return False return True
def on_goPushButton_clicked(self): if self._start_date > self._end_date: execute_critical_msg_box( DATA_VAL_ERROR_MSG_BOX_TITLE, "The start date cannot be after the end date.", QMessageBox.Ok) return if self.model: selection_model = self.tableView.selectionModel() del(selection_model) del(self.model) # Request to view the result of the configured report. if self._current_report == ReportModel.REPORT_TYPE_ITEMS_BY_PROJECT: self.model = ReportModel(self.app_config, self.session, self._current_report, self._project_description, self._start_date, self._end_date, parent=self) elif self._current_report == ReportModel.REPORT_TYPE_ITEMS_BY_SUPPLIER: self.model = ReportModel(self.app_config, self.session, self._current_report, self._supplier_company_name, self._start_date, self._end_date, parent=self) else: return if self.model: self.tableView.setModel(self.model) self.tableView.setEnabled(True) self.tableView.resizeColumnsToContents() self.tableView.horizontalHeader().setStretchLastSection(True) self.tableView.verticalHeader().setDefaultSectionSize(25) self.tableView.verticalHeader().setVisible(False) self.totalLabel.setEnabled(True) self.totalResultLabel.setEnabled(True) self.totalResultLabel.setText( "R {:,.2f}".format( self.model.calculate_total_value())) self.clearToolButton.setEnabled(True) self.exportToolButton.setEnabled(True)
def on_goPushButton_clicked(self): if self._start_date > self._end_date: execute_critical_msg_box( DATA_VAL_ERROR_MSG_BOX_TITLE, "The start date cannot be after the end date.", QMessageBox.Ok) return if self.model: selection_model = self.tableView.selectionModel() del (selection_model) del (self.model) # Request to view the result of the configured report. if self._current_report == ReportModel.REPORT_TYPE_ITEMS_BY_PROJECT: self.model = ReportModel(self.app_config, self.session, self._current_report, self._project_description, self._start_date, self._end_date, parent=self) elif self._current_report == ReportModel.REPORT_TYPE_ITEMS_BY_SUPPLIER: self.model = ReportModel(self.app_config, self.session, self._current_report, self._supplier_company_name, self._start_date, self._end_date, parent=self) else: return if self.model: self.tableView.setModel(self.model) self.tableView.setEnabled(True) self.tableView.resizeColumnsToContents() self.tableView.horizontalHeader().setStretchLastSection(True) self.tableView.verticalHeader().setDefaultSectionSize(25) self.tableView.verticalHeader().setVisible(False) self.totalLabel.setEnabled(True) self.totalResultLabel.setEnabled(True) self.totalResultLabel.setText("R {:,.2f}".format( self.model.calculate_total_value())) self.clearToolButton.setEnabled(True) self.exportToolButton.setEnabled(True)
def _field_not_default(self): '''Verify that the field is not equal to the default value. Compares the field to the default value. If the field equals the default value then a message box is used to display the error. Returns: :return: True if the field is not equal to the default value. False if the field is equal to the default value. :rtype: Boolean ''' if self.field_value == self.default_text: execute_critical_msg_box( DATA_VAL_ERROR_MSG_BOX_TITLE, ("The {} must not be left as the default text " "\"{}\".").format(self.field_name, self.default_text), QMessageBox.Ok) return False return True
def _field_within_limits(self): '''Verify that the field is within the specified range. Checks if the field value is greater than or equal to self.low_limit and less than self.high_limit. Returns: :return: True if the field is within the specified limits. False if the field is outside the specified limits. :rtype: Boolean ''' if self.field_value >= self.low_limit and \ self.field_value < self.high_limit: return True else: execute_critical_msg_box( DATA_VAL_ERROR_MSG_BOX_TITLE, ("The {} must be greater than or equal to {} " "and less than {}.").format(self.field_name, self.low_limit, self.high_limit), QMessageBox.Ok) return False
def on_exportToolButton_clicked(self): if self.active_po_model: pdf_filename = QFileDialog.getSaveFileName( self, caption="Save Purchase Order to PDF", filter="*.pdf") if pdf_filename == "": # The file name is empty, which probably means that the user # pressed Cancel in the file dialog. Just return. return # The file name is valid. # Create a reader to access the latest user config. user_config = UserConfigReader(self.session) company_details = PoPdfCompanyDetails( self.app_config.company.name, user_config.company.postal_address, user_config.company.phone_number, fax=user_config.company.fax_number, email=user_config.company.email_address, web=user_config.company.web_address, logo_filename=user_config.company.logo_filename) order_details = PoPdfOrderDetails( self.orderNumberLabel.text(), self.orderDateEdit.text(), self.paymentTermsComboBox.currentText()) supplier_details = PoPdfSupplierDetails( self.supplierComboBox.currentText(), self.supplierAddressLabel.text(), self.supplierPhoneLabel.text(), self.supplierFaxLabel.text(), self.supplierEmailLabel.text(), self.supplierContactLabel.text()) delivery_details = PoPdfDeliveryDetails( self.deliveryDateEdit.text(), self.deliveryAddressPlainTextEdit.\ document().toPlainText(), self.gpsCoordinatesLineEdit.text()) line_items = [] for row in range(self.active_po_model.line_item_model.\ rowCount() - 1): line_items.append(self.active_po_model.line_item_model.\ get_row(row)) line_item_details = PoPdfLineItemDetails( line_items, self.totalExcludingTaxResultLabel.text(), self.totalTaxResultLabel.text(), self.totalResultLabel.text(), self.app_config.locale.tax_name) signature_details = PoPdfSignatureDetails( user_config.company.signatory_name, user_config.company.signature_filename, draft=True) pdf_report = PoPdf(pdf_filename, company_details, order_details, supplier_details, delivery_details, line_item_details, self.notesPlainTextEdit.document().\ toPlainText(), signature_details, show_all_grids=False) # TODO: Wrap with try except, since will raise, e.g., # FileNotFoundError. try: pdf_report.build() except PermissionError as e: execute_critical_msg_box("Permission Error", ("Could not open the PDF file. Make " "sure that it is not open and the " "try again."), QMessageBox.Ok, info_text=str(e))
def show_error_no_config_file(): execute_critical_msg_box("Config Validation Error", ("A config file was not found. " "The configuration wizard must now be run."), QMessageBox.Ok)
def show_error_config_file_setting(): execute_critical_msg_box("Config Validation Error", ("There are errors in the config file. " "The configuration wizard must now be run."), QMessageBox.Ok)