-
Notifications
You must be signed in to change notification settings - Fork 2
Test PR from ForkPilot - Add test_common_module.py #6
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
base: develop
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| # Common Module - Present in Main Repository | ||
| # This is a shared module that should be present in all forks | ||
|
|
||
| def validate_email(email): | ||
| """Basic email validation""" | ||
| if '@' not in email or '.' not in email: | ||
| return False, "Invalid email format" | ||
| return True, "Valid email" | ||
|
|
||
| def calculate_tax(amount, tax_rate=18): | ||
| """Standard tax calculation""" | ||
| return (amount * tax_rate) / 100 | ||
|
Comment on lines
+10
to
+12
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🏁 Script executed: #!/bin/bash
# Verify how monetary precision is handled in existing tax logic.
rg -n --type=py -C2 '\b(flt|precision|Decimal)\b'
rg -n --type=py -C2 '\bcalculate_tax\s*\('Repository: aerele/erpnext Length of output: 50372 🏁 Script executed: # Check if test_common_module.py exists
find . -name "test_common_module.py" -type f
# Search for tax calculation functions in the codebase
rg -n "def calculate_tax" --type=py
# Check common patterns for tax calculations in ERPNext
rg -n "tax.*\*.*100|rate.*\*.*100" --type=py -C 2 | head -100Repository: aerele/erpnext Length of output: 8795 🏁 Script executed: # Read the actual file to see the implementation
sed -n '1,20p' ./erpnext/test_common_module.pyRepository: aerele/erpnext Length of output: 459 🏁 Script executed: # Find the flt function definition
rg -n "^def flt" --type=py
# Look for flt import location
rg -n "from.*flt|import.*flt" erpnext/test_common_module.py
# Check if there are existing tax calculations that use Decimal
rg -n "from decimal import|Decimal" --type=py | head -20
# Look at how tax calculations are done in ERPNext (focus on precision)
rg -n "tax.*flt|flt.*tax" --type=py -C 2 | head -50Repository: aerele/erpnext Length of output: 4798 🏁 Script executed: # Search for where flt is defined and what it does
rg "from frappe.utils import.*flt" erpnext/ --type=py | head -5
# Check if any tax calculation validates negative values
rg -n "tax.*<.*0|amount.*<.*0|negative" erpnext/controllers/ --type=py -C 2 | head -40
# Search for Decimal usage in financial calculations
rg -n "from decimal import|import decimal" erpnext/ --type=py | grep -v test | head -20Repository: aerele/erpnext Length of output: 3952 🏁 Script executed: # Check if test_common_module is imported or used anywhere
rg "from.*test_common_module|import.*test_common_module" --type=py
# Check what flt actually does - look for its definition in frappe context
rg "def flt" --type=py
# Check actual usage patterns of flt for tax calculations in real code
rg -B2 -A2 "tax_amount.*flt|flt.*tax_amount" --type=py | head -60Repository: aerele/erpnext Length of output: 4947 🏁 Script executed: # Check the directory structure and what test_common_module is
head -1 ./erpnext/test_common_module.py
ls -la ./erpnext/test_common_module.py
file ./erpnext/test_common_module.py
# Search to see if it's referenced in __init__ or setup files
rg "test_common" --type=py
# Look at the region implementations more closely to see the pattern
cat -n erpnext/regional/italy/utils.py | sed -n '20,35p'Repository: aerele/erpnext Length of output: 1184 Use ERPNext's standard Line 12 returns a raw float without precision handling, which can introduce rounding errors in currency calculations. Also add input validation for negative values. The codebase standard for tax calculations (e.g., Suggested fix+from frappe.utils import flt
+
def calculate_tax(amount, tax_rate=18):
"""Standard tax calculation"""
- return (amount * tax_rate) / 100
+ if amount < 0 or tax_rate < 0:
+ raise ValueError("amount and tax_rate must be non-negative")
+ return flt((amount * tax_rate) / 100, 2)🤖 Prompt for AI Agents |
||
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.
🧩 Analysis chain
🏁 Script executed:
Repository: aerele/erpnext
Length of output: 2506
Use the framework email validator; current implementation is too weak and inconsistent with codebase patterns.
The validation at line 6 accepts invalid addresses (e.g., "test@.com") and fails on non-string input with a TypeError. Align with the established ERPNext pattern using
validate_email_addressfromfrappe.utils.Proposed fix
📝 Committable suggestion
🤖 Prompt for AI Agents