-
Notifications
You must be signed in to change notification settings - Fork 1
Add manual override to referral fees calculation #70
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR adds a manual override capability to the referral fees calculation by introducing an optional sales_partner parameter to the apply_referral_fee_rules function. This allows callers to specify a different sales partner than the one attached to the invoice document.
Key changes:
- Added optional
sales_partnerparameter toapply_referral_fee_rulesfunction signature - Modified the logic to use the override parameter when provided, falling back to
doc.sales_partnerotherwise
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| if not doc.sales_partner or doc.sales_partner == "": | ||
| return |
Copilot
AI
Jan 7, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The early return check on line 26 does not account for the new sales_partner parameter override. When a manual override is provided via the sales_partner parameter, this check should evaluate the override value instead of only checking doc.sales_partner. This creates inconsistent behavior where the function could return early even when a valid sales_partner override is passed.
| invoice_count = get_invoice_count(doc) | ||
|
|
||
| sales_partner = doc.sales_partner | ||
| sales_partner = doc.sales_partner if not sales_partner else sales_partner |
Copilot
AI
Jan 7, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The ternary expression logic is inverted. It currently reads "use doc.sales_partner if sales_partner parameter is falsy, otherwise use sales_partner parameter", which means it only uses the override when it's truthy. However, the condition 'if not sales_partner' evaluates to True when sales_partner is None/empty, so the expression should be 'sales_partner if sales_partner else doc.sales_partner' to properly prioritize the override parameter when it's provided.
Description
This pull request introduces several enhancements and fixes to the affiliate referral and sales invoice handling logic, as well as updates to the data model and event hooks. The main improvements include more robust affiliate referral management, better handling of returns, and improved data consistency for affiliate tracking.
Affiliate Referral and Sales Invoice Logic Improvements:
insert_manual_affiliate_referralinaffiliate_referral.pyto allow manual creation of affiliate referrals with validation for positive amounts and valid affiliates.apply_referral_fee_rulesfunction insales_invoice.pyto accept an optionalsales_partnerparameter, improving flexibility and code clarity. [1] [2]on_submitevent insales_invoice.pythat voids affiliate referrals associated with returned invoices.Data Model and Fixtures Updates:
custom_affiliatelink field to theSubscriptiondoctype, allowing subscriptions to be directly associated with affiliates.First Costfield in theSubscriptiondoctype for better UI consistency.title_fieldand enabledshow_title_field_in_linkfor theSales Partnerdoctype, improving display and selection in the UI.is_manualfield in the list of fields forAffiliate Referralto ensure proper tracking of manually created referrals.Event Hooks and Business Logic Integration:
on_submitinSales Invoiceandbefore_insertinSubscriptionto ensure custom business logic is executed at appropriate lifecycle stages.subscription_override.pyto assign the linked affiliate from the subscription to the generated invoice, ensuring accurate affiliate attribution.Relevant Technical Choices
Testing Instructions
Additional Information:
Screenshot/Screencast
Checklist