Skip to content

Add "Trim Zeros" option to Record Formatter fields#7080

Merged
alesan99 merged 29 commits intomainfrom
issue-7037
Aug 18, 2025
Merged

Add "Trim Zeros" option to Record Formatter fields#7080
alesan99 merged 29 commits intomainfrom
issue-7037

Conversation

@alesan99
Copy link
Contributor

@alesan99 alesan99 commented Jul 15, 2025

Fixes #7037

image

Adds a new property called trimZeros to DataObjFormatters that removes leading zeros from any field, as long as it can be cast to a number.

DEV Notes:

As described in the issue, leading zeros were being removed at one point.
However, it looked like a side effect of catalogNumbers being cast to numbers for the purpose of reports. Rather than restoring the original behavior, I opted to add a new setting so its consistent everywhere in the app.

BUT, I did add an option internally to restore the original behavior with the new ObjectFormatterProps. This was the original purpose of this PR, but I left it unused since it doesn't look like the existing behavior has caused any issues yet.

The regression was introduced by Batch Edit 8b2433f (This code was used in #5417).

        else:
            new_query, table, model, specify_field = query.build_join(
                specify_model, orm_table, formatter_field_spec.join_path)
-           new_expr = self._fieldformat(formatter_field_spec.get_field(),
-                                        getattr(table, specify_field.name))
+           new_expr = getattr(table, specify_field.name)

Though its described as just a refactor in the commit, it may be necessary for Batch edit. Re-adding it breaks certain formatters on Batch-edit, so this PR explicitly disables _fieldformat for BE.

Checklist

  • Self-review the PR after opening it to make sure the changes look good and
    self-explanatory (or properly documented)
  • Add relevant issue to release milestone
  • Add pr to documentation list
  • Add automated tests

Testing instructions

  • Enable "Trim Zeros" on the catalog number field in the Record Formatter for Collection Object.
    • Go to App Resources and edit the record formatter for Collection Object.
    • Click the gear and click
    • (Optional) Add any separator to the catalogNumber field. I used CO.
    • Create a new query for Collection Objects.
  • Make sure the configuration button works as expected.
  • Make sure the preview is accurate.
  • Create a new query for CO.
  • Add Formatted and catalogNumber.
  • Query
  • The formatted CO should have no leading zeroes on the catalogNumber. The catalogNumber by itself should appear normally.
  • Make sure the zeros are removed as they were before v7.10.2 in any other contexts you can think of, like exports and reports.
  • Make sure zeros are being trimmed even if you have a COT with a non-numeric format in your database.
  • Try a non-numeric catalogNumber format
  • Make sure this doesn't affect formatted COs with non-numeric CatalogNumber formats, like YEAR-######. For example,
  • Make sure the zeros are removed as they were before v7.10.2 in any other contexts you can think of, like exports and reports.
  • Make sure Batch Edit still works. One simple test should be enough.
    • BE with the following fields could potentially be affected: Agent's agenttype, fields with picklists, booleans, numeric catalognumbers.
  • Make sure queries with Agent Type or any picklist work.

@alesan99 alesan99 added this to the 7.11.2 milestone Jul 15, 2025
@github-project-automation github-project-automation bot moved this to 📋Back Log in General Tester Board Jul 15, 2025
@alesan99 alesan99 marked this pull request as draft July 15, 2025 15:29
@alesan99 alesan99 marked this pull request as ready for review July 16, 2025 18:53
@alesan99 alesan99 requested review from a team July 16, 2025 19:11
@specifysoftware
Copy link

This pull request has been mentioned on Specify Community Forum. There might be relevant details there:

https://discourse.specifysoftware.org/t/formatted-catalog-number-in-dwca-export/2697/9

@melton-jason melton-jason self-requested a review July 18, 2025 18:38
Copy link
Collaborator

@emenslin emenslin left a comment

Choose a reason for hiding this comment

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

  • The formatted CO should have no leading zeroes on the catalogNumber. The catalogNumber by itself should appear normally.
  • Make sure COs appears the same as it did before v7.10.2 in any other contexts you can think of, like exports and reports.
  • Make sure this doesn't affect formatted COs with non-numeric CatalogNumber formats, like YEAR-######. For example, COs with a YEAR-###### catalogNumber should display as COYEAR-000001.
  • If you have a COT with a non-numeric format, any COT with a numeric format should now include leading zeroes again.
  • Do some general testing with Batch Edit.
    • BE with the following fields could potentially be affected: Agent's agenttype, fields with picklists, booleans, numeric catalognumbers.

Everything looks good with queries and reports, however, the top of the CO form and the deletion dialog shows the formatted number with the leading zeros.

Issue branch:
Screenshot 2025-08-01 095541

7.9.6.2:
image

@github-project-automation github-project-automation bot moved this from 📋Back Log to Dev Attention Needed in General Tester Board Aug 1, 2025
@alesan99
Copy link
Contributor Author

alesan99 commented Aug 5, 2025

Everything looks good with queries and reports, however, the top of the CO form and the deletion dialog shows the formatted number with the leading zeros.

Hmm I do think this is a pretty significant issue. Record formatters are pretty inconsistent in general.
While its enough to have the formatters display correctly in reports, I would like them to appear the same in every context. Having the preview in app resources actually be correct would be a big benefit.

In order to make it a little more consistent I think I should rework this PR so removing leading zeroes can be a per-field option in a record formatter.

@alesan99 alesan99 marked this pull request as draft August 6, 2025 18:31
@alesan99 alesan99 marked this pull request as ready for review August 11, 2025 20:16
@alesan99
Copy link
Contributor Author

This PR has been reworked into a setting in Record Formatters.
Ready to be tested again 👍

@alesan99 alesan99 requested review from a team and emenslin August 12, 2025 15:18
Copy link
Collaborator

@emenslin emenslin left a comment

Choose a reason for hiding this comment

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

  • Make sure the configuration button works as expected.
  • Make sure the preview is accurate.
  • The formatted CO should have no leading zeroes on the catalogNumber. The catalogNumber by itself should appear normally.
  • Make sure the zeros are removed as they were before v7.10.2 in any other contexts you can think of, like exports and reports.
  • Make sure zeros are being trimmed even if you have a COT with a non-numeric format in your database.
  • Make sure this doesn't affect formatted COs with non-numeric CatalogNumber formats, like YEAR-######. For example,
  • Make sure the zeros are removed as they were before v7.10.2 in any other contexts you can think of, like exports and reports.
  • Make sure Batch Edit still works. One simple test should be enough.
  • Make sure queries with Agent Type or any picklist work.

Looks good, preference trims zeros for numeric catalog numbers!

@emenslin emenslin requested a review from a team August 12, 2025 18:13
@alesan99
Copy link
Contributor Author

alesan99 commented Aug 12, 2025

NOTE: The automatic linter has broken the UploadAttachment test again for some reason, must revert commit before merging. 909ef37

Still good for testing

Copy link
Collaborator

@bhumikaguptaa bhumikaguptaa left a comment

Choose a reason for hiding this comment

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

  • Make sure the configuration button works as expected.
  • Make sure the preview is accurate.
  • The formatted CO should have no leading zeroes on the catalogNumber. The catalogNumber by itself should appear normally.
  • Make sure the zeros are removed as they were before v7.10.2 in any other contexts you can think of, like exports and reports.
  • Make sure zeros are being trimmed even if you have a COT with a non-numeric format in your database.
  • Make sure this doesn't affect formatted COs with non-numeric CatalogNumber formats, like YEAR-######. For example,
  • Make sure the zeros are removed as they were before v7.10.2 in any other contexts you can think of, like exports and reports.
  • Make sure Batch Edit still works. One simple test should be enough.
    • BE with the following fields could potentially be affected: Agent's agenttype, fields with picklists, booleans, numeric catalognumbers.
  • Make sure queries with Agent Type or any picklist work.

Everything works as expected!

@bhumikaguptaa bhumikaguptaa requested a review from a team August 14, 2025 15:49
@alesan99 alesan99 merged commit 434f7ee into main Aug 18, 2025
14 checks passed
@alesan99 alesan99 deleted the issue-7037 branch August 18, 2025 13:30
@github-project-automation github-project-automation bot moved this from Dev Attention Needed to ✅Done in General Tester Board Aug 18, 2025
melton-jason added a commit that referenced this pull request Oct 24, 2025
grantfitzsimmons pushed a commit that referenced this pull request Oct 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: ✅Done

Development

Successfully merging this pull request may close these issues.

Catalog number formatting discrepancy between 7.10 and 7.11

6 participants