def fill_widgets(self, table_object, row):
        """ Fill input widgets with data int he @row """

        if table_object == "doc":

            utils_giswater.setWidgetText("doc_type", row["doc_type"])
            utils_giswater.setWidgetText("observ", row["observ"])
            utils_giswater.setWidgetText("path", row["path"])

        elif table_object == "element":

            state = ""
            if row['state']:
                sql = ("SELECT name FROM " + self.schema_name + ".value_state"
                       " WHERE id = '" + str(row['state']) + "'")
                row_aux = self.controller.get_row(sql, commit=self.autocommit)
                if row_aux:
                    state = row_aux[0]

            expl_id = ""
            if row['expl_id']:
                sql = ("SELECT name FROM " + self.schema_name + ".exploitation"
                       " WHERE expl_id = '" + str(row['expl_id']) + "'")
                row_aux = self.controller.get_row(sql, commit=self.autocommit)
                if row_aux:
                    expl_id = row_aux[0]

            utils_giswater.setWidgetText("state", state)
            utils_giswater.setWidgetText("expl_id", expl_id)
            utils_giswater.setWidgetText("elementcat_id", row['elementcat_id'])
            utils_giswater.setWidgetText("ownercat_id", row['ownercat_id'])
            utils_giswater.setWidgetText("location_type", row['location_type'])
            utils_giswater.setWidgetText("buildercat_id", row['buildercat_id'])
            utils_giswater.setWidgetText("workcat_id", row['workcat_id'])
            utils_giswater.setWidgetText("workcat_id_end",
                                         row['workcat_id_end'])
            utils_giswater.setWidgetText("comment", row['comment'])
            utils_giswater.setWidgetText("observ", row['observ'])
            utils_giswater.setWidgetText("link", row['link'])
            utils_giswater.setWidgetText("verified", row['verified'])
            utils_giswater.setWidgetText("rotation", row['rotation'])
            if str(row['undelete']) == 'True':
                self.dlg.undelete.setChecked(True)
            builtdate = QDate.fromString(str(row['builtdate']), 'yyyy-MM-dd')
            enddate = QDate.fromString(str(row['enddate']), 'yyyy-MM-dd')

            self.dlg.builtdate.setDate(builtdate)
            self.dlg.enddate.setDate(enddate)
Пример #2
0
    def fill_fields(self):
        """ Fill dates and combo cat_work """

        sql = (
            "SELECT value FROM " + self.controller.schema_name +
            ".config_param_user "
            " WHERE parameter = 'enddate_vdefault' and cur_user = current_user"
        )
        row = self.controller.get_row(sql, log_info=False)
        if row:
            enddate = QDate.fromString(row[0], 'yyyy-MM-dd')
        else:
            enddate = QDate.currentDate()
        utils_giswater.setCalendarDate(self.dlg_work_end, "enddate", enddate)

        sql = ("SELECT id FROM " + self.controller.schema_name + ".cat_work")
        rows = self.controller.get_rows(sql)
        utils_giswater.fillComboBox(self.dlg_work_end,
                                    self.dlg_work_end.workcat_id_end,
                                    rows,
                                    allow_nulls=False)
        utils_giswater.set_autocompleter(self.dlg_work_end.workcat_id_end)
        sql = (
            "SELECT value FROM " + self.controller.schema_name +
            ".config_param_user "
            " WHERE parameter = 'workcat_vdefault' and cur_user = current_user"
        )
        row = self.controller.get_row(sql, log_info=False)
        if row:
            utils_giswater.setWidgetText(self.dlg_work_end,
                                         self.dlg_work_end.workcat_id_end,
                                         row[0])
Пример #3
0
    def month_selector_row(self, dialog, id_table_left, tableleft, view_name):

        left_selected_list = dialog.all_rows.selectionModel().selectedRows()
        if len(left_selected_list) == 0:
            message = "Cap registre seleccionat"
            self.controller.show_warning(message)
            return

        # Get all selected ids
        field_list = []
        for i in range(0, len(left_selected_list)):
            row = left_selected_list[i].row()
            id_ = dialog.all_rows.model().record(row).value(id_table_left)
            field_list.append(id_)

        # Get dates
        plan_month_start = widget_manager.getCalendarDate(
            dialog, dialog.date_inici)
        plan_month_end = widget_manager.getCalendarDate(dialog, dialog.date_fi)

        # Get year from string
        calendar_year = QDate.fromString(plan_month_start, 'yyyy/MM/dd').year()

        # if int(calendar_year) < int(self.planned_camp_id):
        #     self.controller.show_details(detail_text="La data d'inici no pot ser anterior a 'Any planificacio'")
        #     return
        #
        # if plan_month_start > plan_month_end:
        #     self.controller.show_details(detail_text="La data d'inici no pot ser posterior a la data final")
        #     return

        # Update values
        for i in range(0, len(left_selected_list)):
            row = left_selected_list[i].row()
            sql = ("UPDATE " + self.schema_name + "." + tableleft + " "
                   " SET plan_code ='" + self.plan_code + "', "
                   " plan_month_start = '" + plan_month_start + "', "
                   " plan_month_end = '" + plan_month_end + "' "
                   " WHERE id='" +
                   str(dialog.all_rows.model().record(row).value('id')) + "'"
                   " AND mu_id ='" +
                   str(dialog.all_rows.model().record(row).value('mu_id')) +
                   "'"
                   " AND campaign_id = '" + self.planned_camp_id + "'")
            self.controller.execute_sql(sql)

        # Refresh QTableViews and recalculate price
        expr = " AND ( plan_code is NULL OR plan_code = '')"
        self.fill_table_planned_month(dialog.all_rows, dialog.txt_search,
                                      view_name, expr)
        expr = " AND plan_code = '" + self.plan_code + "'"
        self.fill_table_planned_month(dialog.selected_rows,
                                      dialog.txt_selected_filter, view_name,
                                      expr)
        self.calculate_total_price(dialog, self.planned_camp_id)
Пример #4
0
 def set_calendars(self, dialog, widget, table_name, value, parameter):
     """ Executes query and set QDateEdit """
     
     sql = ("SELECT " + value + " FROM " + self.schema_name + "." + table_name + ""
            " WHERE parameter = '" + parameter + "' AND cur_user = current_user")
     row = self.controller.get_row(sql)
     if row:
         date = QDate.fromString(row[0], 'yyyy-MM-dd')
     else:
         date = QDate.currentDate()
     utils_giswater.setCalendarDate(dialog, widget, date)
Пример #5
0
    def basic_new_prices(self, dialog=None):
        """ Button 03: Price generator """

        # Close previous dialog
        if dialog is not None:
            self.close_dialog(dialog)
        self.dlg_new_campaign = NewPrices()
        self.load_settings(self.dlg_new_campaign)

        # Set default dates
        current_year = QDate.currentDate().year()
        start_date = QDate.fromString(
            str(int(current_year)) + '/11/01', 'yyyy/MM/dd')
        self.dlg_new_campaign.start_date.setDate(start_date)
        end_date = QDate.fromString(
            str(int(current_year) + 1) + '/10/31', 'yyyy/MM/dd')
        self.dlg_new_campaign.end_date.setDate(end_date)

        table_name = 'cat_campaign'
        field_id = 'id'
        field_name = 'name'
        self.dlg_new_campaign.rejected.connect(
            partial(self.close_dialog, self.dlg_new_campaign))
        self.dlg_new_campaign.btn_cancel.clicked.connect(
            partial(self.close_dialog, self.dlg_new_campaign))
        self.dlg_new_campaign.btn_accept.clicked.connect(
            partial(self.manage_new_price_catalog))

        self.populate_cmb_years(table_name, field_id, field_name,
                                self.dlg_new_campaign.cbx_years)
        self.set_completer_object(table_name,
                                  self.dlg_new_campaign.txt_campaign,
                                  field_name)

        if self.rows_cmb_poda_type is None:
            self.update_cmb_poda_type()

        self.dlg_new_campaign.exec_()
def setCalendarDate(dialog, widget, date, default_current_date=True):
    if type(widget) is str or type(widget) is unicode:
        widget = dialog.findChild(QWidget, widget)
    if not widget:
        return
    if type(widget) is QDateEdit or (type(widget) is QgsDateTimeEdit and widget.displayFormat() == 'dd/MM/yyyy') \
            or (type(widget) is QgsDateTimeEdit and widget.displayFormat() == 'yyyy/MM/dd'):
        if date is None:
            if default_current_date:
                date = QDate.currentDate()
            else:
                date = QDate.fromString('01/01/2000', 'dd/MM/yyyy')
        widget.setDate(date)
    elif type(widget) is QDateTimeEdit \
            or (type(widget) is QgsDateTimeEdit and widget.displayFormat() == 'dd/MM/yyyy hh:mm:ss'):
        if date is None:
            date = QDateTime.currentDateTime()
        widget.setDateTime(date)
Пример #7
0
    def month_selector(self):

        month_selector = MonthSelector()

        self.load_settings(month_selector)
        month_selector.all_rows.setSelectionBehavior(
            QAbstractItemView.SelectRows)
        month_selector.selected_rows.setSelectionBehavior(
            QAbstractItemView.SelectRows)
        month_selector.setWindowTitle("Planificador mensual")

        # Set label with selected text from previus dialog
        month_selector.lbl_plan_code.setText(self.plan_code)
        month_selector.lbl_year.setText(self.planned_camp_name)

        sql = ("SELECT start_date, end_date FROM " + self.schema_name +
               ".cat_campaign "
               " WHERE id ='" + str(self.planned_camp_id) + "'")
        row = self.controller.get_row(sql)
        if row is not None:
            start_date = QDate.fromString(str(row[0]), 'yyyy-MM-dd')
            end_date = QDate.fromString(str(row[1]), 'yyyy-MM-dd')
        else:
            start_date = QDate.currentDate()
            end_date = QDate.currentDate().addYears(1)

        widget_manager.setCalendarDate(month_selector,
                                       month_selector.date_inici, start_date)
        widget_manager.setCalendarDate(month_selector, month_selector.date_fi,
                                       end_date)

        view_name = 'v_plan_mu_year'
        tableleft = 'planning'
        id_table_left = 'mu_id'

        # Left QTableView
        expr = " AND ( plan_code is NULL OR plan_code = '')"

        self.fill_table_planned_month(month_selector.all_rows,
                                      month_selector.txt_search, view_name,
                                      expr)
        month_selector.txt_search.textChanged.connect(
            partial(self.fill_table_planned_month, month_selector.all_rows,
                    month_selector.txt_search, view_name, expr,
                    QTableView.NoEditTriggers))
        month_selector.btn_select.clicked.connect(
            partial(self.month_selector_row, month_selector, id_table_left,
                    tableleft, view_name))
        self.set_table_columns(month_selector, month_selector.all_rows,
                               view_name, 'basic_month_left')

        # Right QTableView
        expr = " AND plan_code = '" + self.plan_code + "'"

        self.fill_table_planned_month(month_selector.selected_rows,
                                      month_selector.txt_selected_filter,
                                      view_name, expr)
        month_selector.txt_selected_filter.textChanged.connect(
            partial(self.fill_table_planned_month,
                    month_selector.selected_rows,
                    month_selector.txt_selected_filter, view_name, expr,
                    QTableView.NoEditTriggers))
        month_selector.btn_unselect.clicked.connect(
            partial(self.month_unselector_row, month_selector, id_table_left,
                    tableleft, view_name))
        self.set_table_columns(month_selector, month_selector.selected_rows,
                               view_name, 'basic_month_right')

        self.calculate_total_price(month_selector, self.planned_camp_id)

        month_selector.btn_close.clicked.connect(
            partial(self.close_dialog, month_selector))
        month_selector.rejected.connect(
            partial(self.close_dialog, month_selector))

        month_selector.exec_()