コード例 #1
0
ファイル: add_book.py プロジェクト: raulvc/seareiros
 def submit_data(self):
     data = self.extract_input()
     # checking fields that aren't inserted yet
     for val, model in [
         ("author", self._author_model),
         ("s_author", self._s_author_model),
         ("publisher", self._publisher_model),
     ]:
         if isinstance(data[val], unicode):
             # needs to be inserted
             model.insertRow(0)
             model.setData(model.index(0, 1), data[val])
             data[val] = submit_and_get_id(self, model, self.log)
             if not data[val]:
                 # won't proceed if this fails
                 return False
     # filling a book row
     self._model.insertRow(0)
     for key, val in data.items():
         self._model.setData(self._model.index(0, self.column[key]), val)
     book_id = submit_and_get_id(self, self._model, self.log)
     if book_id:
         # for use in selection docks
         self.setBookId(book_id)
         # book sucessfully added, now associating related subjects
         subjects, new_subjects = self.extract_subjects_input()
         for subj in new_subjects:
             self._subject_model.insertRow(0)
             self._subject_model.setData(self._subject_model.index(0, 1), subj)
             id = submit_and_get_id(self, self._subject_model, self.log)
             if not id:
                 # issue saving new subject
                 return False
             subjects.append(int(id))
         # associating book and it's subjects
         error = False
         for subj_id in subjects:
             self._book_in_subj_model.insertRow(0)
             self._book_in_subj_model.setData(self._book_in_subj_model.index(0, 0), book_id)
             self._book_in_subj_model.setData(self._book_in_subj_model.index(0, 1), subj_id)
             ok = self._book_in_subj_model.submitAll()
             if not ok:
                 error = True
                 break
         if error:
             self.log.error(self._book_in_subj_model.lastError.text())
             message = unicode(
                 "Erro\n\n"
                 "Livro cadastrado, porém ocorreu um problema ao"
                 " salvar os temas a que está associado".decode("utf-8")
             )
             QMessageBox.warning(self, "Seareiros - Cadastro de Livro", message)
             return False
         else:
             message = unicode("Sucesso!\n\n" "O livro foi salvo com êxito no banco de dados".decode("utf-8"))
             QMessageBox.information(self, "Seareiros - Cadastro de Livro", message)
             return True
     # failed to insert a row
     return False
コード例 #2
0
ファイル: order_product.py プロジェクト: raulvc/seareiros
 def submit_data(self):
     # I should block empty orders I guess
     if len(self._product_list) == 0:
         message = unicode(
             "Venda vazia!\n\n" "" "É necessário adicionar um produto antes de concluir uma venda".decode("utf-8")
         )
         QMessageBox.critical(self, "Seareiros - Vendas do Bazar", message)
         self.edProductName.setFocus()
         return False
     data = self.extract_input()
     # filling a product order
     self._model.insertRow(0)
     for key, val in data.items():
         self._model.setData(self._model.index(0, self.column[key]), val)
     order_id = submit_and_get_id(self, self._model, self.log)
     if order_id:
         # order creation success, placing items
         error = False
         for item in self._product_list:
             product_name = item[0]
             product_price = item[1]
             product_quantity = item[2]
             self._items_model.insertRow(0)
             self._items_model.setData(self._items_model.index(0, 1), order_id)
             self._items_model.setData(self._items_model.index(0, 2), product_name)
             self._items_model.setData(self._items_model.index(0, 3), product_price)
             self._items_model.setData(self._items_model.index(0, 4), product_quantity)
             ok = self._items_model.submitAll()
             if not ok:
                 error = True
                 break
         if error:
             self.log.error(self._items_model.lastError().text())
             message = unicode(
                 "Erro\n\n"
                 "Venda registrada e contabilizada, porém ocorreu um problema e"
                 " não será possível visualizar seus itens.".decode("utf-8")
             )
             QMessageBox.warning(self, "Seareiros - Vendas do Bazar", message)
             return False
         else:
             # all went fine
             # retrieving some brief info of the order to display at the main window
             if "associate" in data:
                 desc = "Venda do bazar no valor de R$ %s para %s" % (
                     self._locale.toString(data["total"], "f", 2).replace(".", ""),
                     self.lblNickname.text(),
                 )
             else:
                 desc = "Venda do bazar no valor de R$ %s" % self._locale.toString(data["total"], "f", 2).replace(
                     ".", ""
                 )
             if not log_to_history(self._model.database(), "venda_bazar", order_id, desc):
                 self.log.error(self._model.lastError().text())
             message = unicode("Sucesso!\n\n" "Venda concluída.".decode("utf-8"))
             QMessageBox.information(self, "Seareiros - Vendas do Bazar", message)
             return True
     # failed to insert a row
     return False
コード例 #3
0
ファイル: order_book.py プロジェクト: raulvc/seareiros
 def submit_data(self):
     if len(self._book_list) == 0:
         message = unicode("Venda vazia!\n\n"""
                           "É necessário adicionar um livro antes de concluir uma venda".decode('utf-8'))
         QMessageBox.critical(self, "Seareiros - Livraria", message)
         self.edBarcode.setFocus()
         return False
     data = self.extract_input()
     # filling a book order
     self._model.insertRow(0)
     for key,val in data.items():
         self._model.setData(self._model.index(0, self.column[key]), val)
     order_id = submit_and_get_id(self, self._model, self.log)
     if order_id:
         # order creation success, placing items
         error = False
         for item in self._book_list:
             book_id = item[0]
             book_quantity = item[3]
             self._items_model.insertRow(0)
             self._items_model.setData(self._items_model.index(0,1), order_id)
             self._items_model.setData(self._items_model.index(0,2), book_id)
             self._items_model.setData(self._items_model.index(0,3), book_quantity)
             ok = self._items_model.submitAll()
             if not ok:
                 error = True
                 break
         if error:
             self.log.error(self._items_model.lastError().text())
             message = unicode("Erro\n\n""Venda registrada e contabilizada, porém ocorreu um problema e"
                           " não será possível visualizar seus itens.".decode('utf-8'))
             QMessageBox.warning(self, "Seareiros - Livraria", message)
             return False
         else:
             # all went fine
             # retrieving some brief info of the order to display at the main window
             if 'associate' in data:
                 desc = "Venda da livraria no valor de R$ %s para %s" % \
                        (self._locale.toString(data['total'], 'f', 2).replace('.',''), self.lblNickname.text())
             else:
                 desc = "Venda da livraria no valor de R$ %s" % self._locale.toString(data['total'], 'f', 2).replace('.','')
             if not log_to_history(self._model.database(), "venda_livraria", order_id, desc):
                 self.log.error(self._model.lastError().text())
             message = unicode("Sucesso!\n\n""Venda concluída.".decode('utf-8'))
             QMessageBox.information(self, "Seareiros - Livraria", message)
             return True
     # failed to insert a row
     return False
コード例 #4
0
ファイル: edit_book.py プロジェクト: raulvc/seareiros
    def update_data(self):
        data = self.extract_input()
        # checking fields that aren't inserted yet
        for val, model in [('author', self._author_model), ('s_author', self._s_author_model),
                           ('publisher', self._publisher_model)]:
            if isinstance(data[val], unicode):
                # needs to be inserted
                model.insertRow(0)
                model.setData(model.index(0,1), data[val])
                data[val] = submit_and_get_id(self, model, self.log)
                if not data[val]:
                    # won't proceed if this fails
                    return False
        for key,val in data.items():
            self._model.setData(self._model.index(0, self.column[key]), val)
        if 'image' not in data and self._image_changed:
            # user cleared the image
            ok = self._model.setData(self._model.index(0, self.column['image']), None)
            print ok

        # try to commit changes
        if not self._model.submitAll():
            self.log.error(self._model.lastError().text())
            message = unicode("Erro de transação\n\n""Não foi possível salvar no banco de dados".decode('utf-8'))
            QMessageBox.critical(self, "Seareiros - Edição de Livro", message)
            return False
        else:
            # updating subjects
            error = False
            # added subjects
            for subj in self._added_subjects:
                # the list has the format [id, text] for existing subjects or [None, text] otherwise
                if not subj[0]:
                    # need to insert the subject before associating it with the book
                    self._subject_model.insertRow(0)
                    self._subject_model.setData(self._subject_model.index(0,1), subj[1])
                    subj[0] = submit_and_get_id(self, self._subject_model, self.log)
                    if not subj[0]:
                        error = True
                        break
                # have a valid record id for the subject to be associated
                self._book_in_subj_model.insertRow(0)
                self._book_in_subj_model.setData(self._book_in_subj_model.index(0,0), self._record_id)
                self._book_in_subj_model.setData(self._book_in_subj_model.index(0,1), subj[0])
                ok = self._book_in_subj_model.submitAll()
                if not ok:
                    error = True
                    self.log.error(self._book_in_subj_model.setLastError().text())
                    break
            # removed subjects
            for removed_id in self._removed_subjects:
                self._book_in_subj_model.setFilter("book_id = %s AND subject_id = %s" % (str(self._record_id),str(removed_id)))
                self._book_in_subj_model.select()
                self._book_in_subj_model.removeRow(0)
                if self._book_in_subj_model.lastError().isValid():
                    error = True
                    self.log.error(self._book_in_subj_model.lastError().text())
                    break
            if not error:
                message = unicode("Sucesso!\n\n""O livro foi atualizado com êxito no banco de dados".decode('utf-8'))
                QMessageBox.information(self, unicode("Seareiros - Edição de Livro".decode('utf-8')), message)
            else:
                message = unicode("Erro\n\n""Associado alterado, "
                                  "porém ocorreu um problema ao salvar suas atividades".decode('utf-8'))
                QMessageBox.warning(self, unicode("Seareiros - Edição de Livro".decode('utf-8')), message)
            # if I don't set this flag here it'll trigger a warning for altering data on the form
            self._dirty = False
            return True