def popup(self, pos): from ui.ligne_edit import EditLigneViewWidget from ui.deleteview import DeleteViewWidget from data_helper import check_befor_update_data row = self.selectionModel().selection().indexes()[0].row() if (len(self.data) - 1) < row: return False menu = QMenu() editaction = menu.addAction("Modifier cette ligne") delaction = menu.addAction("Supprimer cette ligne") action = menu.exec_(self.mapToGlobal(pos)) report = Report.get(id=self.data[row][-1]) if action == editaction: try: self.parent.open_dialog(EditLigneViewWidget, modal=True, table_p=self, report=report) except IndexError: pass if action == delaction: list_error = check_befor_update_data(report) if list_error == []: if len(self.data) < 2: self.parent.cancellation() else: self.parent.open_dialog( DeleteViewWidget, modal=True, obj=report, table_p=self,) else: from Common.ui.util import raise_error raise_error(u"Impossible de supprimer", """<h3>L'article {} :</h3> Aura <b>{}</b> comme dernier restant.""".format( report.product.name, list_error[-1]))
def cancellation(self): buy = self.buy reports = Report.select().where(Report.buy == buy) list_error = [(check_befor_update_data(report)) for report in reports] if list_error == [] or list_error == [[]]: reply = QMessageBox.question( self, "Confirmation", "<h3 style='color:red;'>Voulez vous" " vraiment annuler ce rapport" " d'achat?</h3>", QMessageBox.Yes | QMessageBox.No, QMessageBox.No, ) if reply == QMessageBox.Yes: from ui.dashboard import DashbordViewWidget buy.deletes_data() self.change_main_context(DashbordViewWidget) else: QMessageBox.about( self, "Alerte", "<h3>Vous ne pousez pas supprimer ce rapport car:</h3>" "<ul><li></li>" " %(err)s" "<li>Après la suppression</li></ul>" % {"err": list_error}, )
def cancellation(self): buy = self.buy reports = Report.select().where(Report.buy == buy) rpt, remaining = check_befor_update_data(reports) if not rpt: reply = QMessageBox.question( self, 'Confirmation', u"<h3 style='color:red;'>Voulez vous" u" vraiment annuler ce rapport" u" d'achat?</h3>", QMessageBox.Yes | QMessageBox.No, QMessageBox.No) if reply == QMessageBox.Yes: buy.deletes_data() self.close() self.table_p.refresh_() else: QMessageBox.about( self, u"Alerte", u""" <h3>Vous ne pousez pas supprimer ce rapport car:</h3> <b>%(prod_name)s </b> aura comme restant : %(remaining)s Après la suppression</li></ul>""" % { "prod_name": rpt.product.name, "remaining": remaining })