Update app.py
Browse files
app.py
CHANGED
|
@@ -60,7 +60,7 @@ def signup():
|
|
| 60 |
generated_referral_code = generate_referral_code()
|
| 61 |
|
| 62 |
try:
|
| 63 |
-
ref=0 # Default reward points for new user
|
| 64 |
|
| 65 |
# Check if a referral code is entered
|
| 66 |
if referral_code:
|
|
@@ -75,14 +75,31 @@ def signup():
|
|
| 75 |
referrer = referral_result['records'][0]
|
| 76 |
referrer_email = referrer.get('Email__c')
|
| 77 |
|
| 78 |
-
# Generate a unique coupon code
|
| 79 |
new_coupon_code = generate_coupon_code()
|
| 80 |
|
| 81 |
-
#
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 86 |
|
| 87 |
# Create the new customer record in Salesforce
|
| 88 |
sf.Customer_Login__c.create({
|
|
@@ -93,7 +110,7 @@ def signup():
|
|
| 93 |
"Reward_Points__c": ref, # No points added, only coupon is created
|
| 94 |
"Referral__c": generated_referral_code
|
| 95 |
})
|
| 96 |
-
|
| 97 |
return redirect(url_for("login"))
|
| 98 |
|
| 99 |
except Exception as e:
|
|
|
|
| 60 |
generated_referral_code = generate_referral_code()
|
| 61 |
|
| 62 |
try:
|
| 63 |
+
ref = 0 # Default reward points for new user
|
| 64 |
|
| 65 |
# Check if a referral code is entered
|
| 66 |
if referral_code:
|
|
|
|
| 75 |
referrer = referral_result['records'][0]
|
| 76 |
referrer_email = referrer.get('Email__c')
|
| 77 |
|
| 78 |
+
# Generate a new unique coupon code
|
| 79 |
new_coupon_code = generate_coupon_code()
|
| 80 |
|
| 81 |
+
# Check if referrer already has a record in Referral_Coupon__c
|
| 82 |
+
existing_coupon_query = f"SELECT Id, Coupon_Code__c FROM Referral_Coupon__c WHERE Referral_Email__c = '{referrer_email}'"
|
| 83 |
+
existing_coupon_result = sf.query(existing_coupon_query)
|
| 84 |
+
|
| 85 |
+
if existing_coupon_result['records']:
|
| 86 |
+
# If record exists, append the new coupon on the next line
|
| 87 |
+
referral_record = existing_coupon_result['records'][0]
|
| 88 |
+
referral_id = referral_record['Id']
|
| 89 |
+
existing_coupons = referral_record.get('Coupon_Code__c', '')
|
| 90 |
+
|
| 91 |
+
updated_coupons = f"{existing_coupons}\n{new_coupon_code}".strip()
|
| 92 |
+
|
| 93 |
+
# Update the existing record with the new coupon
|
| 94 |
+
sf.Referral_Coupon__c.update(referral_id, {
|
| 95 |
+
"Coupon_Code__c": updated_coupons
|
| 96 |
+
})
|
| 97 |
+
else:
|
| 98 |
+
# If no record exists, create a new one
|
| 99 |
+
sf.Referral_Coupon__c.create({
|
| 100 |
+
"Referral_Email__c": referrer_email,
|
| 101 |
+
"Coupon_Code__c": new_coupon_code
|
| 102 |
+
})
|
| 103 |
|
| 104 |
# Create the new customer record in Salesforce
|
| 105 |
sf.Customer_Login__c.create({
|
|
|
|
| 110 |
"Reward_Points__c": ref, # No points added, only coupon is created
|
| 111 |
"Referral__c": generated_referral_code
|
| 112 |
})
|
| 113 |
+
|
| 114 |
return redirect(url_for("login"))
|
| 115 |
|
| 116 |
except Exception as e:
|