def delete_action(self): if self.current_item: o_id = getattr( self.current_item, self.key_field) if o_id >= 0: # For some reason I have o_id = 0 somewhere... # mainlog.debug("About to delete {}".format(o_id)) try: if self.delete_object(o_id): self.current_item = None # Do this only if delete was successful ! self.in_save = True self._refresh_list() # The current filter might lead to a 0-length list # or we might delete the only item of the list # In that case, we clear the form. if self.list_view.model().rowCount() > 0: self.list_view.selectRow(0) else: self._populate_form(None) self.in_save = False except Exception as e: showErrorBox(_("There was an error while deleting"),str(e),e) return else: mainlog.error("The current object has no id => I can't delete it") else: showWarningBox(_("You have selected nothing for delete."),None) return
def _apply_filter(self, filter_text): mainlog.debug(u"_apply_filter : {}".format(filter_text)) parts = [] len_check = False if " " in filter_text.strip(): # More than one word in the filter => I assume it's the full # fledged filtering check = check_parse(filter_text) if check == True: parts = supply_order_service.find_parts_expression_filter( filter_text) len_check = True else: showErrorBox(_("Error in the filter !"), check, object_name="filter_is_wrong") elif filter_text: parts = supply_order_service.find_parts_filtered(filter_text) len_check = True else: parts = supply_order_service.find_recent_parts() len_check = False if len_check and len(parts) >= supply_order_service.MAX_RESULTS: showWarningBox( _("Too many results"), _("The query you've given brought back too many results. Only a part of them is displayed. Consider refining your query" )) self._fill_model(parts) self.search_results_view.setFocus(Qt.OtherFocusReason)
def edit_timetrack_no_ndx(self): ndx = self.table_view.currentIndex() if ndx.isValid() and ndx.column() >= 0 and ndx.row() >= 0: self.edit_timetrack(ndx) else: showWarningBox(_("Can't edit"), _("You must first select a day/person."))
def delete_filter_action_slot(self): try: fq_id = None if self.filter_name.currentIndex() >= 0: fq_id = self.filter_name.itemData(self.filter_name.currentIndex()) if not fq_id: showWarningBox(_("The filter you want to delete was never saved"),None,parent=self,object_name="no_need_to_delete_filter") return fq = dao.filters_dao.find_by_id(fq_id) if fq.owner_id != user_session.user_id: showWarningBox(_("You can't delete the filter because it doesn't belong to you."),None,parent=self,object_name="not_my_filter") return dao.filters_dao.delete_by_id(fq_id,user_session.user_id) self.filter_name.reload() self.filter_name.preselect(None) except Exception as e: mainlog.error("Can't delete fq_id = {}".format(fq_id)) showErrorBox(_("There was a problem while deleting the filter."),None,e,object_name="delete_filter_fatal") self.filter_name.reload() self.filter_name.preselect(None)
def orderCreate(self): if self.dao.customer_dao.number_of_customers() > 0: d = ChangeCustomerDialog(self) if d.exec_() and d.result() == QDialog.Accepted: edit_order_parts_widget = self._make_edit_order_parts_widget() edit_order_parts_widget.edit_new_order(d.customer_id) self.stack.add_panel(edit_order_parts_widget) self.order_overview_widget.refresh_panel() else: showWarningBox(_("No customer defined"), _("Before creating an order, you must first create a customer"))
def create_supply_order(self): if supplier_service.number_of_suppliers() > 0: d = ChooseSupplierDialog(self) if d.exec_() and d.result() == QDialog.Accepted: p = EditSupplyOrderPanel(None) p.supply_order_saved.connect(self.get_supply_order_overview_widget().refresh_action) self.stack.add_panel(p) p.edit_new(d.supplier) else: showWarningBox(_("No supplier defined"), _("Before creating an order, you must first create a supplier"))
def handle_delete_last_slip(parent): last_id = dao.delivery_slip_part_dao.find_last_slip_id() if last_id: d = DeleteLastDeliverySlipDialog(parent) d.set_last_id(last_id) d.exec_() return d.result() == QDialog.Accepted else: showWarningBox(_("No delivery slip to delete !"), _("There are no delivery slip to delete")) return False
def _populate_dto(self,dto): fq_query = self.super_filter_entry.text() if not fq_query or not fq_query.strip(): showWarningBox(_("The filter's query can't be empty"),None,parent=self,object_name="empty_filter_query") return False dto.owner_id = user_session.user_id dto.shared = self.share_filter.checkState() == Qt.Checked dto.query = fq_query dto.family = self._filter_family return True
def set_on_identifier(self, identifier): order_re = re.compile("^([0-9]+)$") # FIXME use common regex orde_part_re = re.compile("^([0-9]+)([A-Za-z]+)$") m2 = order_re.match(identifier.upper()) m = orde_part_re.match(identifier.upper()) if m: order_label = int(m.groups()[0]) part_label = m.groups()[1] order_part_id = session().query( OrderPart.order_part_id).join(Order).filter( Order.accounting_label == order_label).filter( OrderPart.label == part_label).scalar() if order_part_id: self.imputable_tasks = self.potential_imputable_operations_for_order_part( order_part_id) self._identifier = identifier.upper() else: # FIXME Or the order is not in production... Message not 100% clear showWarningBox( _("The order part {} does not exist !").format(identifier), "", None, "order_doesnt_exist") elif m2: order_label = int(m2.groups()[0]) mainlog.debug( "set_on_identifier, given accounting label : {}".format( order_label)) order_id = session().query(Order.order_id).filter( Order.accounting_label == order_label).scalar() if order_id: self.imputable_tasks = self.potential_imputable_task_for_order( order_label) self._identifier = identifier.upper() else: # FIXME Or the order is not in production... Message not 100% clear showWarningBox( _("The order {} does not exist !").format(identifier), "", None, "order_doesnt_exist") elif identifier.strip() == "": self.imputable_tasks = self.potential_imputable_task_for_operation_definition( ) self._identifier = "" session().commit()
def save_and_accept(self): super(EditConfigurationDialog, self).accept() configuration.font_select = self.font_select.isChecked() configuration.set_server_network_address( self.server_address.text().strip(), overwrite=True) configuration.save() showWarningBox( _("Restart needed"), _("The modifications you have requested needs a restart of the application to be applied. They will take effect when you restart the application." )) self.deleteLater()
def editTaskActionReports(self): if not user_session.has_any_roles(['TimeTrackModify']): return m = self.base_date.month ndx = self.table_view.currentIndex() if ndx.isValid() and ndx.column() >= 0 and ndx.row() >= 0: edit_date = date(self.base_date.year,m,ndx.column()) # +1 already in because of employee's names employee = self._table_model.data(self._table_model.index(ndx.row(),0),Qt.UserRole) # FIXME Use a delegate d = EditTaskActionReportsDialog(dao,self,edit_date) d.set_employee_date(employee, edit_date) d.exec_() if d.result() == QDialog.Accepted: self.refresh_action() d.deleteLater() else: showWarningBox(_("Can't edit"),_("You must first select a day/person."))
def handle_edit_delivery_slip(order_id,parent): """ Returns True if a delivery slip was actually produced. """ # We only allow reporting quantities on part where # an actual work was produced. order = dao.order_dao.find_by_id(order_id) parts_with_qty_left = list(filter(lambda p:p.tex2<p.qty and p.state not in (OrderPartStateType.aborted,OrderPartStateType.completed), order.parts)) parts_with_hours_done = list(filter(lambda p:p.total_hours>0, parts_with_qty_left)) session().commit() # mainlog.debug("handle_edit_delivery_slip : parts_with_qty_left:{}, parts_with_hours_done:{}".format( # len(parts_with_qty_left), len(parts_with_hours_done))) if not order.accounting_label: showWarningBox(_("Order has never been in production"), _("This order has never been in production, so there can't be units to report on it"), parent) return if not order.parts: showWarningBox(_("Empty order"), _("There's nothing to report on a delivery slip !"), parent) return if not parts_with_qty_left: showWarningBox(_("All parts completed"), _("All the parts of the order are already completed (either because one explictely marked them as completed/aborted or because the quantities out are equal to the planned quantities), making a delivery slip is not needed"), parent) return if not parts_with_hours_done: showWarningBox(_("No work done"), _("You're trying to create a delivery slip for parts of an order where no work was actually done.\nI'll let you do it although it doesn't make much sense."), parent) # if order.state in (OrderStatusType.preorder_definition, OrderStatusType.order_definition): # showWarningBox(_("Order not ready for production"), # _("You're trying to create a delivery slip for an order that is not yet in production. This is not possible"), parent) # return d = EditDeliverySlipDialog(parent) d.set_data(order_id) d.exec_() r = d.result() == QDialog.Accepted if r: print_delivery_slip(dao,d.slip_id) d.deleteLater() return r
def find_by_text(self,text): text = text.strip() try: too_many_results, res = dao.order_part_dao.find_ids_by_text(text.strip()) if too_many_results: showWarningBox(_("Too many results"),_("The query you've given brought back too many results. Only a part of them is displayed. Consider refining your query"),object_name="too_many_results") return dao.order_part_dao.find_by_ids(res) except DataException as de: if de.code == DataException.CRITERIA_IS_EMPTY: showErrorBox(_("Error in the filter !"), _("The filter can't be empty"),object_name="filter_is_empty") elif de.code == DataException.CRITERIA_IS_TOO_SHORT: showErrorBox(_("Error in the filter !"), _("The filter is too short"),object_name="filter_is_too_short") elif de.code == DataException.CRITERIA_IS_TOO_LONG: showErrorBox(_("Error in the filter !"), _("The filter is too long"),object_name="filter_is_too_long") return []
def _validate_identifier(self, text): if text and len(text) > 0: # If the user didn't enter anything in the cell # then we won't check anything. This is to handle # the case where one starts editing a cell and # then stop editing by clicking out of the table. # We look for order_parts, those are named like '1234A' t = dao.order_part_dao.find_by_full_id(text) t = dao.order_part_dao.find_by_ids(t) session().commit() mainlog.debug("With identifier {}, found order part {}".format( text, t)) if t: t = [part for part in t if part.accounting_part_label][0] if t: return t else: showWarningBox( _("Time reporting only on orders ready for production" ), "") return False else: # No part were found, so we look for an order # whose name is like '1234' (no X part) try: oid = int(text) t = dao.order_dao.find_by_accounting_label(oid, True) session().commit() except ValueError as ex: pass if t: if t.state == OrderStatusType.order_ready_for_production: return t else: showWarningBox( _("Time reporting only on orders ready for production" ), "") return False else: showWarningBox( _("The order or order part with number {} doesn't exist." ).format(text), "") return False else: return None
def all_systems_go(): global user_session,configuration,window, args mainlog.debug("all_systems_go() : init dao") dao.set_session(session()) mainlog.debug("all_systems_go() : call back") dao.set_callback_operational_error(database_operational_error) mainlog.debug("all_systems_go() : building mainwindow") window = MainWindow(dao) window.setMinimumSize(1024,768) splash.finish(window) mainlog.debug("all_systems_go() : login dialog") if not user_session.is_active(): # the configuration may have forced a user # Special case for demo from koi.datalayer.employee_mapping import Employee if 'koi-mes.net' in configuration.get("DownloadSite", "base_url") or args.demo: user_session.open( dao.employee_dao.authenticate( "roba", Employee.hash_password("roba"))) d = AboutDemoDialog(None) d.exec_() else: d = LoginDialog(window, user_session) d.exec_() # splash.repaint() # zzz = QWidget() # splash.finish(zzz) # splash.show() # splash.update() # from PySide.QtGui import QSound # snd = QSound(os.path.join(resource_dir,'logo_sound.wav')) # splash.timer.start(25) # splash.alpha = 255 # snd.play() if user_session.is_active(): # d = LoginDialog(window, user_session) # d.exec_() window.build() w = StatusWidget2(window, user_session.name) window.statusBar().addWidget(w,100000) window.statusBar().setSizeGripEnabled(False) _koi_base.set_main_window(window) window.module = IndicatorsModule() window.module.wire( _koi_base) # window.showMaximized() # If I maximize what happens to multiscreens ? window.showMaximized() # splash = SplashScreen(pixmap) if args.screenshots: make_screenshot() app.exec_() else: # User was no authorized showWarningBox(_("Not authorized"),_("You are not authorized to use this program. Please check with your system administrator.")) dao.close()
def make_delivery_slip(self): global dao t = self.controller_part.model # mainlog.debug(u"make_delivery_slip() {}".format(t.objects)) # Extract the quantities to get out from the order part table parts_ids_quantities = dict() info = u"" for i in range(t.rowCount()): qty = t.data( t.index(i,self.qty_out_column), Qt.UserRole) or 0 order_part = t.objects[i] mainlog.debug("Line {} qty = {}, order part={} ".format(i,qty, order_part is not None)) if order_part and qty > 0: if order_part.order_part_id not in parts_ids_quantities: parts_ids_quantities[order_part.order_part_id] = 0 parts_ids_quantities[order_part.order_part_id] += qty info = info + ("<li>" + _("For {} {}, quantity {}")\ + "</li>").format(t.data( t.index(i,0), Qt.UserRole), t.data( t.index(i,1), Qt.UserRole), qty) info = u"<ul>{}</ul>".format(info) mainlog.debug("edit_dialog : checking for missing quantities") if len(parts_ids_quantities) == 0: showWarningBox(_("You requested to create a new delivery slip. However, you didn't encode any quantities"),None,None,"quantity_missing") return False mainlog.debug("edit_dialog : checking for quantities") if self._check_for_quantities_too_big(): showErrorBox(_("One quantity is too big"), _("Pay attention ! On some parts, you gave a quantity out that will make the total quantity out bigger than what was ordered. You must either change the quantity out or change the planned quantity."),None,"quantityTooBig") return False if self._check_unpriced_part(): showWarningBox(_("Some of the parts you want to make a delivery slip for have a null sell price. This is not an error but you may want to double check that situation."),None,None,"unpriced_part") mainlog.debug("edit_dialog : confirmationBox to be opened order_id is {}".format(self.order_id)) if confirmationBox(u"<font color='red'><b>{}</b></font>".format(_("<b>You're about to make a new delivery slip. This can't be reversed, please confirm.\n Here are the quantities you're going to record")),info,"confirmDSCreation"): mainlog.debug("confirmationBox was OK") try: self.slip_id = dao.delivery_slip_part_dao.make_delivery_slip_for_order( self.order_id, parts_ids_quantities, datetime.now(), self.close_order_checkbox.checkState() == Qt.Checked) mainlog.debug("A delivery slip was created {}".format(self.slip_id)) return True except Exception as ex: showErrorBox(_("Error while creating the delivery slip"), _("The delivery slip was not created due to an unexpected error."),ex) return False