Skip to content

Commit

Permalink
Merge pull request #2441 from shadrak98/fix_partner_discount
Browse files Browse the repository at this point in the history
fix(partner): Remove legacy contract check
  • Loading branch information
shadrak98 authored Jan 23, 2025
2 parents 92d40ee + 3a6a6fa commit a89d18b
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 23 deletions.
8 changes: 3 additions & 5 deletions press/api/partner.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,8 @@ def transfer_credits(amount, customer, partner):
amt = frappe.utils.flt(amount)
partner_doc = frappe.get_doc("Team", partner)
credits_available = partner_doc.get_balance()
partner_level, legacy_contract = partner_doc.get_partner_level()
# no discount for partners on legacy contract
# TODO: remove legacy contract check
discount_percent = 0.0 if legacy_contract == 1 else DISCOUNT_MAP.get(partner_level)
partner_level, certificates = partner_doc.get_partner_level()
discount_percent = DISCOUNT_MAP.get(partner_level)

if credits_available < amt:
frappe.throw(f"Insufficient Credits to transfer. Credits Available: {credits_available}")
Expand Down Expand Up @@ -221,7 +219,7 @@ def get_prev_month_partner_contribution(partner_email):

@frappe.whitelist()
def calculate_partner_tier(contribution, currency):
partner_tier = frappe.qb.DocType("Partner Teir")
partner_tier = frappe.qb.DocType("Partner Tier")
query = frappe.qb.from_(partner_tier).select(partner_tier.name)
if currency == "INR":
query = query.where(partner_tier.target_in_inr <= contribution).orderby(
Expand Down
13 changes: 0 additions & 13 deletions press/press/doctype/invoice/invoice.py
Original file line number Diff line number Diff line change
Expand Up @@ -622,19 +622,6 @@ def validate_items(self):
def compute_free_credits(self):
self.free_credits = sum([d.amount for d in self.credit_allocations if d.source == "Free Credits"])

def apply_partner_discount(self):
if self.flags.on_partner_conversion:
return

team = frappe.get_cached_doc("Team", self.team)
partner_level, legacy_contract = team.get_partner_level()
PartnerDiscounts = {"Entry": 0, "Bronze": 0.05, "Silver": 0.1, "Gold": 0.15}
discount_percent = 0.1 if legacy_contract == 1 else PartnerDiscounts.get(partner_level)
self.discount_note = "New Partner Discount"
for item in self.items:
if item.document_type in ("Site", "Server", "Database Server"):
item.discount_percentage = discount_percent

def calculate_discounts(self):
for item in self.items:
if item.discount_percentage:
Expand Down
8 changes: 3 additions & 5 deletions press/press/doctype/team/team.py
Original file line number Diff line number Diff line change
Expand Up @@ -999,9 +999,9 @@ def get_partner_level(self):
if response.ok:
res = response.json()
partner_level = res.get("message")
legacy_contract = res.get("legacy_contract")
certificate_count = res.get("certificates")
if partner_level:
return partner_level, legacy_contract
return partner_level, certificate_count
return None

self.add_comment(text="Failed to fetch partner level" + "<br><br>" + response.text)
Expand Down Expand Up @@ -1194,9 +1194,7 @@ def notify_with_email(self, recipients: list[str], **kwargs):
def send_telegram_alert_for_failed_payment(self, invoice):
team_url = get_url_to_form("Team", self.name)
invoice_url = get_url_to_form("Invoice", invoice)
message = (
f"Failed Invoice Payment [{invoice}]({invoice_url}) of" f" Partner: [{self.name}]({team_url})"
)
message = f"Failed Invoice Payment [{invoice}]({invoice_url}) of Partner: [{self.name}]({team_url})"
TelegramMessage.enqueue(message=message)

@frappe.whitelist()
Expand Down

0 comments on commit a89d18b

Please sign in to comment.