Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"Add New Opportunity" Button on Project Page #105

Open
maxpearl opened this issue Jul 28, 2020 · 0 comments
Open

"Add New Opportunity" Button on Project Page #105

maxpearl opened this issue Jul 28, 2020 · 0 comments
Assignees

Comments

@maxpearl
Copy link

Feature Name: "Add Opportunity Button"

Basic Workflow:

  • Application Submitted
  • Project Created
  • If no opportunity has yet been created (there is no sf_opportunity_id):
    • Button on project page: "Create new opportunity"
    • List of Record Types displayed, user chooses
    • Page with fields for new Oppty is displayed
    • When submitted, new oppty in SF is created
    • That returns sf_opportunity_id, which is stored in hypha project model
  • If sf_opportunity_id exists when project is displayed, button with "See opportunity" with link to salesforce is displayed.

Requires: Project, Opportunity and RecordType models

Project Model

  • Revision: Add field sf_opportunity_id: sf_opportunity_id = models.CharField(max_length=20, null=True, blank=True)

RecordType and Opportunity Models

(See specific model definitions at bottom of Notion document relating to the specific Reset project)

Page:

  • Path: /apply/projects/
  • Location: Under "Actions to Take"

Condition:

  • If SALESFORCE_INTEGRATION: if no sf_opportunity_id in project, show "add opportunity button", otherwise, show button that says "Show opportunity in Salesforce" linking to the Salesforce Record.
  • Link is generated from HOST database variable, plus: 'lightning/r/Opportunity/sf_opportunity_id/view':
    url =DATABASES['salesforce']['HOST'] + '/r/Opportunity/' + sf_opportunity_id + '/view'

Actions:

  • Add opportunity button leads to a pop-up form, giving user a choice of record types
# Function
from .models import Project, Opportunity, RecordType

def get_record_types(sobject):
    record_types = RecordType.objects.filter(sobject_type=sobject)
    return record_types

## View
def rt_choice(request):
    sobject = 'Opportunity'
    project_id = request.GET.get('project_id')
    record_types = get_record_types(sobject)
    context = {
        'project_id': project_id,
        'record_types': record_types
    }
    return render(request, 'projects/rt_choice.html', context)
  • Action after form submission is a form which displays fields from the Opportunity model.
from django.forms import ModelForm
from django import forms
from .models import Opportunity

class OpportunityForm(ModelForm):
    class Meta:
        model = Opportunity
        fields = ['name', 'description', 'stage_name', 'org_name', 'amount', 'op_type', 'close_date']
        widgets = {
            'project_id': forms.HiddenInput(),
            'record_type': forms.HiddenInput()
        }
  • Action after submission of that form is the opportunity is added to Salesforce
## View

def new_oppty(request):
    if request.method == 'POST':
        form = OpportunityForm(request.POST)
        oppty = form.save()
        print(f"Oppty: {oppty.id}")
        project = get_object_or_404(Project, pk=request.POST.get('project_id'))
        context = {
            'project': project,
            'message': "Opportunity Saved!",
            'oppty': oppty
        }
        return render(request, 'projects/detail.html', context)
    else:
        context = {
            'form': OpportunityForm,
            'project_id': request.GET.get('project_id'),
            'record_type': request.GET.get('rt_id')
        }
        return render(request, 'opportunity/new_oppty.html', context)
@frjo frjo self-assigned this Jul 28, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants