Ejemplo n.º 1
0
 def setActionTypeId(self, actionTypeId):
     self.cmbActionType.setValue(actionTypeId)
     self.tabWidget.setTabEnabled(1, bool(actionTypeId))
     old_props = dict()
     if self.action:
         old_props = self.action._propertiesByName
     if actionTypeId:
         if (not self.action or self.action.getType().id != actionTypeId):
             self.action = CAction.createByTypeId(actionTypeId)
             self.tblProps.model().setAction(self.action, None, 0, None)
             self.tblProps.resizeRowsToContents()
     else:
         self.action = None
         self.tblProps.model().setAction(self.action, None, 0, None)
         self.tblProps.resizeRowsToContents()
     if self.action:
         new_props = self.action._propertiesByName
         for prop in old_props:
             if prop in self.action._propertiesByName and \
                             new_props[prop]._type.getValueType() == old_props[prop]._type.getValueType():
                 new_props[prop]._changed = True
                 new_props[prop]._evaluation = old_props[prop]._evaluation
                 new_props[prop]._isAssigned = old_props[prop]._isAssigned
                 new_props[prop]._norm = old_props[prop]._norm
                 new_props[prop]._unitId = old_props[prop]._unitId
                 new_props[prop]._value = old_props[prop]._value
Ejemplo n.º 2
0
    def processResults(self, results):
        defaultEventTypeId = forceRef(
            self.db.translate('EventType', 'code', '001', 'id'))
        tableJobTicket = self.db.table('Job_Ticket').alias('jt')
        tableAction = self.db.table('Action').alias('a')
        currentDate = QDate.currentDate()
        for i in range(results.length()):
            result = results.at(i)
            localId = result.firstChildElement('ido').text()
            externalId = result.firstChildElement('idi').text()
            tests = result.firstChildElement('tests')
            if not tests:
                continue

            test = tests.firstChildElement('test')
            if not test:
                continue
            dateString = test.firstChildElement('date').text()
            date = QDate.fromString(dateString, Qt.ISODate)
            value = test.firstChildElement('value').text()
            status = test.firstChildElement('status').text()
            comment = test.firstChildElement('comment').text()
            if localId:
                stmt = u'''SELECT
                  a.id as actionId, Event.id as eventId
                FROM Job_Ticket jt
                  INNER JOIN Job j
                    ON j.id = jt.master_id AND jt.status = 0
                  INNER JOIN rbJobType jt1 ON jt1.code = '4-4' AND jt1.id= j.jobType_id
                  INNER JOIN ActionProperty_Job_Ticket apjt
                    ON apjt.value = jt.id
                  INNER JOIN ActionProperty ap ON ap.id = apjt.id
                  INNER JOIN Action a ON a.id = ap.action_id AND a.deleted = 0
                  INNER JOIN Event ON Event.id = a.event_id AND Event.deleted = 0
                  INNER JOIN Client c ON c.id = Event.client_id AND c.deleted = 0
                WHERE %s'''
                cond = [
                    self.tableEvent['client_id'].eq(forceRef(localId)),
                    tableJobTicket['datetime'].dateEq(date),
                    tableAction['actionType_id'].eq(self.actionType)
                ]
                query = self.db.query(stmt % self.db.joinAnd(cond))
                if not query.first():
                    continue
                record = query.record()
                eventId = forceRef(record.value('eventId'))
                action = CAction.getAction(eventId, u'А06.09.007.002*')
                actionRecord = action.getRecord()
                endDate = forceDate(actionRecord.value('endDate'))
                if not endDate:
                    actionRecord.setValue('endDate', toVariant(currentDate))
                actionRecord.setValue(
                    'status',
                    toVariant(2 if status == 1 else 3 if status == 2 else 0))
                action[u'Результат'] = externalId + u' ' + value
                action[u'Описание'] = comment
                action.setRecord(actionRecord)
                action.save()

            elif defaultEventTypeId:
                localId = self._mapIDOtoIDI.get(externalId, None)
                if localId is None:
                    print 'Error: found test result without information about client. Skipping.'
                    continue

                self.db.transaction()
                try:
                    eventRecord = self.tableEvent.newRecord()
                    eventRecord.setValue('eventType_id',
                                         toVariant(defaultEventTypeId))
                    eventRecord.setValue('client_id', toVariant(localId))
                    eventRecord.setValue('setDate', toVariant(date))
                    eventRecord.setValue('isPrimary', toVariant(1))
                    eventRecord.setValue('order', toVariant(1))
                    eventId = self.db.insertRecord('Event', eventRecord)

                    action = CAction.createByTypeId(self.actionType)
                    actionRecord = action.getRecord()
                    if not actionRecord:
                        actionRecord = self.tableAction.newRecord()
                        actionRecord.setValue('actionType_id',
                                              toVariant(self.actionType))
                    actionRecord.setValue(
                        'status',
                        toVariant(2 if status == 1 else 3 if status ==
                                  2 else 0))
                    actionRecord.setValue('begDate', toVariant(date))
                    actionRecord.setValue('endDate', toVariant(currentDate))
                    action[u'Результат'] = externalId + ' ' + value
                    action[u'Описание'] = comment
                    action.setRecord(actionRecord)
                    action.save(eventId)
                    self.db.commit()
                except:
                    self.db.rollback()
                    raise