Exemple #1
0
    def __call__(self):
        request = self.request

        ret = cc.makeRequest(
            '/variable-instance',
            'post', {'processInstanceIdIn': [request.matchdict['processId']]},
            urlParams={'deserializeValues': 'false'})
        if not ret:
            raise HTTPNotFound()

        self.variables = cc.parseVariables(ret)
        ois = self.variables.get('orderItems')
        if ois:
            addItemInfo(ois)

        stream = self.template.generate(variables=self.variables, view=self)
        body = rml2pdf.parseString(stream.render()).read()

        response = Response(
            content_type='application/pdf',
            content_disposition='filename="%s_%s.pdf"' %
            (self.variables['externalOrderId'], request.matchdict['form']),
            content_length=len(body),
            body=body)
        return response
Exemple #2
0
    def getOutstandingOrders(self):
        params = {
            'processDefinitionKey': 'worktop',
            'activityId': 'WorktopShipped',
            'unfinished': True
        }

        ret = cc.makeRequest(
            '/history/activity-instance',
            'post',
            params,
            urlParams={'maxResults': 100},
            withProcessVariables=('orderId', 'externalOrderId',
                                  'factoryNumber', 'customerName',
                                  'customerRegionCode',
                                  'scheduledInstallationDate',
                                  'productionDrawing', 'orderItems'),
            hoistProcessVariables=True)

        for p in ret:
            ois = p.get('orderItems')
            if ois:
                addItemInfo(ois)

            if 'customerRegionCode' in p:
                p['customerRegionName'] = getRegionName(
                    p['customerRegionCode'])
                del p['customerRegionCode']
        return ret
Exemple #3
0
    def getTask(self, taskId):
        """
        Return a single task by task id together with all process variables of
        the process to which the task belongs.

        If the task can no longer be found, maybe completed by someone else,
        return None.
        """
        try:
            task = cc.makeRequest(f'/task/{taskId}',
                                  'get',
                                  withProcessVariables='*')
        except CamundaRESTError as e:
            if e.status == 404:
                task = None
            else:
                raise

        if task:
            task['comments'] = cc.makeRequest(f'/task/{taskId}/comment', 'get')
            ois = task['processVariables'].get('orderItems')
            if ois:
                addItemInfo(ois)

        return task
Exemple #4
0
    def getProcessVariables(self, processInstanceId):
        variables = cc.parseVariables(
            cc.makeRequest(f'/history/variable-instance',
                           'post',
                           {'processInstanceIdIn': [processInstanceId]},
                           urlParams={'deserializeValues': 'false'}))

        ois = variables.get('orderItems')
        if ois:
            addItemInfo(ois)

        return variables
Exemple #5
0
def searchProcess(cond, request, countOnly=False, maxRows=50):
    """ Note the startDate and endDate will be passed in UTC """
    cond['storeId'] = request.user.extraData['worktop'].get('storeId')

    params = {
        'processDefinitionKey': 'worktop',
        'sorting': [{
            'sortBy': 'startTime',
            'sortOrder': 'desc'
        }]
    }

    searchText = cond.get('searchText')
    showCompleted = cond.get('completed')

    if searchText:
        if isOrderId(searchText):
            params['processInstanceBusinessKey'] = searchText
        elif isIkeaOrderId(searchText):
            params['variables'] = [{
                'name': 'externalOrderId',
                'operator': 'eq',
                'value': searchText.upper()
            }]
        elif isMobile(searchText):
            params['variables'] = [{
                'name': 'customerMobile',
                'operator': 'eq',
                'value': searchText
            }]
        else:
            params['variables'] = [{
                'name': 'customerName',
                'operator': 'eq',
                'value': searchText
            }]
    else:
        parseDate(cond, fields=['startDate', 'endDate'])
        startDate, endDate = cond['startDate'], cond['endDate']
        endDate = endDate + timedelta(1)

        if (endDate - startDate) > timedelta(365):
            raise RPCUserError('订单查询时间跨度不能大于1年。')

        if showCompleted:
            params['variables'] = [{
                'name': 'actualInstallationDate',
                'operator': 'gteq',
                'value': startDate
            }, {
                'name': 'actualInstallationDate',
                'operator': 'lt',
                'value': endDate
            }]
        else:
            params['startedBefore'] = endDate
            params['startedAfter'] = startDate

    storeId = cond['storeId']
    if storeId:
        variables = params.setdefault('variables', [])
        variables.append({
            'name': 'storeId',
            'operator': 'eq',
            'value': storeId
        })

    if countOnly:
        ret = cc.makeRequest(
            '/history/process-instance/count',
            'post',
            params,
        )
        if ret['count'] > 500:
            raise RPCUserError('单次导出结果大于500条,请搜索条件再')
        return ret['count']
    else:
        ret = cc.makeRequest(
            '/history/process-instance',
            'post',
            params,
            urlParams={'maxResults': maxRows},
            withProcessVariables=('externalOrderId', 'customerName', 'storeId',
                                  'orderItems', 'receivingDate',
                                  'isInstallationRequested',
                                  'actualMeasurementDate',
                                  'confirmedMeasurementDate',
                                  'scheduledMeasurementDate',
                                  'actualInstallationDate',
                                  'confirmedInstallationDate',
                                  'scheduledInstallationDate'),
            processInstanceIdField='id',
            hoistProcessVariables=True)

        #
        # Prepare for display by adding additional infos:
        #  * add model to orderItems as only itemId is stored
        #  * add human readable status text
        #
        currentTime = datetime.now()
        for p in ret:
            # The instance variables of Date type are parsed correctly, but the
            # process property is not. We will do the parse here.
            parseDate(p, fields=['startTime'])
            p['startTime'] = p['startTime'].astimezone(tzLocal).replace(
                tzinfo=None)

            # calculate the duration of the process.
            if 'TERMINATED' not in p['state']:
                start = p.get('actualMeasurementDate') or \
                    p.get('scheduledMeasurementDate') or p['startTime']
                end = p.get('actualInstallationDate') or currentTime
                delta = end - start
                if delta.total_seconds() > 0:
                    p['duration'] = delta.days + decimal_round(
                        Decimal(delta.seconds / 86400), Decimal('0.1'))

            state = p.pop('state')
            if state == 'ACTIVE':
                if p.get('actualInstallationDate'):
                    text = '已安装' \
                        if p.get('isInstallationRequested', True) else '已送货'
                elif p.get('confirmedInstallationDate'):
                    text = '待安装'
                elif p.get('receivingDate'):
                    text = '已收货'
                elif p.get('actualMeasurementDate') or \
                        not p.get('scheduledMeasurementDate'):
                    text = '生产中'
                elif p.get('confirmedMeasurementDate') or \
                        p.get('scheduledMeasurementDate'):
                    text = '待测量'
                else:
                    text = '进行中'
                p['statusText'] = text
            else:
                p['statusText'] = __StatusNames__[state]

            ois = p.get('orderItems')
            if ois:
                addItemInfo(ois)

        return ret