Beispiel #1
0
    def insert_subtraction_comps_into_db(self):
        comps_to_subtract = utils.get_line_items_contents(
            (self.comps_holder_section), as_dictionary=True
        )
        db = db_manager.DB_Manager()
        for comp_display, subtr_amount in comps_to_subtract.items():
            comp_sql = db.get_SQL_name_for_component(comp_display)
            stock_vald_pre_appl = db.get_stock_at_valdenegro_for(comp_sql)
            stock_vald_post_appl = stock_vald_pre_appl - subtr_amount
            self.final_dialog_data[comp_display] = [
                stock_vald_pre_appl,
                stock_vald_post_appl,
                subtr_amount,
            ]
            data_to_apply_subtraction = {
                "comp_sql": comp_sql,
                "subtr_amount": subtr_amount,
                "stock_vald_post_appl": stock_vald_post_appl,
            }
            db.apply_subtraction_to_valdenegro_only(data_to_apply_subtraction)
            settings = QtCore.QSettings("solutronic", "admin_stock")
            db.log_new_movement(
                movement="Egreso",
                destination="Uso interno",
                component=comp_display,
                amount=subtr_amount,
                user=settings.value("username"),
            )

        db.close_connection()
        self.close()
        SubtractionAppliedMessageBox(self).exec_()
Beispiel #2
0
 def test_if_there_are_duplicates(self):
     contents = utils.get_line_items_contents(self.comps_holder_section)
     duplicates = tests.test_if_duplicated_first_value_in_line_items_contents(
         contents)
     if duplicates:
         WarningBox("Componentes duplicados",
                    "Borrar uno de los componentes duplicados.").exec_()
         return True
     else:
         return False
 def test_if_there_are_no_products(self):
     no_line_items = not self.products_holder_section.children()
     contents = utils.get_line_items_contents(self.products_holder_section)
     empty_string = tests.test_if_empty_string_in_line_items_contents(contents)
     if no_line_items or empty_string:
         WarningBox(
             "Sin productos", "Completar o borrar campos\nvacíos antes de ejecutar."
         ).exec_()
         return True
     else:
         return False
Beispiel #4
0
    def test_if_there_are_recipe_data(self):
        contents = utils.get_line_items_contents(self.comps_holder_section)
        empty_strings_exist = tests.test_if_empty_string_in_line_items_contents(
            contents)

        if self.comps_holder_section.children() and empty_strings_exist:
            WarningBox(
                "Sin componentes",
                "Completar o borrar campos\nvacíos antes de ejecutar.",
            ).exec_()
            return True
        else:
            return False
Beispiel #5
0
 def test_if_there_are_unrecognized_components(self):
     contents = utils.get_line_items_contents(self.comps_holder_section)
     incoming_comps = contents[0::2]
     db = db_manager.DB_Manager()
     existing_comps = db.get_all_display_names_for_components()
     db.close_connection()
     unrecognized_comps = not set(incoming_comps).issubset(existing_comps)
     if unrecognized_comps:
         WarningBox(
             "Componente extraño",
             "Componente no reconocido. Cargar el\ncomponente desde el autocompletado.",
         ).exec_()
         return True
     else:
         return False
    def insert_edited_recipe_into_db(self):
        fields_contents = utils.get_line_items_contents(
            self.comps_holder_section)
        components = fields_contents[0::2]
        amounts = fields_contents[1::2]

        self.test_if_edited_recipe_is_equal_to_original()

        self.recipe_being_edited_contents = dict(zip(components, amounts))
        db = db_manager.DB_Manager()
        db.edit_recipe(self.recipe_being_edited_sql,
                       self.recipe_being_edited_contents)
        db.log_new_config_record(config="Edición de receta",
                                 details=self.recipe_being_edited_display)
        db.close_connection()

        admin_window = self.parent().parent().parent().parent()
        admin_window.statusbar.show_quick_message(
            "Receta guardada: " + self.recipe_being_edited_display)

        self.close()
        self.parent().close()
Beispiel #7
0
    def insert_new_recipe_into_db(self):
        recipe_being_created_display = (self.product_field.text() + "-" +
                                        self.model_field.text())
        recipe_being_created_sql = utils.format_display_name_into_sql_name(
            recipe_being_created_display)
        fields_contents = utils.get_line_items_contents(
            self.comps_holder_section)
        components = fields_contents[0::2]
        amounts = fields_contents[1::2]
        recipe_contents = dict(zip(components, amounts))

        db = db_manager.DB_Manager()
        db.create_recipe(recipe_being_created_sql)
        db.populate_recipe(recipe_being_created_sql, recipe_contents)
        db.log_new_config_record(config="Creación de receta",
                                 details=recipe_being_created_display)
        db.close_connection()

        admin_window = self.parent().parent().parent()
        admin_window.statusbar.show_quick_message("Receta creada: " +
                                                  recipe_being_created_display)

        self.close()
Beispiel #8
0
    def insert_incoming_comps_into_db(self):
        fields_contents = utils.get_line_items_contents(
            self.comps_holder_section)
        incoming_components = fields_contents[0::2]
        incoming_amounts = fields_contents[1::2]
        incoming_components_and_amounts_for_display = dict(
            zip(incoming_components, incoming_amounts))

        db = db_manager.DB_Manager()

        for k, v in incoming_components_and_amounts_for_display.items():
            self.incoming_comps_and_amounts_for_operation[
                db.get_SQL_name_for_component(
                    k)] = utils.format_number_for_calculation(v)

        for component_display in incoming_components_and_amounts_for_display.keys(
        ):
            for (
                    comp_sql,
                    amount,
            ) in self.incoming_comps_and_amounts_for_operation.items():
                stock_vald_pre_application = db.get_stock_at_valdenegro_for(
                    comp_sql)
                stock_vald_post_application = stock_vald_pre_application + amount
                self.data_for_final_dialog[component_display] = [
                    stock_vald_pre_application,
                    stock_vald_post_application,
                ]
                data = {
                    "comp_sql":
                    comp_sql,
                    "amount":
                    amount,
                    "packing_list":
                    self.packing_list_field.text(),
                    "supplier":
                    self.supplier_field.text(),
                    "note":
                    self.note_field.text()
                    if self.note_field.text() else "---",
                    "stock_vald_post_application":
                    stock_vald_post_application,
                    "stock_karina":
                    db.get_stock_at_assembler_for(comp_sql, "karina"),
                    "stock_brid":
                    db.get_stock_at_assembler_for(comp_sql, "brid"),
                    "stock_tercero":
                    db.get_stock_at_assembler_for(comp_sql, "tercero"),
                }
                db.apply_incoming_to_valdenegro(data)

        start_screen = self.parent().parent().parent().start_screen
        start_screen.rebuild_main_section()
        settings = QtCore.QSettings("solutronic", "admin_stock")
        for component, amount in incoming_components_and_amounts_for_display.items(
        ):
            db.log_new_movement(
                movement="Ingreso",
                destination="Depósito",
                component=component,
                amount=amount,
                user=settings.value("username"),
            )

        db.close_connection()
        IncomingAppliedMessageBox(self).exec_()
Beispiel #9
0
 def test_if_there_are_empty_main_fields(self):
     contents = utils.get_line_items_contents(self.comps_holder_section)
     if not all(contents):
         return self.autoremove_line()
     else:
         return False
    def preview_calculation(self):
        table = QtWidgets.QTableWidget()
        table.setFixedWidth(360)
        table.setEditTriggers(QtWidgets.QAbstractItemView.NoEditTriggers)
        table.verticalHeader().setVisible(False)
        table.setSelectionMode(QtWidgets.QAbstractItemView.NoSelection)
        table.setFocusPolicy(QtCore.Qt.NoFocus)
        table.setColumnCount(2)
        table.setHorizontalHeaderLabels(["Componente", "Necesidad"])
        table.horizontalHeaderItem(0).setTextAlignment(QtCore.Qt.AlignHCenter)
        table.horizontalHeaderItem(1).setTextAlignment(QtCore.Qt.AlignHCenter)
        table.horizontalHeader().setDefaultSectionSize(70)
        table.horizontalHeader().setSectionResizeMode(0, QtWidgets.QHeaderView.Stretch)
        table.horizontalHeader().setSectionResizeMode(1, QtWidgets.QHeaderView.Fixed)
        table_section = QtWidgets.QVBoxLayout()
        table_section.addWidget(table)

        self.layout.addLayout(table_section)

        self.add_button.setEnabled(False)

        utils.delete_layout(self.bottom_section)

        self.back_button = QtWidgets.QPushButton("« Volver")
        self.back_button.setShortcut("Alt+v")

        self.execute_button = QtWidgets.QPushButton("Calcular »")
        self.execute_button.setShortcut("Alt+c")

        self.bottom_section = QtWidgets.QHBoxLayout()
        self.bottom_section.addWidget(self.back_button)
        self.bottom_section.addWidget(self.execute_button)

        self.back_button.clicked.connect(self.close)
        self.add_button.clicked.connect(self.add_line_item)
        self.execute_button.clicked.connect(self.on_execute_clicked)

        self.layout.addLayout(self.bottom_section)

        self.entered_products_and_amounts = utils.get_line_items_contents(
            self.products_holder_section, as_dictionary=True
        )

        series_for_production = []

        db = db_manager.DB_Manager()

        for (
            product_to_be_manufactured,
            amount_to_be_manufactured,
        ) in self.entered_products_and_amounts.items():
            recipe_sql = utils.format_display_name_into_sql_name(
                product_to_be_manufactured
            )
            product_recipe = db.get_recipe_contents(recipe_sql)
            for comp_name, comp_amount in product_recipe.items():
                product_recipe[comp_name] = comp_amount * amount_to_be_manufactured

            series_for_production.append(product_recipe)

        db.close_connection()

        dd = defaultdict(list)

        for single_recipe in series_for_production:
            for component, amount in single_recipe.items():
                dd[component].append(amount)

        for key, value in dd.items():
            for _ in value:
                dd[key] = sum(value)

        self.needed_comps_and_amounts = dict(dd)

        table.setRowCount(len(self.needed_comps_and_amounts))

        utils.populate_table_column_with_list_of_strings(
            table=table, col_num=0, input_list=self.needed_comps_and_amounts.keys()
        )

        utils.populate_table_column_with_list_of_integers(
            table=table, col_num=1, input_list=self.needed_comps_and_amounts.values()
        )

        custom_height = table.rowCount() * 30 + 25
        if table.rowCount() <= 3:
            table.setMaximumHeight(custom_height)
            table.setFixedHeight(custom_height)
        elif table.rowCount() > 4:
            table.setMaximumHeight(205)
            table.setFixedHeight(205)

        self.execute_button.setText("Generar informe »")
        self.execute_button.setShortcut("Alt+g")

        self.code_field.setFocus()

        for l in self.products_holder_section.children():
            l.itemAt(0).widget().setDisabled(True)
            l.itemAt(1).widget().setDisabled(True)

        self.add_button.clicked.disconnect()