Skip to content

Add alpha_numeric widget for nullable numeric fields with special code support - #96

Draft
agrogers with Copilot wants to merge 3 commits into
mainfrom
copilot/create-numeric-widget-for-null-values
Draft

Add alpha_numeric widget for nullable numeric fields with special code support#96
agrogers with Copilot wants to merge 3 commits into
mainfrom
copilot/create-numeric-widget-for-null-values

Conversation

Copilot AI commented May 3, 2026

Copy link
Copy Markdown
Contributor

Odoo float fields cannot hold NULL — the sentinel hack (-0.01) works for blank display but breaks down when scores need to carry semantic meaning like "Absent" or "Cheating". This adds a proper solution: a paired Char field (score_alpha) that holds either a formatted number or a configurable special code, keeping the underlying float field in sync automatically.

Widget (alpha_numeric)

New OWL field widget registered as "alpha_numeric" for char fields:

  • Accepts numbers or configurable special codes (default: ["-", "A", "C"])
  • Formats numbers on display via decimal_places + use_separator options
  • Auto-derives the paired numeric field from the _alpha suffix convention (score_alphascore); overridable via numeric_field option
  • Writes both fields atomically on commit — special codes write sentinel to the float, numbers write the parsed value
  • Falls back to displaying the numeric field's value for pre-existing records (backward compat)
  • Inline validation error; Enter commits, Escape cancels; works in editable list and form views
<field name="score_alpha"
       widget="alpha_numeric"
       options="{'allowed_codes': ['-', 'A', 'C'],
                 'decimal_places': 2,
                 'use_separator': false}"/>

Python model (aps.resource.submission)

  • score_alpha and out_of_marks_alpha Char fields added (both tracking=True)
  • Module-level alpha_to_float(val, sentinel) helper — parses number strings, returns sentinel for empty/special codes
  • @api.onchange handlers keep the numeric fields live during UI edits
  • write() override syncs alpha → numeric on programmatic saves (runs before the auto_score flag check so the flag is correctly set to False)

Migration (18.0.1.0.45)

Post-migration back-fills score_alpha / out_of_marks_alpha from existing float values using FM format with 6 decimal places to preserve precision.

Copilot AI linked an issue May 3, 2026 that may be closed by this pull request
Copilot AI and others added 2 commits May 3, 2026 16:04
…ews, migration

Agent-Logs-Url: https://github.com/agrogers/aps_sis/sessions/82516a2f-7fc6-4250-873b-170fd375d89c

Co-authored-by: agrogers <13920678+agrogers@users.noreply.github.com>
…on, add JSDoc

Agent-Logs-Url: https://github.com/agrogers/aps_sis/sessions/82516a2f-7fc6-4250-873b-170fd375d89c

Co-authored-by: agrogers <13920678+agrogers@users.noreply.github.com>
Copilot AI changed the title [WIP] Create numeric widget that handles null values and formatting Add alpha_numeric widget for nullable numeric fields with special code support May 3, 2026
Copilot AI requested a review from agrogers May 3, 2026 16:07
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.

Create a numeric widget that handles null values

2 participants