Пример #1
0
def create_opportunity_with_olis(account_sfdc, opportunity_name, products):
    product_ids = [product['Id'] for product in products]
    product_ids = "'" + "\',\'".join(product_ids) + "'"
    try:
        sf = sfdc.get_instance()
        pbes = sf.query(
            "Select Id,Product2Id,UnitPrice from PricebookEntry where Product2Id in (%s) and Pricebook2.IsStandard=True"
            % product_ids)
        pdt_to_price = {}
        for pdt in pbes['records']:
            pdt_to_price[pdt['Product2Id']] = pdt
    except Exception as e:
        err = str(
            e
        ) + "\n Please reset your SFDC credentials \n Failed to create Opportunity"
        err += "\n attempting to create %s" % products + \
               "\n Account %s" % account_sfdc
        email_sender.auto_report_bug(err)
        raise e

    close_date = datetime.datetime.now().isoformat()

    try:
        opty = {
            "AccountId": account_sfdc,
            "Name": opportunity_name,
            "StageName": "Actively Communicating",
            "CloseDate": close_date
        }
        #
        opportunity = sf.Opportunity.create(opty)
    except Exception as e:
        print 'err'
        err = str(e) + "\n Failed to create the opportunity" + \
                       "\n Opportunity %s " % opty + \
                       "\n %s" % products
        email_sender.auto_report_bug(err)
        raise e

    try:
        opporunity_id = opportunity['id'] if 'id' in opportunity else None
        for line_item in products:
            pdt_id = line_item['Id']
            pbe = pdt_to_price[pdt_id]['Id']
            quantity = int(line_item['Quantity'])
            if quantity > 0:
                unit_price = pdt_to_price[pdt_id]['UnitPrice']
                oli = {
                    "OpportunityId": opporunity_id,
                    "PricebookEntryId": pbe,
                    "UnitPrice": unit_price,
                    "Quantity": quantity
                }
                resp = sf.OpportunityLineItem.create(oli)
    except Exception as e:
        err = str(e) + "Failed to create the OLI" + \
                       "\n For Opportunity %s" % opporunity_id + \
                       "Products %s" % products
        email_sender.auto_report_bug(err)
Пример #2
0
def pricepoints(productids):
    sf = sfdc.get_instance()
    pdtids = "'" + "\',\'".join(productids) + "'"
    products = sf.query(
        "Select Id,UnitPrice,Product2Id from PricebookEntry where Product2Id in (%s) and Pricebook2.IsStandard = True"
        % pdtids)

    return products['records']
Пример #3
0
def get_products():
    sf = sfdc.get_instance()
    products = sf.query(
        "Select Id, Name, Family, Description,UnitType__c,"
        "                 (Select Name, Product__r.Name, Product__r.Id, Id from AddOnProducts__r order by Product__r.Name),"
        "                 (Select Name, Id, Quantity__c,Product__r.Name,Product__r.Id from Breakdown_Products__r order by Name) "
        + "   from Product2 " + "where Display_In_SPN__c=True")

    return products['records']
Пример #4
0
 def create(sfdc_case_id, comment_id):
     comment = Comment.query.filter(
         Comment.CommentID == comment_id).first()
     sf = sfdc.get_instance()
     if comment.RenderType == '' or comment.RenderType is None or comment.RenderType == 'text' and sfdc_case_id:
         sf.CaseComment.create({
             'CommentBody': comment.Message,
             'ParentId': sfdc_case_id
         })
Пример #5
0
 def create(sfdc_case_id, attachment_id):
     attachment = SequenceAttachment.query.filter_by(
         SequenceAttachmentID=attachment_id).first()
     sf = sfdc.get_instance()
     if sfdc_case_id and attachment.Attachment:
         sf.Attachment.create({
             "ParentID":
             sfdc_case_id,
             "Name":
             attachment.FileName,
             "Body":
             base64.b64encode(attachment.Attachment)
         })
Пример #6
0
 def create(forum_id):
     forum = Forum.query.filter(Forum.ForumID == forum_id).first()
     try:
         sf = sfdc.get_instance()
         response = sf.Case.update(str(forum.SFDC_ID),
                                   {'Status': 'closed'})
         case = sf.Case.get(str(forum.SFDC_ID))
         forum.ClosedDate = case['ClosedDate']
         forum.save()
         print response
     except Exception as e:
         print "what??"
         err = str(e) + "\n Please reset your SFDC credentials"
         email_sender.auto_report_bug(err)
Пример #7
0
def testing():
    #temp function to update database
    forums = Forum.query.all()
    sf = sfdc.get_instance()
    for forum in forums:
        try:
            case = sf.Case.get(str(forum.SFDC_ID))
            forum.ClosedDate = case['ClosedDate']
            forum.save()
            print "saving"
            print response
        except Exception as e:
            print "what??"
            err = str(e) + "\n Please reset your SFDC credentials"
            email_sender.auto_report_bug(err)
Пример #8
0
def search_sfdc_by_name(search_text):
    import modules.sfdc as sfdc
    sf = sfdc.get_instance()
    accounts = sf.query(search_text);
    accounts = accounts['records']
    return Response(json.dumps(accounts), content_type='application/json')
Пример #9
0
        def create(forum_id, sfdc_data):
            if sfdc_data is None:
                print 'no sfdc data'
                return
            assistance_request = str(sfdc_data['assistanceRequest'])
            support_request = str(sfdc_data['instrument'])
            elixys_version = str(sfdc_data['elixysVersion'])

            original_subject = self.Subject
            forum = Forum.query.filter(Forum.ForumID == forum_id).first()

            try:
                sf = sfdc.get_instance()
                user = forum.user
                account_id = user.account.SFDC_ID
                contact_id = user.SFDC_ID
                case_details = {
                    'Description': self.Subtitle,
                    "Subject": self.Subject,
                    "Origin": "Web",
                    "SuppliedEmail": user.Email,
                    "AccountID": account_id,
                    "ContactID": contact_id,
                    "Support_Request__c": support_request,
                    "Assistance_Request__c": assistance_request,
                    "Elixys_Version__c": elixys_version
                }
                response = sf.Case.create(case_details)
                sf_case_id = response['id']
                forum.SFDC_ID = sf_case_id

                sf_case = sf.Case.get(sf_case_id)
                case_number = sf_case['CaseNumber']
                forum.CaseNumber = case_number

                forum.save()

                from comment import Comment
                from sequenceattachment import SequenceAttachment

                comment_attachments = Comment.query.filter(
                    and_(Comment.ParentID == forum.ForumID,
                         Comment.Type == 'Forums')).all()
                for comment_attached in comment_attachments:
                    if comment_attached.RenderType != 'text' and comment_attached.RenderType is not None and comment_attached.RenderType != '':
                        attachment = SequenceAttachment.query.filter(
                            and_(
                                SequenceAttachment.Type == 'comments',
                                SequenceAttachment.ParentID ==
                                comment_attached.CommentID)).first()
                        if attachment:
                            attachment.create_case_attachment(sf_case_id)

                comment = Comment(Type='Forums',\
                                  ParentID=forum.ForumID,\
                                  UserID=SOFIEBIO_USERID,\
                                  RenderType='text',\
                                  Message='Thank-you %s, case #%s has been assigned to you. \n You will be contacted within 48 business hours by an ELIXYS support team-member' % (user.Name, case_number))
                comment.save()

            except Exception as e:
                err = str(e) + "\n Please reset your SFDC credentials"
                email_sender.auto_report_bug(err)
            finally:
                email_sender.report_issue(forum, original_subject)