Skip to content

Fix crop residue visibility condition and calculations#569

Merged
SvenVw merged 6 commits into
mainfrom
hotfix/FDM568
Apr 16, 2026
Merged

Fix crop residue visibility condition and calculations#569
SvenVw merged 6 commits into
mainfrom
hotfix/FDM568

Conversation

@SvenVw
Copy link
Copy Markdown
Collaborator

@SvenVw SvenVw commented Apr 15, 2026

Summary by CodeRabbit

  • Bug Fixes

    • Fixed crop residue field visibility to properly depend on crop rotation type instead of another field.
    • Improved organic matter supply calculations when crop residue values are not specified.
  • Tests

    • Added test coverage for crop residue handling in nitrogen removal calculations.
    • Added test coverage for crop residue handling in organic matter supply calculations.

Closes #568

SvenVw added 3 commits April 15, 2026 09:26
…residues yielded zero supply; it now correctly calculates supply for residues that are not explicitly removed.
…ation category (`b_lu_croprotation === 'cereal'`) and ensure its default value is `undefined` when hidden.
@SvenVw SvenVw self-assigned this Apr 15, 2026
@github-actions
Copy link
Copy Markdown
Contributor

👋 Hotfix Branch PR Detected!

Before merging this Pull Request into main, please ensure you have finalized the hotfix by manually running the 'Release' workflow on this hotfix/FDM568 branch.

This will:

  1. Bump package versions.
  2. Generate changelogs.
  3. Create Git tags.

You can trigger the workflow from the 'Actions' tab, selecting the 'Release' workflow, and choosing this hotfix/FDM568 branch.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 15, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: a82cde9f-b8ed-42ec-9a26-d99133259311

📥 Commits

Reviewing files that changed from the base of the PR and between f6ca306 and dee15e2.

📒 Files selected for processing (4)
  • fdm-app/CHANGELOG.md
  • fdm-app/package.json
  • fdm-calculator/CHANGELOG.md
  • fdm-calculator/package.json
✅ Files skipped from review due to trivial changes (4)
  • fdm-calculator/package.json
  • fdm-app/package.json
  • fdm-calculator/CHANGELOG.md
  • fdm-app/CHANGELOG.md

📝 Walkthrough

Walkthrough

This PR fixes crop residue visibility and calculation logic by conditionally showing the "Gewasresten achterlaten" checkbox only for cereal crops based on b_lu_croprotation, setting the field value to undefined when hidden, and updating balance calculations to treat undefined as "residues left on field" rather than removed.

Changes

Cohort / File(s) Summary
UI Form Layer
fdm-app/app/components/blocks/cultivation/card-details.tsx, fdm-app/app/components/blocks/rotation/columns.tsx
Changed residue checkbox visibility condition from b_lu_eom_residue to b_lu_croprotation === 'cereal'. Updated default value from false to undefined when field is hidden.
Balance Calculation Logic
fdm-calculator/src/balance/organic-matter/supply/residues.ts
Modified residue inclusion condition from truthy check (cult.m_cropresidue) to explicit false check (cult.m_cropresidue !== false), allowing undefined values to contribute organic matter supply.
Test Coverage
fdm-calculator/src/balance/nitrogen/removal/residue.test.ts, fdm-calculator/src/balance/organic-matter/supply/residues.test.ts
Added test cases verifying m_cropresidue: undefined correctly results in zero nitrogen removal and proper organic matter supply calculation.
Version Management
fdm-app/CHANGELOG.md, fdm-app/package.json, fdm-calculator/CHANGELOG.md, fdm-calculator/package.json
Bumped fdm-app to 0.29.5 and fdm-calculator to 0.13.2; documented fixes in respective changelog files.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested labels

bug, fdm-app, fdm-calculator, branch:main

Suggested reviewers

  • gerardhros
  • BoraIneviNMI

Poem

🐰 A residue riddle solved at last,
No more false defaults from the past!
Cereals shine when crops align,
And undefined means "left divine"—
The balance beams now truly fine. 🌾

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Linked Issues check ✅ Passed Pull request successfully addresses all UI and balance calculation requirements from issue #568, with appropriate visibility, value handling, and calculation fixes.
Out of Scope Changes check ✅ Passed All changes are directly aligned with issue #568 requirements; no out-of-scope modifications detected.
Title Check ✅ Passed Title check skipped as CodeRabbit has written the PR title.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch hotfix/FDM568

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 coderabbitai Bot changed the title @coderabbitai Fix crop residue visibility condition and calculations Apr 15, 2026
@sentry
Copy link
Copy Markdown

sentry Bot commented Apr 15, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
fdm-calculator/src/balance/organic-matter/supply/residues.ts (1)

39-42: Keep the function JSDoc in sync with the new !== false logic.

Implementation now treats undefined as “residues left,” but the top doc still implies only true qualifies. Please update the doc text to avoid future confusion.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@fdm-calculator/src/balance/organic-matter/supply/residues.ts` around lines 39
- 42, Update the JSDoc to reflect the actual logic: state that residues are
considered left unless cult.m_cropresidue is explicitly false (i.e., undefined
or true are treated as residues left), and that
cultivationDetail.b_lu_eom_residue must be present (not null/undefined) to
trigger residue handling; reference the variables
cultivationDetail?.b_lu_eom_residue and cult.m_cropresidue in the doc so future
readers understand the !== false check and the != null requirement.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@fdm-calculator/src/balance/organic-matter/supply/residues.ts`:
- Around line 39-42: Update the JSDoc to reflect the actual logic: state that
residues are considered left unless cult.m_cropresidue is explicitly false
(i.e., undefined or true are treated as residues left), and that
cultivationDetail.b_lu_eom_residue must be present (not null/undefined) to
trigger residue handling; reference the variables
cultivationDetail?.b_lu_eom_residue and cult.m_cropresidue in the doc so future
readers understand the !== false check and the != null requirement.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: fc25d04f-de1a-493b-b6d1-4f2a138cdf27

📥 Commits

Reviewing files that changed from the base of the PR and between c315b43 and 6fd2c63.

📒 Files selected for processing (7)
  • .changeset/fix-fdm-app-m-cropresidue.md
  • .changeset/fix-fdm-calculator-m-cropresidue.md
  • fdm-app/app/components/blocks/cultivation/card-details.tsx
  • fdm-app/app/components/blocks/rotation/columns.tsx
  • fdm-calculator/src/balance/nitrogen/removal/residue.test.ts
  • fdm-calculator/src/balance/organic-matter/supply/residues.test.ts
  • fdm-calculator/src/balance/organic-matter/supply/residues.ts

@SvenVw
Copy link
Copy Markdown
Collaborator Author

SvenVw commented Apr 15, 2026

@coderabbitai resume

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 15, 2026

✅ Actions performed

Reviews resumed.

@SvenVw SvenVw requested a review from BoraIneviNMI April 15, 2026 10:11
@SvenVw SvenVw linked an issue Apr 15, 2026 that may be closed by this pull request
6 tasks
@SvenVw SvenVw merged commit deea6e4 into main Apr 16, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Fix "Gewasresten achterlaten" visibility and residue removal calculation

1 participant