Skip to content

Refactor: select price fields for currency validation by type (PriceField)#2311

Open
Flix6x wants to merge 2 commits into
mainfrom
refactor/price-field
Open

Refactor: select price fields for currency validation by type (PriceField)#2311
Flix6x wants to merge 2 commits into
mainfrom
refactor/price-field

Conversation

@Flix6x

@Flix6x Flix6x commented Jul 13, 2026

Copy link
Copy Markdown
Member

Summary

Introduces a PriceField marker subclass of VariableQuantityField for monetary fields, and uses it in two ways:

  • FlexContextSchema._try_to_convert_price_units now selects fields by isinstance(field, PriceField) instead of the field[-5:] == "price" name-suffix convention. Same ten fields as before — but future price fields get currency validation by declaration rather than by naming discipline.
  • The nested commitment prices (up-price/down-price in CommitmentSchema) are now also declared as PriceFields and held to the flex-context's shared_currency_unit, which they previously escaped. A commitment price in a different currency now fails at deserialization with the usual example-unit hint (and commitments can establish the shared currency when no top-level price field does).

Since commitment prices may be per-energy or per-power, a small _extract_currency_unit helper obtains the currency part of a price unit regardless of denominator.

Relation to #2310

Split out from #2310, which builds on this to validate flex-model price fields (soc-value-at-end) against the flex-context currency. This PR is pure refactoring plus the commitments currency check and can land independently.

Tests

Three new FlexContextSchema cases: commitment price in USD vs EUR context (rejected), matching EUR prices incl. kWh-denominated (accepted), and mixed currencies within one commitment with no top-level price (rejected).

🤖 Generated with Claude Code

https://claude.ai/code/session_01LQFkeGxDwErydUV5ZmHmki

Flix6x and others added 2 commits July 14, 2026 00:14
Introduce a PriceField subclass of VariableQuantityField marking
monetary fields. The flex-context's shared-currency check now selects
fields by isinstance instead of the *price name-suffix convention, and
extends to the nested commitment prices (up-price/down-price), which
were previously not held to the flex-context's shared currency.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01LQFkeGxDwErydUV5ZmHmki
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01LQFkeGxDwErydUV5ZmHmki
@read-the-docs-community

Copy link
Copy Markdown

Documentation build overview

📚 flexmeasures | 🛠️ Build #33573222 | 📁 Comparing a6a3704 against latest (8d775f6)

  🔍 Preview build  

5 files changed · ± 5 modified

± Modified

@Flix6x

Flix6x commented Jul 13, 2026

Copy link
Copy Markdown
Member Author

I self-approve this, but maybe you also want to have a look @nhoening.

@Flix6x Flix6x added this to the 1.0.0 milestone Jul 13, 2026
@Flix6x Flix6x self-assigned this Jul 13, 2026
@Flix6x
Flix6x requested a review from nhoening July 13, 2026 22:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant