Skip to content

Conversation

@silasg
Copy link

@silasg silasg commented Jan 2, 2026

Summary

  • Add default_unit field to Space model for use in property calculations when an ingredient has no unit
  • When an ingredient has no unit but the space has a default unit configured, use it for property calculations
  • Show missing_conversion details (not missing_unit) when default unit exists but conversion is missing -- just like for a configured unit without conversion
  • Refactor property calculation logic to extract _try_calculate_property helper method

Changes

Backend

  • Model: Added default_unit ForeignKey to Space (nullable, SET_NULL)
  • Serializer: Moved UnitSerializer earlier in file to use in SpaceSerializer
  • Property Helper: Use space's default_unit when ingredient has no unit
  • Property Helper: Extracted _try_calculate_property to reduce code duplication

Frontend

  • SpaceEditor: Added UI to select default unit
  • Translations: Added English and German translations

Test Plan

  • Added 4 new test cases covering:
    • Default unit with working conversion
    • No default unit (marks missing_unit)
    • Default unit but missing conversion (shows missing_conversion details)
    • Default unit matches property unit (no conversion needed)
  • Migration tested

Partially fixes #4009 (I did not touch the display logic)

Notes

I am neither a Vue nor a Python developer. So I used an LLM to help me with the implementation, reviewed and revised the results. But still I don't know what I don't know so please review the PR carefully.

silasg and others added 2 commits January 1, 2026 18:11
Backend changes only:
- Add default_unit field to Space model
- Use default_unit in property calculations when ingredient has no unit
- Show missing_conversion details (not missing_unit) when default unit
  exists but conversion is missing

Does not include frontend display changes for missing_conversion.

Related to TandoorRecipes#4009

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <[email protected]>
Extract duplicated property calculation logic into a reusable helper
method. The calculation for explicit unit and default unit cases was
nearly identical - now both use the same _try_calculate_property method.

Also improves readability by using early returns (continue) and clearer
comments for each error handling case.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <[email protected]>
@CLAassistant
Copy link

CLAassistant commented Jan 2, 2026

CLA assistant check
All committers have signed the CLA.

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.

Default unit for countable foods w/ option to hide it

2 participants