コード例 #1
0
def recursively_explode_demands(process, order, user, visited):
    """This method assumes the output commitment from the process 

        has already been created.

    """
    #import pdb; pdb.set_trace()
    pt = process.process_type
    output = process.main_outgoing_commitment()
    if output.resource_type not in visited:
        visited.append(output.resource_type)
    for ptrt in pt.all_input_resource_type_relationships():
        commitment = Commitment(
            independent_demand=order,
            event_type=ptrt.event_type,
            description=ptrt.description,
            due_date=process.start_date,
            resource_type=ptrt.resource_type,
            process=process,
            project=pt.project,
            quantity=output.quantity * ptrt.quantity,
            unit_of_quantity=ptrt.resource_type.unit,
            created_by=user,
        )
        commitment.save()
        if ptrt.resource_type not in visited:
            visited.append(ptrt.resource_type)
            qty_to_explode = commitment.net()
            if qty_to_explode:
                pptr = ptrt.resource_type.main_producing_process_type_relationship(
                )
                if pptr:
                    next_pt = pptr.process_type
                    start_date = process.start_date - datetime.timedelta(
                        minutes=next_pt.estimated_duration)
                    next_process = Process(
                        name=next_pt.name,
                        process_type=next_pt,
                        process_pattern=next_pt.process_pattern,
                        project=next_pt.project,
                        url=next_pt.url,
                        end_date=process.start_date,
                        start_date=start_date,
                    )
                    next_process.save()
                    next_commitment = Commitment(
                        independent_demand=order,
                        event_type=pptr.event_type,
                        description=pptr.description,
                        due_date=process.start_date,
                        resource_type=pptr.resource_type,
                        process=next_process,
                        project=next_pt.project,
                        quantity=qty_to_explode * pptr.quantity,
                        unit_of_quantity=pptr.resource_type.unit,
                        created_by=user,
                    )
                    next_commitment.save()
                    recursively_explode_demands(next_process, order, user,
                                                visited)
コード例 #2
0
ファイル: utils.py プロジェクト: ai-jarvis/valuenetwork
def recursively_explode_demands(process, order, user, visited):
    """This method assumes the output commitment from the process 

        has already been created.

    """
    #import pdb; pdb.set_trace()
    pt = process.process_type
    output = process.main_outgoing_commitment()
    if output.resource_type not in visited:
        visited.append(output.resource_type)
    for ptrt in pt.all_input_resource_type_relationships():        
        commitment = Commitment(
            independent_demand=order,
            event_type=ptrt.event_type,
            description=ptrt.description,
            due_date=process.start_date,
            resource_type=ptrt.resource_type,
            process=process,
            project=pt.project,
            quantity=output.quantity * ptrt.quantity,
            unit_of_quantity=ptrt.resource_type.unit,
            created_by=user,
        )
        commitment.save()
        if ptrt.resource_type not in visited:
            visited.append(ptrt.resource_type)
            qty_to_explode = commitment.net()
            if qty_to_explode:
                pptr = ptrt.resource_type.main_producing_process_type_relationship()
                if pptr:
                    next_pt = pptr.process_type
                    start_date = process.start_date - datetime.timedelta(minutes=next_pt.estimated_duration)
                    next_process = Process(          
                        name=next_pt.name,
                        process_type=next_pt,
                        process_pattern=next_pt.process_pattern,
                        project=next_pt.project,
                        url=next_pt.url,
                        end_date=process.start_date,
                        start_date=start_date,
                    )
                    next_process.save()
                    next_commitment = Commitment(
                        independent_demand=order,
                        event_type=pptr.event_type,
                        description=pptr.description,
                        due_date=process.start_date,
                        resource_type=pptr.resource_type,
                        process=next_process,
                        project=next_pt.project,
                        quantity=qty_to_explode * pptr.quantity,
                        unit_of_quantity=pptr.resource_type.unit,
                        created_by=user,
                    )
                    next_commitment.save()
                    recursively_explode_demands(next_process, order, user, visited)
コード例 #3
0
ファイル: utils.py プロジェクト: bhaugen/valuenetwork
def generate_schedule(process, order, user):
    pt = process.process_type
    output = process.main_outgoing_commitment()
    for ptrt in pt.consumed_resource_type_relationships():
        commitment = Commitment(
            independent_demand=order,
            event_type=ptrt.relationship.event_type,
            relationship=ptrt.relationship,
            due_date=process.start_date,
            resource_type=ptrt.resource_type,
            process=process,
            project=pt.project,
            quantity=output.quantity * ptrt.quantity,
            unit_of_quantity=ptrt.resource_type.unit,
            created_by=user,
        )
        commitment.save()
        pptr = ptrt.resource_type.main_producing_process_type_relationship()
        if pptr:
            next_pt = pptr.process_type
            start_date = process.start_date - datetime.timedelta(
                minutes=next_pt.estimated_duration)
            next_process = Process(
                name=next_pt.name,
                process_type=next_pt,
                project=next_pt.project,
                url=next_pt.url,
                end_date=process.start_date,
                start_date=start_date,
            )
            next_process.save()
            next_commitment = Commitment(
                independent_demand=order,
                event_type=pptr.relationship.event_type,
                relationship=pptr.relationship,
                due_date=process.start_date,
                resource_type=pptr.resource_type,
                process=next_process,
                project=next_pt.project,
                quantity=output.quantity * pptr.quantity,
                unit_of_quantity=pptr.resource_type.unit,
                created_by=user,
            )
            next_commitment.save()
            generate_schedule(next_process, order, user)
コード例 #4
0
ファイル: utils.py プロジェクト: bhaugen/valuenetwork
def generate_schedule(process, order, user):
    pt = process.process_type
    output = process.main_outgoing_commitment()
    for ptrt in pt.consumed_resource_type_relationships():
        commitment = Commitment(
            independent_demand=order,
            event_type=ptrt.relationship.event_type,
            relationship=ptrt.relationship,
            due_date=process.start_date,
            resource_type=ptrt.resource_type,
            process=process,
            project=pt.project,
            quantity=output.quantity * ptrt.quantity,
            unit_of_quantity=ptrt.resource_type.unit,
            created_by=user,
        )
        commitment.save()
        pptr = ptrt.resource_type.main_producing_process_type_relationship()
        if pptr:
            next_pt = pptr.process_type
            start_date = process.start_date - datetime.timedelta(minutes=next_pt.estimated_duration)
            next_process = Process(          
                name=next_pt.name,
                process_type=next_pt,
                project=next_pt.project,
                url=next_pt.url,
                end_date=process.start_date,
                start_date=start_date,
            )
            next_process.save()
            next_commitment = Commitment(
                independent_demand=order,
                event_type=pptr.relationship.event_type,
                relationship=pptr.relationship,
                due_date=process.start_date,
                resource_type=pptr.resource_type,
                process=next_process,
                project=next_pt.project,
                quantity=output.quantity * pptr.quantity,
                unit_of_quantity=pptr.resource_type.unit,
                created_by=user,
            )
            next_commitment.save()
            generate_schedule(next_process, order, user)
コード例 #5
0
ファイル: Commitment.py プロジェクト: andreswebs/valuenetwork
    def mutate(cls, root, args, context, info):
        action = args.get('action')
        input_of_id = args.get('input_of_id')
        output_of_id = args.get('output_of_id')
        provider_id = args.get('provider_id')
        receiver_id = args.get('receiver_id')
        scope_id = args.get('scope_id')
        committed_resource_classified_as_id = args.get('committed_resource_classified_as_id')
        involves_id = args.get('involves_id')
        committed_numeric_value = args.get('committed_numeric_value')
        committed_unit_id = args.get('committed_unit_id')
        planned_start = args.get('planned_start')
        due = args.get('due')
        note = args.get('note')
        plan_id = args.get('plan_id')
        is_plan_deliverable = args.get('is_plan_deliverable')
        #for_plan_deliverable_id = args.get('for_plan_deliverable_id')
        url = args.get('url')

        #if output_of_id or input_of_id:
        #    if not plan_id:
        #        raise ValidationError("Process related commitments must be part of a plan.")
        event_type = EventType.objects.convert_action_to_event_type(action)
        if not note:
            note = ""
        due = datetime.datetime.strptime(due, '%Y-%m-%d').date()
        if planned_start:
            planned_start = datetime.datetime.strptime(planned_start, '%Y-%m-%d').date()
        if scope_id:
            scope = EconomicAgent.objects.get(pk=scope_id)
        else:
            scope = None
        if provider_id:
            provider = EconomicAgent.objects.get(pk=provider_id)
        else:
            provider = None
        if receiver_id:
            receiver = EconomicAgent.objects.get(pk=receiver_id)
        else:
            receiver = None
        if input_of_id:
            process = Process.objects.get(pk=input_of_id)
        elif output_of_id:
            process = Process.objects.get(pk=output_of_id)
        else:
            process = None
        if committed_resource_classified_as_id:
            resource_classified_as = EconomicResourceType.objects.get(pk=committed_resource_classified_as_id)
        else:
            resource_classified_as = None
        if involves_id:
            committed_resource = EconomicResource.objects.get(pk=involves_id)
        else:
            committed_resource = None
        committed_unit = Unit.objects.get(pk=committed_unit_id)
        if not url:
            url = ""
        if plan_id:
            plan = Order.objects.get(pk=plan_id)
        else:
            plan = None
        if is_plan_deliverable:
            deliverable_for = plan
        else:
            deliverable_for = None
        #if for_plan_deliverable_id:
        #    order_item = CommitmentProxy.objects.get(pk=for_plan_deliverable_id)
        #else:
        #    order_item = None

        commitment = CommitmentProxy(
            event_type = event_type,
            process = process,
            from_agent = provider,
            to_agent = receiver,
            resource_type = resource_classified_as,
            resource = committed_resource,
            quantity = Decimal(committed_numeric_value),
            unit_of_quantity = committed_unit,
            url=url,
            start_date = planned_start,
            due_date = due,
            description=note,
            context_agent=scope,
            order=deliverable_for,
            independent_demand=plan,
            order_item=None, #order_item,
            created_by=context.user,
        )

        user_agent = AgentUser.objects.get(user=context.user).agent
        is_authorized = user_agent.is_authorized(object_to_mutate=commitment)
        if is_authorized:
            commitment.save_api()
        else:
            raise PermissionDenied('User not authorized to perform this action.')

        return CreateCommitment(commitment=commitment)
コード例 #6
0
    def mutate(cls, root, args, context, info):
        action = args.get('action')
        input_of_id = args.get('input_of_id')
        output_of_id = args.get('output_of_id')
        provider_id = args.get('provider_id')
        receiver_id = args.get('receiver_id')
        scope_id = args.get('scope_id')
        committed_resource_classified_as_id = args.get('committed_resource_classified_as_id')
        involves_id = args.get('involves_id')
        committed_numeric_value = args.get('committed_numeric_value')
        committed_unit_id = args.get('committed_unit_id')
        planned_start = args.get('planned_start')
        due = args.get('due')
        note = args.get('note')
        plan_id = args.get('plan_id')
        is_plan_deliverable = args.get('is_plan_deliverable')
        #for_plan_deliverable_id = args.get('for_plan_deliverable_id')
        url = args.get('url')

        #if output_of_id or input_of_id:
        #    if not plan_id:
        #        raise ValidationError("Process related commitments must be part of a plan.")
        event_type = EventType.objects.convert_action_to_event_type(action)
        if not note:
            note = ""
        due = datetime.datetime.strptime(due, '%Y-%m-%d').date()
        if planned_start:
            planned_start = datetime.datetime.strptime(planned_start, '%Y-%m-%d').date()
        if scope_id:
            scope = EconomicAgent.objects.get(pk=scope_id)
        else:
            scope = None
        if provider_id:
            provider = EconomicAgent.objects.get(pk=provider_id)
        else:
            provider = None
        if receiver_id:
            receiver = EconomicAgent.objects.get(pk=receiver_id)
        else:
            receiver = None
        if input_of_id:
            process = Process.objects.get(pk=input_of_id)
        elif output_of_id:
            process = Process.objects.get(pk=output_of_id)
        else:
            process = None
        if committed_resource_classified_as_id:
            resource_classified_as = EconomicResourceType.objects.get(pk=committed_resource_classified_as_id)
        else:
            resource_classified_as = None
        if involves_id:
            committed_resource = EconomicResource.objects.get(pk=involves_id)
        else:
            committed_resource = None
        committed_unit = Unit.objects.get(pk=committed_unit_id)
        if not url:
            url = ""
        if plan_id:
            plan = Order.objects.get(pk=plan_id)
        else:
            plan = None
        if is_plan_deliverable:
            deliverable_for = plan
        else:
            deliverable_for = None
        #if for_plan_deliverable_id:
        #    order_item = CommitmentProxy.objects.get(pk=for_plan_deliverable_id)
        #else:
        #    order_item = None

        commitment = CommitmentProxy(
            event_type = event_type,
            process = process,
            from_agent = provider,
            to_agent = receiver,
            resource_type = resource_classified_as,
            resource = committed_resource,
            quantity = Decimal(committed_numeric_value),
            unit_of_quantity = committed_unit,
            url=url,
            start_date = planned_start,
            due_date = due,
            description=note,
            context_agent=scope,
            order=deliverable_for,
            independent_demand=plan,
            order_item=None, #order_item,
            created_by=context.user,
        )

        user_agent = AgentUser.objects.get(user=context.user).agent
        is_authorized = user_agent.is_authorized(object_to_mutate=commitment)
        if is_authorized:
            commitment.save_api()
        else:
            raise PermissionDenied('User not authorized to perform this action.')

        return CreateCommitment(commitment=commitment)