fix: dynamic due date when payment terms are fetched from order#23
fix: dynamic due date when payment terms are fetched from order#23ljain112 wants to merge 5 commits into
Conversation
WalkthroughThe method Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~15 minutes Poem
Note ⚡️ Unit Test Generation is now available in beta!Learn more here, or try it out under "Finishing Touches" below. 📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (4)
✅ Files skipped from review due to trivial changes (1)
🚧 Files skipped from review as they are similar to previous changes (3)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
✨ Finishing Touches
🧪 Generate unit tests
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
2254e49 to
dd78aa4
Compare
There was a problem hiding this comment.
Actionable comments posted: 4
🧹 Nitpick comments (1)
erpnext/accounts/doctype/payment_schedule/payment_schedule.json (1)
22-25: Minor ordering nit – consider showing “Discount Type” after “Discount” in the UI as well
field_ordernow placesdiscount_typeafterdiscount, but the DocField definitions still appear withdiscount_typefirst (Lines 125-137 vs 133-137). Not functionally wrong, yet aligning definition order withfield_orderreduces cognitive load when reading the JSON.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (4)
erpnext/accounts/doctype/payment_schedule/payment_schedule.json(3 hunks)erpnext/accounts/doctype/payment_schedule/payment_schedule.py(1 hunks)erpnext/controllers/accounts_controller.py(4 hunks)erpnext/selling/doctype/sales_order/test_sales_order.py(3 hunks)
✅ Files skipped from review due to trivial changes (1)
- erpnext/accounts/doctype/payment_schedule/payment_schedule.py
🚧 Files skipped from review as they are similar to previous changes (2)
- erpnext/selling/doctype/sales_order/test_sales_order.py
- erpnext/controllers/accounts_controller.py
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
- GitHub Check: Patch Test
🔇 Additional comments (1)
erpnext/accounts/doctype/payment_schedule/payment_schedule.json (1)
13-18: Field-order update aligns with the new calculation logicMoving
invoice_portionahead of the newly-added credit & due-date fields keeps related attributes grouped and should make the form easier to scan.
| "fetch_from": "payment_term.due_date_based_on", | ||
| "fetch_if_empty": 1, | ||
| "fieldname": "due_date_based_on", | ||
| "fieldtype": "Select", | ||
| "label": "Due Date Based On", | ||
| "options": "\nDay(s) after invoice date\nDay(s) after the end of the invoice month\nMonth(s) after the end of the invoice month" | ||
| }, |
There was a problem hiding this comment.
🛠️ Refactor suggestion
Remove the leading newline in options to avoid an empty select entry
The first character in the options string is \n, which introduces a blank option in the drop-down:
- "options": "\nDay(s) after invoice date\nDay(s) after the end of the invoice month\nMonth(s) after the end of the invoice month"
+ "options": "Day(s) after invoice date\nDay(s) after the end of the invoice month\nMonth(s) after the end of the invoice month"Having an empty option can break validation when the field is marked mandatory or when downstream code assumes a non-blank value.
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| "fetch_from": "payment_term.due_date_based_on", | |
| "fetch_if_empty": 1, | |
| "fieldname": "due_date_based_on", | |
| "fieldtype": "Select", | |
| "label": "Due Date Based On", | |
| "options": "\nDay(s) after invoice date\nDay(s) after the end of the invoice month\nMonth(s) after the end of the invoice month" | |
| }, | |
| "fetch_from": "payment_term.due_date_based_on", | |
| "fetch_if_empty": 1, | |
| "fieldname": "due_date_based_on", | |
| "fieldtype": "Select", | |
| "label": "Due Date Based On", | |
| "options": "Day(s) after invoice date\nDay(s) after the end of the invoice month\nMonth(s) after the end of the invoice month" | |
| }, |
🤖 Prompt for AI Agents
In erpnext/accounts/doctype/payment_schedule/payment_schedule.json between lines
182 and 188, the "options" field for "due_date_based_on" starts with a newline
character, causing an empty option in the select dropdown. Remove the leading
newline so the options string begins directly with the first option to prevent
an empty select entry and avoid validation issues.
| "fetch_if_empty": 1, | ||
| "fieldname": "credit_days", | ||
| "fieldtype": "Int", | ||
| "label": "Credit Days", | ||
| "non_negative": 1 | ||
| }, | ||
| { | ||
| "fetch_if_empty": 1, | ||
| "fieldname": "credit_months", | ||
| "fieldtype": "Int", | ||
| "label": "Credit Months", | ||
| "non_negative": 1 | ||
| }, |
There was a problem hiding this comment.
Replace non-standard non_negative flag with the supported min property
Frappe DocFields don’t recognise non_negative; the framework silently ignores unknown keys, so the restriction will not be enforced.
- "fieldtype": "Int",
- "label": "Credit Days",
- "non_negative": 1
+ "fieldtype": "Int",
+ "label": "Credit Days",
+ "min": 0Apply the same change to credit_months (Lines 197-202) and keep the user from entering negative values.
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| "fetch_if_empty": 1, | |
| "fieldname": "credit_days", | |
| "fieldtype": "Int", | |
| "label": "Credit Days", | |
| "non_negative": 1 | |
| }, | |
| { | |
| "fetch_if_empty": 1, | |
| "fieldname": "credit_months", | |
| "fieldtype": "Int", | |
| "label": "Credit Months", | |
| "non_negative": 1 | |
| }, | |
| { | |
| "fetch_if_empty": 1, | |
| "fieldname": "credit_days", | |
| "fieldtype": "Int", | |
| "label": "Credit Days", | |
| "min": 0 | |
| }, | |
| { | |
| "fetch_if_empty": 1, | |
| "fieldname": "credit_months", | |
| "fieldtype": "Int", | |
| "label": "Credit Months", | |
| "min": 0 | |
| }, |
🤖 Prompt for AI Agents
In erpnext/accounts/doctype/payment_schedule/payment_schedule.json between lines
190 and 202, replace the unsupported "non_negative" flag with the supported
"min" property set to 0 for both "credit_days" and "credit_months" fields. This
change will enforce the restriction preventing users from entering negative
values as intended.
| "fetch_from": "payment_term.discount_validity_based_on", | ||
| "fetch_if_empty": 1, | ||
| "fieldname": "discount_validity_based_on", | ||
| "fieldtype": "Select", | ||
| "label": "Discount Validity Based On", | ||
| "options": "\nDay(s) after invoice date\nDay(s) after the end of the invoice month\nMonth(s) after the end of the invoice month" | ||
| }, |
There was a problem hiding this comment.
🛠️ Refactor suggestion
Duplicate newline in discount_validity_based_on.options – same issue as above
- "options": "\nDay(s) after invoice date\nDay(s) after the end of the invoice month\nMonth(s) after the end of the invoice month"
+ "options": "Day(s) after invoice date\nDay(s) after the end of the invoice month\nMonth(s) after the end of the invoice month"📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| "fetch_from": "payment_term.discount_validity_based_on", | |
| "fetch_if_empty": 1, | |
| "fieldname": "discount_validity_based_on", | |
| "fieldtype": "Select", | |
| "label": "Discount Validity Based On", | |
| "options": "\nDay(s) after invoice date\nDay(s) after the end of the invoice month\nMonth(s) after the end of the invoice month" | |
| }, | |
| "fetch_from": "payment_term.discount_validity_based_on", | |
| "fetch_if_empty": 1, | |
| "fieldname": "discount_validity_based_on", | |
| "fieldtype": "Select", | |
| "label": "Discount Validity Based On", | |
| "options": "Day(s) after invoice date\nDay(s) after the end of the invoice month\nMonth(s) after the end of the invoice month" | |
| }, |
🤖 Prompt for AI Agents
In erpnext/accounts/doctype/payment_schedule/payment_schedule.json around lines
204 to 210, the "options" field for "discount_validity_based_on" contains a
duplicate leading newline character. Remove the extra newline at the start of
the options string so that the options begin immediately without an empty line.
| "fetch_from": "payment_term.discount_validity", | ||
| "fetch_if_empty": 1, | ||
| "fieldname": "discount_validity", | ||
| "fieldtype": "Int", | ||
| "label": "Discount Validity" | ||
| } |
There was a problem hiding this comment.
🛠️ Refactor suggestion
Enforce non-negative value on discount_validity as well
Follow the same pattern as credit_days / credit_months to keep data clean:
- "fieldtype": "Int",
- "label": "Discount Validity"
+ "fieldtype": "Int",
+ "label": "Discount Validity",
+ "min": 0📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| "fetch_from": "payment_term.discount_validity", | |
| "fetch_if_empty": 1, | |
| "fieldname": "discount_validity", | |
| "fieldtype": "Int", | |
| "label": "Discount Validity" | |
| } | |
| "fetch_from": "payment_term.discount_validity", | |
| "fetch_if_empty": 1, | |
| "fieldname": "discount_validity", | |
| "fieldtype": "Int", | |
| "label": "Discount Validity", | |
| "min": 0 | |
| } |
🤖 Prompt for AI Agents
In erpnext/accounts/doctype/payment_schedule/payment_schedule.json around lines
212 to 217, the discount_validity field lacks validation to prevent negative
values. Add a validation rule similar to credit_days and credit_months by
including a "depends_on" or "validate" property that enforces discount_validity
to be zero or positive, ensuring data integrity.
b56ef91 to
81dd6d3
Compare
Summary by CodeRabbit