Skip to content

COHIV-203: Refactor Report configuration and NK report#383

Draft
MarcoSteinacher wants to merge 42 commits into
developfrom
dev/COHIV-203/refactor_nk_config
Draft

COHIV-203: Refactor Report configuration and NK report#383
MarcoSteinacher wants to merge 42 commits into
developfrom
dev/COHIV-203/refactor_nk_config

Conversation

@MarcoSteinacher

Copy link
Copy Markdown
Member

I confirm that I have read the Contributor Agreement v1.1, agree to be bound on them and confirm that my contribution is compliant.

AlwinEgger and others added 30 commits March 17, 2026 11:42
NkCost.get_section_weights() was returning equal weights (1.0) for all
sections, ignoring the section_weights profile configured per cost item.
It now looks up the profile from the report's section_weights dict and
applies the correct weight per section (matched via section.id.capitalize()).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Tests two NkTotalCost instances side-by-side:
- "Wasser_Abwasser" with default section weights (all sections at 1.0),
  verifying costs are split purely by area
- "Reinigung" with "reinigung" section weights (Wohnen=0.7, Gewerbe=1.0,
  Lager=1.0, Allgemein=0.0), verifying the section weight scales the
  rental unit's effective area when distributing costs

Both individual rental unit costs and section totals are asserted.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Calculates costs individually per rental unit rather than distributing
a total amount. Mirrors the logic from the old report_nk.internetrechnung():

- Fixed fee per rental unit name (from config key fixed_fees_key)
- Or: fee_per_unit + min_occupancy × fee_per_person (from config keys
  fee_per_unit_key / fee_per_person_key)
- Monthly amounts are scaled by get_monthly_weights()
- split_costs() aggregates the per-unit amounts up to sections and total
  instead of distributing a total downward via weights

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- Path 1 (fixed fee): G001 configured with a fixed 100 CHF/month via
  Internet:Tarif:Fix, verified against 100 × num_months
- Path 2 (per-unit + per-person × min_occupancy): 001a (min_occupancy=3)
  and 001b (min_occupancy=1) verified using Internet:Tarif:ProWohnung and
  Internet:Tarif:ProPerson config values
- Path 3 (zero): G002 with no min_occupancy and no fixed fee → 0
- Section and grand totals verified to aggregate correctly from rental units

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- Add NkCostZEVStromallmend (cost/zev.py): new NkCost subclass implementing
  ZEV electricity cost calculation per rental unit, mirroring the logic of
  the old report_nk.stromrechnung(). Reads measurement data from
  report.object_messung[ru.name] and building totals from report.data_amount,
  computes eigenverbrauch solar, netzstrom, HKN, and corrections.

- Add NkCost.get_extra_context() hook (cost/base.py): base class returns {}
  by default; subclasses can override to inject extra variables into the ODT
  bill template context beyond the standard billing-group fields.

- Modify NkBill._get_rental_unit_context() (bill.py): after building the
  costs list, call get_extra_context() on every cost and merge the result
  into the context dict, enabling NkCostZEVStromallmend to inject the
  ssd_*, sss_*, snh_*, snt_*, shk_*, sk_*, st_*, stot_* variables required
  by the Stromkosten section of the ODT template.

- Add tests (tests/test_nk_zev.py): three test cases covering correct
  per-unit cost calculation, extra-context variable generation, and the
  no-measurement-data zero case.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
AlwinEgger and others added 12 commits May 21, 2026 10:25
- Add ReportInput choice fields for enums
- Add enums for weights
- Fix report config default value issue
- Add monthly weights
- Add base settings report item
- Separate config structure `get_report_item_config()` from the actual
  costs config `get_costs_from_config()`
- Flattened measurement data config
- Replaced INPUT_KEY fields with actual value fields
@coderabbitai

coderabbitai Bot commented Jul 12, 2026

Copy link
Copy Markdown

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 0fad2e02-11c7-41b6-9ff4-5e5dc578cebc

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch dev/COHIV-203/refactor_nk_config

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.

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.

2 participants