Skip to content

Conversation

@vorasmit
Copy link
Collaborator

@vorasmit vorasmit commented Nov 28, 2025

Issue

In Production Plan -> When multiple sales orders exist for same item -> Calculates incorrect Raw Materials Required (when Consider Projected Qty in Calculation is checked)

Say: Projected Qty of Raw Materials is 12 Units. Required Qty: 13 Units (12+1) in two rows.
Available qty not cascading over rows, and material Request Qty was set as Zero

Fix

Track consumed qty over the rows

Before

image

After

With-Fix.mp4

@github-actions github-actions bot added the needs-tests This PR needs automated unit-tests. label Nov 28, 2025
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Nov 28, 2025

📝 Walkthrough

Walkthrough

This pull request changes production plan material-request calculations to track consumed quantities per (item_code, warehouse) instead of a global per-item total. The get_material_request_items signature replaces total_qty with consumed_qty (a defaultdict keyed by (item_code, warehouse)) and call sites are updated to propagate and update this per-location consumption when projecting available quantity. A new test, test_projected_qty_cascading_across_multiple_sales_orders, is added to validate cascading projected requirements across multiple sales orders and related stock reconciliation behavior.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

  • Mixed edits: function signature change, propagation of a new parameter through nested calls, and an added test.
  • Areas needing extra attention:
    • erpnext/manufacturing/doctype/production_plan/production_plan.py — correctness of consumed_qty keying, initialization, update logic when projecting available qty, and all updated call sites.
    • erpnext/manufacturing/doctype/production_plan/test_production_plan.py — validity of the new test scenario and teardown (stock reconciliation cancel).
    • Search for any remaining call sites or external integrations still expecting the old total_qty parameter.

Possibly related PRs

  • Fix/Support 50220 #49960 — Modifies production_plan quantity aggregation logic; likely related to reserved/projected quantity handling that interacts with the per-(item,warehouse) consumption changes.

Suggested reviewers

  • rohitwaghchaure
  • mihir-kandoi

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 40.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The PR title accurately summarizes the main change: fixing cascading of projected quantity across multiple items in material requests, which directly addresses the core issue described in the PR objectives.
Description check ✅ Passed The PR description clearly explains the issue, provides a concrete example, outlines the fix (tracking consumed qty across rows), and includes before/after assets demonstrating the problem and solution.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

coderabbitai[bot]

This comment was marked as resolved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport version-15-hotfix needs-tests This PR needs automated unit-tests.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant