Add "Trim Zeros" option to Record Formatter fields#7080
Conversation
|
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 |
emenslin
left a comment
There was a problem hiding this comment.
- 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.
Triggered by 8fa66d8 on branch refs/heads/issue-7037
Hmm I do think this is a pretty significant issue. Record formatters are pretty inconsistent in general. 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. |
Triggered by 20cb2e9 on branch refs/heads/issue-7037
Move comment
|
This PR has been reworked into a setting in Record Formatters. |
emenslin
left a comment
There was a problem hiding this comment.
- 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!
|
NOTE: The automatic linter has broken the UploadAttachment test again for some reason, must revert commit before merging. 909ef37 Still good for testing |
bhumikaguptaa
left a comment
There was a problem hiding this comment.
- 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!
Triggered by c349ff1 on branch refs/heads/issue-7037


Fixes #7037
Adds a new property called
trimZerosto 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-explanatory (or properly documented)
Testing instructions