Beispiel #1
0
    def select_favorite_substitute(self, text):
        """
            Method used when cb_favorite_substitutes is activated
            Attributes :receive the Actual text in the combobox

            Select Database as source an retrieve :
            - category
            - product
            - substitute
            from the database.
            Set all combobox and table according to selected object
        """
        if len(self.favorite_substitutes) > 0:
            favorite_substitute = next(
                (x for x in self.favorite_substitutes if x.name == text), None)
            product, substitute = favorite_substitute.get_favorite(self.sql)

            if product is not None and substitute is not None:
                widgets.change_combobox_index_from_text(
                    self.ui.cb_source, "DataBase")
                self.select_source(self.ui.cb_source.currentText())

                category_name = Cat.get_name_from_id(self.sql,
                                                     product.id_category)
                widgets.change_combobox_index_from_text(
                    self.ui.cb_category, category_name)
                self.select_category()

                widgets.change_combobox_index_from_text(
                    self.ui.cb_product, product.name)
                self.select_product(product.name)

                widgets.change_combobox_index_from_text(
                    self.ui.cb_substitute, substitute.name)
                self.select_substitute(substitute.name)