Exemple #1
0
    def addEventAction(self, eventId, actionTypeId, jobTicketId, date, idx, amount):
        def checkActionTypeIdByTissueType(actionTypeId):
            tissueTypeId = forceRef(self.takenTissueRecord.value('tissueType_id'))
            table = QtGui.qApp.db.table('ActionType_TissueType')
            cond = [table['master_id'].eq(actionTypeId),
                    table['tissueType_id'].eq(tissueTypeId)]
            return bool(QtGui.qApp.db.getRecordEx(table, 'id', cond))

        def setTicketIdToAction(action, jobTicketId):
            propertyTypeList = action.getType().getPropertiesById().values() if action else []
            for propertyType in propertyTypeList:
                if type(propertyType.valueType) == CJobTicketActionPropertyValueType:
                    property = action.getPropertyById(propertyType.id)
                    property.setValue(jobTicketId)
                    return True
            return False

        db = QtGui.qApp.db
        record = db.table('Action').newRecord()
        fillActionRecord(self, record, actionTypeId)
        action = CAction(record=record)
        if setTicketIdToAction(action, jobTicketId):
            #            record.setValue('directionDate', QVariant(date))
            record.setValue('setPerson_id', QtCore.QVariant(QtGui.qApp.userId))
            if not amount is None:
                record.setValue('amount', QtCore.QVariant(amount))
            if self.takenTissueRecord and checkActionTypeIdByTissueType(actionTypeId):
                record.setValue('takenTissueJournal_id', self.takenTissueRecord.value('id'))
            actionId = action.save(eventId, idx)
            self.actionIdListCanDeleted.append(actionId)

            self.mapActionIdToAction[actionId] = action
            return action
        return None
Exemple #2
0
def setProbeResultToActionProperties(tissueJournalId, testId, result):
    db = QtGui.qApp.db

    tableAction = db.table('Action')
    tableActionPropertyType = db.table('ActionPropertyType')

    queryTable = tableAction.innerJoin(
        tableActionPropertyType, tableActionPropertyType['actionType_id'].eq(
            tableAction['actionType_id']))

    cond = [
        tableAction['takenTissueJournal_id'].eq(tissueJournalId),
        tableActionPropertyType['test_id'].eq(testId)
    ]

    actionRecordList = db.getRecordList(queryTable, 'Action.*', cond)

    for actionRecord in actionRecordList:

        needSave = False

        action = CAction(record=actionRecord)

        actionType = action.getType()
        propertyTypeItemsList = actionType.getPropertiesById().items()
        for propertyTypeId, propertyType in propertyTypeItemsList:
            if propertyType.testId == testId:
                property = action.getPropertyById(propertyTypeId)
                if not propertyType.isVector:
                    property.setValue(
                        propertyType.convertQVariantToPyValue(result))
                    needSave = True

        if needSave:
            action.save(idx=forceInt(actionRecord.value('idx')))
Exemple #3
0
def getPlannedEndDateByJobTicketProperty(record):
    # план заполняется по номерку, a номерок может подбираться автоматом
    if record:
        action = CAction(record=record)
        actionType = action.getType()
        propertyTypeList = actionType.getPropertiesById().values()
        for propertyType in propertyTypeList:
            if type(propertyType.valueType
                    ) == CJobTicketActionPropertyValueType:
                property = action.getPropertyById(propertyType.id)
                jobTicketId = property.getValue()
                if jobTicketId:
                    db = QtGui.qApp.db
                    date = forceDate(
                        db.translate('Job_Ticket', 'id', jobTicketId,
                                     'datetime'))
                    jobId = forceRef(
                        db.translate('Job_Ticket', 'id', jobTicketId,
                                     'master_id'))
                    jobTypeId = forceRef(
                        db.translate('Job', 'id', jobId, 'jobType_id'))
                    ticketDuration = forceInt(
                        db.translate('rbJobType', 'id', jobTypeId,
                                     'ticketDuration'))
                    return date.addDays(ticketDuration)
        return None
Exemple #4
0
    def loadData(self, eventId):
        record = None
        db = QtGui.qApp.db
        tableAction = db.table('Action')

        propertyDefList = []
        for row in xrange(self.rowCount()):
            for column in xrange(self.columnCount()):
                propertyName = self.getPropertyName(row, column)
                if propertyName is not None:
                    propertyDefList.append({'name' : propertyName,
                                         'descr' : None,
                                         'unit' : None,
                                         'typeName' : 'String',
                                         'valueDomain' : None,
                                         'isVector' : False,
                                         'norm' : None,
                                         'sex' : None,
                                         'age' : None
                                         })

        actionTypeFlatCode = u'calfTeeth' if self._isCalf else u'permanentTeeth'
        ensureActionTypePresence(actionTypeFlatCode, propTypeList = propertyDefList, isUseFlatCode=True)
        actionType = CActionTypeCache.getByFlatCode(actionTypeFlatCode)
        if eventId:
            cond  = [tableAction['deleted'].eq(0),
                     tableAction['event_id'].eq(eventId),
                     tableAction['actionType_id'].eq(actionType.id)]

            record = db.getRecordEx(tableAction,
                                    '*',
                                    cond,
                                    order = 'idx')
        self._dentalNotationAction = CAction(record = record if record else None,
                                             actionType = actionType)
Exemple #5
0
 def __init__(self, context, actionId, action=None):
     db = QtGui.qApp.db
     if not action:
         record = db.getRecord('Action', '*', actionId)
         action = CAction(record=record)
     else:
         record = action.getRecord()
     CCookedActionInfo.__init__(self, context, record, action)
Exemple #6
0
 def __getitem__(self, key):
     v = self._items[key]
     if v is None:
         record = QtGui.qApp.db.getRecord('Action', '*', self.idList[key])
         action = CAction(record=record)
         v = self.getInstance(CCookedActionInfo, record, action)
         self._items[key] = v
     return v
Exemple #7
0
 def loadEvent(self, event_id):
     db = QtGui.qApp.db
     for rec in db.getRecordList('Action',
                                 where='event_id=%d AND deleted=0' %
                                 event_id):
         action = CAction(record=rec)
         action_type = action.getType()  # type: CActionType
         self._items[action_type.class_].append(action)
Exemple #8
0
    def loadItems(self, eventId):
        self._analysesGroups.clear()
        self._items = []

        db = QtGui.qApp.db
        tableAction = db.table('Action')
        tableAT = db.table('ActionType')

        table = tableAction.innerJoin(tableAT, [
            tableAT['id'].eq(tableAction['actionType_id']),
            tableAT['class'].eq(ActionClass.Analyses), tableAT['deleted'].eq(0)
        ])
        cols = [tableAction['id'], tableAction['parent_id']]
        cond = [
            tableAction['event_id'].eq(eventId), tableAction['deleted'].eq(0)
        ]

        idList = []
        childMap = DefaultOrderedDict(list)
        for record in db.iterRecordList(
                table,
                cols,
                cond,
                order=tableAction['idx'] if not self.orderByDirectionDate else
                tableAction['directionDate'].desc()):
            id = forceRef(record.value('id'))
            parentId = forceRef(record.value('parent_id'))
            idList.append(id)
            if parentId:
                childMap[parentId].append(id)

        recordMap = dict(
            (forceRef(rec.value('id')), rec) for rec in db.iterRecordList(
                tableAction, '*', tableAction['id'].inlist(idList)))

        for mainActionId, childrenIdList in childMap.iteritems():
            mainAction = CAction(record=recordMap[mainActionId])
            for actionId in childrenIdList:
                action = CAction(record=recordMap[actionId])
                self._analysesGroups[mainAction].append(action)

        self._recalcItems()
        self.reset()
Exemple #9
0
 def getChildren(self):
     db = QtGui.qApp.db
     tableAction = db.table('Action')
     actionId = forceRef(self._record.value('id'))
     return [
         self.getInstance(CCookedActionInfo, record, CAction(record=record))
         for record in db.iterRecordList(tableAction, '*', [
             tableAction['parent_id'].eq(actionId),
             tableAction['deleted'].eq(0)
         ])
     ]
Exemple #10
0
    def setActionId(self):
        if self.actionId:
            db = QtGui.qApp.db
            record = db.getRecord('Action', '*', self.actionId)
        else:
            record = None

        if record:
            self.setAction(CAction(record=record))
        else:
            self.setAction(None)
Exemple #11
0
    def loadItems(self, eventId):
        self._items = []
        db = QtGui.qApp.db
        tableAction = db.table('Action')
        tableEvent = db.table('Event')
        tableEventTypeAction = db.table('EventType_Action')
        tableActionType = db.table('ActionType')
        cond = [
            tableAction['deleted'].eq(0), tableAction['event_id'].eq(eventId)
        ]
        if self.actionTypeClass is not None:
            cond.append(tableAction['actionType_id'].inlist(
                self.actionTypeIdList))
        if self.ignoredActionTypesIdList:
            cond.append(tableAction['actionType_id'].notInlist(
                self.ignoredActionTypesIdList))
        actionTypeProtocolIdList = getActionTypeIdListByFlatCode(u'protocol%')
        if actionTypeProtocolIdList:
            cond.append(tableAction['actionType_id'].notInlist(
                actionTypeProtocolIdList))

        actionTypeIdList = []
        for record in db.iterRecordList(tableAction,
                                        '*',
                                        cond,
                                        order=['idx', 'id']):
            self.addItem((record, CAction(record=record)))
            actionTypeIdList.append(forceRef(record.value('actionType_id')))

        queryTable = tableEvent.innerJoin(
            tableEventTypeAction, tableEventTypeAction['eventType_id'].eq(
                tableEvent['eventType_id']))
        queryTable = queryTable.innerJoin(
            tableActionType,
            tableActionType['id'].eq(tableEventTypeAction['actionType_id']))
        notDeletedActionTypeRecordList = db.getRecordList(
            queryTable,
            cols=[
                tableActionType['id'], tableActionType['code'],
                tableActionType['name']
            ],
            where=[
                tableEvent['id'].eq(eventId),
                tableEventTypeAction['isCompulsory'].eq(1),
                tableActionType['id'].inlist(actionTypeIdList)
            ])
        for record in notDeletedActionTypeRecordList:
            self.notDeletedActionTypes[forceRef(
                record.value('id'))] = forceString(
                    record.value('code')) + '|' + forceString(
                        record.value('name'))
        self.reset()
Exemple #12
0
 def addRow(self,
            actionTypeId=None,
            amount=None,
            financeId=None,
            contractId=None,
            presetAction=None):
     if not presetAction:
         record = self.fillNewRecord(actionTypeId, amount, financeId,
                                     contractId)
         item = (record, CAction(record=record) if actionTypeId else None)
     else:
         record = presetAction.getRecord()
         item = (record, presetAction)
     if item[1]:
         item[1].initPropertyPresetValues()
     return self.insertItem(item)
Exemple #13
0
    def getHospitalDirectionNumberStr(self, eventId):
        numberStr = ''

        if self.hospitalDirectionActionTypeId:
            db=QtGui.qApp.db
            table = db.table('Action')
            record = db.getRecordEx(table, '*',
                u'event_id=\'%d\' AND actionType_id=\'%d\'' % (eventId, self.hospitalDirectionActionTypeId))

            if record:
                action = CAction()
                action.setRecord(record)
                property = action.getProperty(u'Номер направления')

                if property:
                    numberStr = property.getTextScalar()

        return numberStr
Exemple #14
0
    def setData(self,
                index,
                value,
                role=QtCore.Qt.EditRole,
                presetAction=None):
        if role == QtCore.Qt.EditRole:
            row = index.row()
            actionTypeId = forceRef(value)
            if actionTypeId and not (
                    self.checkMaxOccursLimit(actionTypeId)
                    and self.checkMovingNoLeaved(actionTypeId)
                    and self.checkMovingAfterReceived(actionTypeId)
                    and self.checkLeavedAfterMoving(actionTypeId)
                    and self.checkLeavedAfterMovingDate(actionTypeId)
                    and self.checkCompatibility(actionTypeId)
                    and self.checkPeriodicActionPosibility(actionTypeId)):
                return False
            if row == len(self._items):
                if actionTypeId is None:
                    return False
                self.addRow(presetAction=presetAction)
            if not presetAction:
                record = self._items[row][0]
                self.fillRecord(record, actionTypeId)
                action = None if actionTypeId is None else CAction(
                    record=record)
            else:
                record = presetAction.getRecord()
                action = presetAction
            setPerson = forceRef(record.value('setPerson_id'))
            execPerson = forceRef(record.value('person_id'))
            if not QtGui.qApp.userSpecialityId:
                if setPerson == QtGui.qApp.userId:
                    record.setValue('setPerson_id', toVariant(None))
                if execPerson == QtGui.qApp.userId:
                    record.setValue('person_id', toVariant(None))

            self._items[row] = (record, action)
            self.emitDataChanged(index)
            self.emitItemsCountChanged()
            return True
Exemple #15
0
    def loadClientDentitionHistory(self, clientId, setDate):
        self._dentitionHistoryItems = []
        self._resultDentitionHistoryItems.clear()
        self._clientId = clientId
        db = QtGui.qApp.db
        tableEvent = db.table('Event')
        tableAction = db.table('Action')
        tableActionType = db.table('ActionType')

        cond = [
            tableEvent['client_id'].eq(clientId), tableEvent['deleted'].eq(0),
            tableAction['deleted'].eq(0), tableActionType['flatCode'].inlist(
                [u'dentitionInspection', u'parodentInsp'])
        ]
        if setDate:
            cond.append(tableAction['begDate'].yearEq(setDate))

        queryTable = tableEvent.innerJoin(
            tableAction, tableAction['event_id'].eq(tableEvent['id']))
        queryTable = queryTable.innerJoin(
            tableActionType,
            tableActionType['id'].eq(tableAction['actionType_id']))
        # order  = tableAction['begDate'].name() + ' DESC' + ', ' + tableAction['event_id'].name() + ' DESC'
        order = [tableAction['id']]
        fields = 'Event.id AS eventId, ActionType.flatCode AS flatCode, Action.*'
        recordList = db.getRecordList(queryTable, fields, cond, order)
        for record in recordList:
            id = forceRef(record.value('id'))
            eventId = forceRef(record.value('eventId'))
            action = CAction(record=record)
            isChecked = 0
            self._resultDentitionHistoryItems[eventId] = (record, action, id,
                                                          eventId, isChecked)
            self._dentitionHistoryItems.append(
                (record, action, id, eventId, isChecked))
        if len(self._dentitionHistoryItems) > 0:
            self._dentitionHistoryItems.sort(
                key=lambda x: forceDate(x[0].value('begDate')))
            self._dentitionHistoryItems.reverse()
        self.reset()
Exemple #16
0
 def createAction(self):
     self.action = None
     if self.clientId:
         db = QtGui.qApp.db
         tableAction = db.table('Action')
         date = self.edtDate.date()
         time = self.edtTime.time()
         execPersonId = self.cmbExecPerson.value()
         if not execPersonId:
             execPersonId = QtGui.qApp.userId
             self.cmbExecPerson.setValue(execPersonId)
         dialogDateTime = QtCore.QDateTime(date, time)
         cond = [tableAction['deleted'].eq(0),
                 tableAction['event_id'].eq(self.eventId),
                 tableAction['actionType_id'].inlist(self.actionTypeIdList)
                 ]
         cond.append(tableAction['endDate'].eq(dialogDateTime))
         record = db.getRecordEx(tableAction, '*', cond)
         if record:
             execPersonId = forceRef(record.value('person_id'))
             if execPersonId:
                 self.cmbExecPerson.setValue(execPersonId)
             else:
                 self.cmbExecPerson.setValue(QtGui.qApp.userId)
             record.setValue('person_id', toVariant(execPersonId))
             self.action = CAction(record=record)
         else:
             actionTypeId = self.actionTypeIdList[0]
             if actionTypeId:
                 record = tableAction.newRecord()
                 record.setValue('event_id', toVariant(self.eventId))
                 record.setValue('actionType_id', toVariant(actionTypeId))
                 record.setValue('begDate', toVariant(dialogDateTime))
                 record.setValue('endDate', toVariant(dialogDateTime))
                 record.setValue('status',  toVariant(2))
                 record.setValue('person_id', toVariant(execPersonId))
                 record.setValue('org_id',  toVariant(QtGui.qApp.currentOrgId()))
                 record.setValue('amount',  toVariant(1))
                 self.action = CAction(record=record)
         if self.action:
             tableEvent = db.table('Event')
             prevSetDate = None
             prevEventId = None
             prevEventRecord = db.getRecordEx(tableEvent, [tableEvent['prevEvent_id'], tableEvent['setDate']], [tableEvent['id'].eq(self.eventId), tableEvent['deleted'].eq(0)])
             if prevEventRecord:
                 prevEventId = forceRef(prevEventRecord.value('prevEvent_id'))
                 prevSetDate = forceRef(prevEventRecord.value('setDate'))
             while prevEventId:
                 prevEventRecord = db.getRecordEx(tableEvent, [tableEvent['prevEvent_id'], tableEvent['setDate']], [tableEvent['id'].eq(prevEventId), tableEvent['deleted'].eq(0)])
                 if prevEventRecord:
                     prevEventId = forceRef(prevEventRecord.value('prevEvent_id'))
                     prevSetDate = forceRef(prevEventRecord.value('setDate'))
                 else:
                     prevEventId = None
             begDate = forceDate(record.value('begDate'))
             if (self.setDate and begDate) or (prevSetDate and begDate):
                 if prevSetDate:
                     self.action[u'День болезни'] = prevSetDate.daysTo(begDate) + 1
                 else:
                     self.action[u'День болезни'] = self.setDate.daysTo(begDate) + 1
             setActionPropertiesColumnVisible(self.action._actionType, self.tblAPProps)
             self.updatePropTable(self.action)
             self.tblAPProps.setEnabled(self.getIsLocked(self.action._record))
     self.isDirty = False
     return self.action
Exemple #17
0
    def add(self,
            actionTypeId,
            amount=None,
            necessity=None,
            parentActionRecord=None):
        db = QtGui.qApp.db
        row = len(self._items)
        record = self.getEmptyRecord(
            self.getPropertyTypeCellsSettings(actionTypeId, row))
        fillActionRecord(self.parentWidget.eventEditorOwner(), record,
                         actionTypeId)
        #Добавление типа финансирования по умолчанию, если он не заполнен на основе других данных
        if not forceRef(record.value('finance_id')) and self.defaultFinanceId:
            record.setValue('finance_id',
                            QtCore.QVariant(self.defaultFinanceId))

        contractId = forceRef(record.value('contract_id'))
        paymentScheme = self.parentWidget.getPaymentScheme()
        if paymentScheme:
            paymentSchemeItem = self.parentWidget.getPaymentSchemeItem()
            tableAT = db.table('ActionType')
            tableContract = db.table('Contract')
            tableContractTariff = db.table('Contract_Tariff')
            tablePSI = db.table('PaymentSchemeItem')
            tableService = db.table('rbService')

            queryTable = tableAT.innerJoin(
                tableService, tableService['code'].eq(tableAT['code']))
            queryTable = queryTable.innerJoin(
                tableContractTariff,
                tableContractTariff['service_id'].eq(tableService['id']))
            queryTable = queryTable.innerJoin(tableContract, [
                tableContract['id'].eq(tableContractTariff['master_id']),
                tableContract['deleted'].eq(0)
            ])
            queryTable = queryTable.innerJoin(
                tablePSI, tablePSI['contract_id'].eq(tableContract['id']))
            cond = [
                tableAT['id'].eq(actionTypeId),
                tablePSI['paymentScheme_id'].eq(paymentScheme),
                db.joinOr([
                    tablePSI['idx'].eq(paymentSchemeItem['idx']),
                    tablePSI['idx'].lt(0)
                ]) if paymentSchemeItem else tablePSI['idx'].lt(0)
            ]
            recordContract = db.getRecordEx(queryTable,
                                            tablePSI['contract_id'],
                                            cond,
                                            order=tablePSI['idx'])
            if recordContract:
                contractId = forceRef(recordContract.value('contract_id'))
            # record.setValue('contract_id', QtCore.QVariant(self.getContractId()))
        #Добавление контракта по умолчанию, если он не заполнен на основе других данных
        elif not forceRef(record.value(
                'contract_id')) and self.defaultContractFilterPart:
            contractModel = CContractDbModel(None)
            eventEditor = self.parentWidget.eventEditorOwner().eventEditor
            contractModel.setOrgId(eventEditor.orgId)
            contractModel.setClientInfo(eventEditor.clientId,
                                        eventEditor.clientSex,
                                        eventEditor.clientAge,
                                        eventEditor.clientWorkOrgId,
                                        eventEditor.clientPolicyInfoList)
            contractModel.setFinanceId(forceRef(record.value('finance_id')))
            contractModel.setActionTypeId(
                forceRef(record.value('actionType_id')))
            contractModel.setBegDate(
                forceDate(record.value('directionDate'))
                or QtCore.QDate.currentDate())
            contractModel.setEndDate(
                forceDate(record.value('endDate'))
                or QtCore.QDate.currentDate())
            contractModel.dbDataAvailable()
            availableIdList = contractModel.dbdata.idList
            tableContract = db.table('Contract')
            contractIdList = db.getIdList(
                tableContract,
                tableContract['id'], [
                    tableContract['id'].inlist(availableIdList),
                    self.defaultContractFilterPart
                ],
                limit=1)
            contractId = contractIdList[0] if contractIdList else None

        record.setValue('contract_id', QtCore.QVariant(contractId))
        record.setValue('checked', QtCore.QVariant(QtCore.Qt.Checked))
        record.setValue('price', QtCore.QVariant(self.getPrice(record)))

        if amount:
            record.setValue('amount', QtCore.QVariant(amount))

        if necessity:
            record.setValue('necessity', QtCore.QVariant(necessity))

        if parentActionRecord:
            fieldsToDerive = ['begDate', 'endDate', 'plannedEndDate', 'status']
            for field in fieldsToDerive:
                record.setValue(field, parentActionRecord.value(field))
            record.setValue('parent_id', toVariant(1))  # fix it

        self.insertRecord(row, record)
        self._idToAction[actionTypeId] = CAction(record=record)
        self._idToRow[actionTypeId] = row
        self.prices.append(0.0)
        if not self.isRowPlanEndDateEdited(row):
            self.updatePlannedEndDate(row)
        self.emitPricesAndSumsUpdated()

        setPerson = forceRef(record.value('setPerson_id'))
        execPerson = forceRef(record.value('person_id'))
        if not QtGui.qApp.userSpecialityId:
            if setPerson == QtGui.qApp.userId:
                record.setValue('setPerson_id', toVariant(None))
            if execPerson == QtGui.qApp.userId:
                record.setValue('person_id', toVariant(None))

        return record
Exemple #18
0
 def newAction(self, actionTypeId):
     record = self.fillNewRecord(actionTypeId)
     return CAction(record=record)
Exemple #19
0
 def setRecord(self, record):
     action = CAction(record=record)
     self._initByAction(action)
Exemple #20
0
 def setRecordByNext(self, record):
     oldAction = self.action
     newAction = CAction(record=record)
     CAction.copyAction(oldAction, newAction, isCopyRecordData=False)
     self.setAction(newAction)
Exemple #21
0
 def on_btnNextAction_clicked(self):
     if self.cmbStatus.currentIndex() == 3:
         currentDateTime = QtCore.QDateTime.currentDateTime()
         db = QtGui.qApp.db
         table = db.table('vrbPersonWithSpeciality')
         personId = QtGui.qApp.userId if (
         QtGui.qApp.userId and QtGui.qApp.userSpecialityId) else self.cmbSetPerson.value()
         record = db.getRecordEx(table, [table['name']], [table['id'].eq(personId)]) if personId else None
         personName = forceString(record.value('name')) if record else ''
         self.edtNote.setText('Отменить: %s %s' % (currentDateTime.toString('dd-MM-yyyy hh:mm'), personName))
     else:
         self.newActionId = None
         prevRecord = self.getRecord()
         if prevRecord:
             actionTypeId = forceRef(prevRecord.value('actionType_id')) if prevRecord else None
             duration = self.edtDuration.value()
             aliquoticity = self.edtAliquoticity.value()
             if duration >= 1 or aliquoticity > 1:
                 recordList = {}
                 periodicity = self.edtPeriodicity.value()
                 if aliquoticity and actionTypeId:
                     db = QtGui.qApp.db
                     tableAction = db.table('Action')
                     eventId = forceRef(prevRecord.value('event_id'))
                     actionId = forceRef(prevRecord.value('id'))
                     directionDate = forceDateTime(prevRecord.value('directionDate'))
                     setPersonId = forceRef(prevRecord.value('setPerson_id'))
                     if eventId:
                         cond = [
                             tableAction['deleted'].eq(0),
                             tableAction['actionType_id'].eq(actionTypeId),
                             tableAction['event_id'].eq(eventId),
                             tableAction['directionDate'].eq(directionDate),
                             tableAction['setPerson_id'].eq(setPersonId)
                         ]
                         for recordOld in db.iterRecordList(
                                 tableAction, tableAction['*'], cond, tableAction['begDate']
                         ):
                             id = forceRef(recordOld.value('id'))
                             begDateOld = forceDateTime(recordOld.value('begDate'))
                             recordList[(id, begDateOld)] = recordOld
                         keysList = recordList.keys()
                         keysList.sort()
                         keyList = keysList[-1]
                         quoticity = 0
                         if aliquoticity > 1:
                             for key in recordList.keys():
                                 if key[1].date() == keyList[1].date():
                                     quoticity += 1
                         if duration >= 1 or (aliquoticity > 1 and aliquoticity > quoticity):
                             lastRecord = recordList.get(keyList, None)
                             newRecordAction = False
                             if lastRecord:
                                 prevActionId = forceRef(lastRecord.value('id'))
                                 if actionId == prevActionId:
                                     begDate = forceDateTime(prevRecord.value('begDate'))
                                     if QtGui.qApp.userId and QtGui.qApp.userSpecialityId:
                                         execPersonId = QtGui.qApp.userId
                                     else:
                                         execPersonId = self.cmbSetPerson.value()
                                     dialog = CExecTimeNextActionDialog(self, begDate, execPersonId)
                                     if dialog.exec_():
                                         execTime = dialog.getExecTime()
                                         execPersonId = dialog.getExecPersonId()
                                         specifiedName = forceString(prevRecord.value('specifiedName'))
                                         prevRecord.setValue('person_id', toVariant(execPersonId))
                                         executionPlan = self.action.getExecutionPlan()
                                         executionPlanKeys = executionPlan.keys()
                                         executionPlanKeys.sort()
                                         executionPlanBegDate = executionPlan.get(pyDate(begDate.date()), {})
                                         if not executionPlanBegDate:
                                             for keyDate in executionPlanKeys:
                                                 executionPlanTimes = executionPlan.get(keyDate, {})
                                                 aliquoticityNew = len(executionPlanTimes)
                                                 if aliquoticityNew:
                                                     executionPlanTimeKeys = executionPlanTimes.keys()
                                                     executionPlanTimeKeys.sort()
                                                     aliquoticity = aliquoticityNew
                                                     begDateDate = begDate.date()
                                                     durationNew = duration - begDateDate.daysTo(
                                                         QtCore.QDate(keyDate))
                                                     duration = durationNew
                                                     begDate = QtCore.QDateTime(QtCore.QDate(keyDate),
                                                                                executionPlanTimeKeys[0])
                                                     break
                                         else:
                                             executionPlanBegDateKeys = executionPlanBegDate.keys()
                                             executionPlanBegDateKeys.sort()
                                             begTime = executionPlanBegDateKeys[0]
                                             executionPlanKeys = executionPlan.keys()
                                             executionPlanKeys.sort()
                                             if QtCore.QDate(executionPlanKeys[0]) == begDate.date():
                                                 aliquoticity = len(executionPlanBegDateKeys)
                                                 newBegDate = begDate.date().addDays(1)
                                                 maxBegDate = executionPlanKeys[len(executionPlanKeys) - 1]
                                                 while newBegDate <= maxBegDate:
                                                     periodicityPlanTimes = executionPlan.get(pyDate(newBegDate), {})
                                                     if len(periodicityPlanTimes):
                                                         periodicity = begDate.date().daysTo(newBegDate) - 1
                                                         break
                                                     else:
                                                         newBegDate = newBegDate.addDays(1)
                                                 if periodicity < 0:
                                                     periodicity = 0
                                             begDate = QtCore.QDateTime(begDate.date(), begTime)
                                         prevRecord.setValue('aliquoticity', toVariant(aliquoticity))
                                         prevRecord.setValue('begDate', toVariant(begDate))
                                         prevRecord.setValue('endDate',
                                                             toVariant(QtCore.QDateTime(begDate.date(), execTime)))
                                         prevRecord.setValue('status', toVariant(2))
                                         prevRecord.setValue('plannedEndDate',
                                                             toVariant(begDate.addDays(duration - 1)))
                                         prevRecord.setValue('duration', toVariant(duration))
                                         endDate = forceDateTime(prevRecord.value('endDate'))
                                         newExecutionPlan = {}
                                         tableActionExecutionPlan = db.table('Action_ExecutionPlan')
                                         for execDate, timeList in executionPlan.items():
                                             timeListDict = {}
                                             for execTime, record in timeList.items():
                                                 if QtCore.QDateTime(QtCore.QDate(execDate), execTime) > begDate:
                                                     newExecPlanRecord = tableActionExecutionPlan.newRecord()
                                                     newExecPlanRecord.setValue('execDate',
                                                                                toVariant(record.value('execDate')))
                                                     newExecPlanRecord.setValue('master_id', toVariant(None))
                                                     newExecPlanRecord.setValue('id', toVariant(None))
                                                     timeListDict[execTime] = newExecPlanRecord
                                             if timeListDict or QtCore.QDate(execDate) > begDate.date():
                                                 newExecutionPlan[execDate] = timeListDict
                                         begDateNew = None
                                         periodicityNew = -1
                                         if newExecutionPlan:
                                             newExecutionPlanKeys = newExecutionPlan.keys()
                                             newExecutionPlanKeys.sort()
                                             newExecTimeList = {}
                                             newExecDate = None
                                             for planKey in newExecutionPlanKeys:
                                                 newExecTimeList = newExecutionPlan.get(planKey, {})
                                                 if newExecTimeList:
                                                     newExecDate = planKey
                                                     break
                                             if newExecTimeList and newExecDate:
                                                 newExecTimeListKeys = newExecTimeList.keys()
                                                 if len(newExecTimeListKeys) > 0:
                                                     newExecTimeListKeys.sort()
                                                     newExecTime = newExecTimeListKeys[0]
                                                     begDateNew = QtCore.QDateTime(QtCore.QDate(newExecDate),
                                                                                   newExecTime)
                                                     aliquoticity = len(newExecTimeListKeys)
                                                     begDateDate = begDate.date()
                                                     periodicity = begDateDate.daysTo(begDateNew.date()) - 1
                                                     if periodicity < 0:
                                                         periodicity = 0
                                                     if begDateDate == begDateNew.date():
                                                         durationNew = duration
                                                     else:
                                                         durationNew = duration - 1 - periodicity
                                                     periodicityNew = 0
                                                     begDateNewDate = begDateNew.date()
                                                     for newExecutionKey in newExecutionPlanKeys:
                                                         newExecutionDate = QtCore.QDate(newExecutionKey)
                                                         if newExecutionDate > begDateNewDate:
                                                             periodicityNew = begDateNewDate.daysTo(
                                                                 newExecutionDate) - 1
                                                             if periodicityNew < 0:
                                                                 periodicityNew = 0
                                                             break
                                         elif aliquoticity > 1 and aliquoticity > quoticity:
                                             begDateNew = QtCore.QDateTime(endDate.date(),
                                                                           execTime if execTime else self.getCurrentTimeAction(
                                                                               endDate))
                                             durationNew = duration
                                         else:
                                             endDateNew = endDate.addDays(periodicity + 1)
                                             begDateNew = QtCore.QDateTime(endDateNew.date(),
                                                                           execTime if execTime else  self.getCurrentTimeAction(
                                                                               endDate))
                                             durationNew = duration - 1 - periodicity
                                         prevRecord.setValue('periodicity', toVariant(periodicity))
                                         if begDateNew and durationNew:
                                             if periodicityNew > -1:
                                                 periodicity = periodicityNew
                                             newRecord = tableAction.newRecord()
                                             newRecord.setValue('event_id', toVariant(prevRecord.value('event_id')))
                                             newRecord.setValue('begDate', toVariant(begDateNew))
                                             newRecord.setValue('status', toVariant(0))
                                             newRecord.setValue('idx', toVariant(9999))
                                             newRecord.setValue('specifiedName', toVariant(specifiedName))
                                             newRecord.setValue('duration', toVariant(durationNew))
                                             newRecord.setValue('periodicity', toVariant(periodicity))
                                             newRecord.setValue('aliquoticity', toVariant(aliquoticity))
                                             newRecord.setValue('plannedEndDate',
                                                                toVariant(begDateNew.addDays(durationNew - 1)))
                                             newRecord.setValue('actionType_id', toVariant(actionTypeId))
                                             newRecord.setValue('directionDate',
                                                                toVariant(prevRecord.value('directionDate')))
                                             newRecord.setValue('setPerson_id',
                                                                toVariant(prevRecord.value('setPerson_id')))
                                             newRecord.setValue('person_id', toVariant(QtGui.qApp.userId if (
                                             QtGui.qApp.userId and QtGui.qApp.userSpecialityId) else self.cmbSetPerson.value()))
                                             newRecord.setValue('org_id', toVariant(prevRecord.value('org_id')))
                                             newRecord.setValue('amount', toVariant(prevRecord.value('amount')))
                                             newAction = CAction(record=newRecord)
                                             if newExecutionPlan:
                                                 newAction.setExecutionPlan(newExecutionPlan)
                                             if newAction:
                                                 for properties in self.action._properties:
                                                     type = properties._type
                                                     name = type.name
                                                     if (type.canChangeOnlyOwner > 0
                                                         or type.inActionsSelectionTable == 1
                                                         or type.isActionNameSpecifier
                                                         ) and name:
                                                         newAction[name] = self.action[name]
                                                 self.newActionId = newAction.save(idx=9999)
                                             newRecordAction = True
                                             self.setRecordByNext(prevRecord)
                                             self.saveData()
                                             self.close()
                             if duration == 1 and not newRecordAction:
                                 begDate = forceDateTime(prevRecord.value('begDate'))
                                 prevRecord.setValue('status', toVariant(2))
                                 endDate = forceDateTime(prevRecord.value('endDate'))
                                 if not endDate:
                                     prevRecord.setValue('endDate', toVariant(begDate))
                                 prevRecord.setValue('person_id', toVariant(QtGui.qApp.userId if (
                                 QtGui.qApp.userId and QtGui.qApp.userSpecialityId) else self.cmbSetPerson.value()))
                                 prevRecord.setValue('plannedEndDate', toVariant(begDate.addDays(duration - 1)))
                                 self.setRecordByNext(prevRecord)
                                 self.saveData()
                                 self.close()
Exemple #22
0
 def __init__(self, context, actionId):
     db = QtGui.qApp.db
     record = db.getRecord('Action', '*', actionId)
     action = CAction(record=record)
     CCookedActionInfo.__init__(self, context, record, action)