Esempio n. 1
0
 def setData(self, index, value, role=QtCore.Qt.EditRole):
     if role == QtCore.Qt.EditRole:
         column = index.column()
         if column == self.getColIndex('id'):
             id  = forceRef(value)
             row = index.row()
             record = self._mapProbeId2Record[id]
             if id:
                 record.setValue('placeInTripod', QtCore.QVariant(row+1))
                 record.setValue('tripodNumber',  QtCore.QVariant(self._tripodNumber+1))
             self._items[row] = record
             self._mapTripodNumberToItems[self._tripodNumber][row] = record
             self.emitCellChanged(row, column)
             return True
     CRecordListModel.setData(self, index, value, role)
Esempio n. 2
0
    def setData(self, index, value, role=QtCore.Qt.EditRole):
        column = index.column()
        row = index.row()
        if role == QtCore.Qt.CheckStateRole and column == self.getColIndex(
                'checked'):
            record = self._items[row]
            actionTypeId = forceRef(record.value('actionType_id'))
            self.parentWidget.setSelected(actionTypeId,
                                          forceInt(value) == QtCore.Qt.Checked,
                                          resetMainModel=True)
            return False
        result = CRecordListModel.setData(self, index, value, role)

        col = self.cols()[column]
        fieldName = col.fieldName()

        if fieldName == 'finance_id':
            self.initContract(row)
            self.updatePricesAndSums(row, row)
        elif fieldName == 'contract_id':
            self.updatePricesAndSums(row, row)
        elif fieldName == 'amount':
            self.updatePricesAndSums(row, row)
            if self.isRowDpedBegDatePlusAmount(row):
                self.updatePlannedEndDate(row)
        elif fieldName == 'duration':
            self.updatePlannedEndDate(row)
        elif fieldName == 'begDate' and not self.isRowPlanEndDateEdited(row):
            self.updatePlannedEndDate(row)

        return result
Esempio n. 3
0
 def setData(self, index, value, role=QtCore.Qt.EditRole):
     if role == QtCore.Qt.CheckStateRole and forceBool(value):
         row = index.row()
         item = self._items[row]
         selectionGroup = forceInt(item.value('selectionGroup'))
         if selectionGroup > 1:
             groupItemList = self._cacheItemsByGroup.get(selectionGroup, [])
             for item in groupItemList:
                 item.setValue('checked', QtCore.QVariant(False))
             self.emitColumnChanged(self.getColIndex('checked'))
     return CRecordListModel.setData(self, index, value, role)
Esempio n. 4
0
 def setData(self, index, value, role=QtCore.Qt.EditRole):
     if role == QtCore.Qt.EditRole:
         id = forceRef(value)
         if not id:  # не добавляем пустую строку
             return False
         idlist = self.getIdList()
         if id in idlist:  # не добавляем повторы
             return False
         result = CRecordListModel.setData(self, index, value, role)
         if not result:
             return False
         # добавляем аналоги только что указанного
         idlist.append(id)
         db = QtGui.qApp.db
         table = db.table('rbNomenclature')
         newAnalogId = db.translate(table, 'id', value, 'analog_id')
         if newAnalogId:
             row = index.row() + 1
             for record in self.getAnalogies(idlist, newAnalogId):
                 self.insertRecord(row, record)
                 row += 1
         return True
     else:
         return CRecordListModel.setData(self, index, value, role)
Esempio n. 5
0
    def setData(self, index, value, role=Qt.EditRole):
        column = index.column()
        row = index.row()
        if role == Qt.EditRole:
            if row == len(self._items):
                if value.isNull():
                    return False

            if column == self.getColIndex('actionType_id'):
                db = QtGui.qApp.db
                actionTypeId = forceRef(value)

                for r in range(self.rowCount() - 1):
                    record = self._items[r]
                    otherActionTypeId = forceRef(record.value('actionType_id'))
                    otherActionExpireDate = forceDate(
                        record.value('expireDate'))
                    otherActionAmountLeft = forceDouble(
                        record.value('amount_left'))
                    otherPerson2Id = forceRef(record.value('person2_id'))
                    currentDate = QtCore.QDate.currentDate()
                    if actionTypeId == otherActionTypeId and currentDate <= otherActionExpireDate and otherActionAmountLeft > 0.0 and not otherPerson2Id:
                        person = forceString(
                            db.translate('vrbPerson', 'id',
                                         record.value('person_id'), 'name'))
                        date = forceString(record.value('setDate'))
                        currentActionTypeId = self._items[row].value(
                            'actionType_id')
                        actionCode = forceString(
                            db.translate('ActionType', 'id', actionTypeId,
                                         'code'))
                        actionName = forceString(
                            db.translate('ActionType', 'id', actionTypeId,
                                         'name'))
                        if currentActionTypeId != actionTypeId:
                            QtGui.QMessageBox.warning(
                                None,  #TODO: mdldml: неплохо бы получить виджет-предок, amirite?
                                u'Внимание!',
                                u'Услуга ' + actionCode + u'|' + actionName +
                                u' была рекомендована врачом ' + person +
                                u' и ' + date,
                                QtGui.QMessageBox.Close)
                        return False

                stmt = u'''
                    SELECT
                        Recommendation.setDate AS date,
                        vrbPerson.name AS person
                    FROM
                        Recommendation
                        INNER JOIN vrbPerson ON Recommendation.person_id = vrbPerson.id
                        INNER JOIN Event ON Recommendation.setEvent_id = Event.id
                        INNER JOIN ActionType ON Recommendation.actionType_id = ActionType.id
                    WHERE
                        Event.client_id = %s
                        AND Recommendation.deleted = 0
                        AND Recommendation.actionType_id = %s
                        AND Recommendation.amount_left > 0.0
                        AND Recommendation.person2_id IS NULL
                        AND DATE(NOW()) <= Recommendation.expireDate
                    LIMIT 1
                '''
                query = db.query(stmt % (self.clientId, forceString(value)))
                if query.next():
                    record = query.record()
                    person = forceString(record.value('person'))
                    date = forceString(record.value('date'))
                    currentActionTypeId = self._items[row].value(
                        'actionType_id') if row < len(self._items) else None
                    if currentActionTypeId != actionTypeId:
                        actionCode = forceString(
                            db.translate('ActionType', 'id', actionTypeId,
                                         'code'))
                        actionName = forceString(
                            db.translate('ActionType', 'id', actionTypeId,
                                         'name'))
                        QtGui.QMessageBox.warning(
                            None, u'Внимание!',
                            u'Услуга ' + actionCode + u'|' + actionName +
                            u' была рекомендована врачом ' + person + u' и ' +
                            date, QtGui.QMessageBox.Close)
                    return False

                if row == len(self._items):
                    self._items.append(self.getEmptyRecord(actionTypeId))
                    count = len(self._items)
                    rootIndex = QModelIndex()
                    self.beginInsertRows(rootIndex, count, count)
                    self.insertRows(count, 1, rootIndex)
                    self.endInsertRows()
                record = self._items[
                    row]  #todo: заменить на getEmptyRecord или проставить все изменившиеся поля, потому что amount и expirePeriod зависят от actionType_id
                col = self._cols[column]
                record.setValue(col.fieldName(), value)
                self.emitCellChanged(row, column)
                return True

            elif column == self.getColIndex('amount'):
                result = CRecordListModel.setData(self, index, value, role)
                if result:
                    record = self._items[row]
                    record.setValue('amount_left', record.value('amount'))
                return result

        return CRecordListModel.setData(self, index, value, role)