-
-
Notifications
You must be signed in to change notification settings - Fork 332
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add custom MATHESAR_TYPES.MONEY
type
#647
Conversation
TODO: fix server_default, then alter the associated tests
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mathemancer Looks good, the implementation is straightforward and easy to read.
I attempted to cast a VARCHAR
type (the data was numeric) to money via the column PATCH
API locally and received the following error:
[
"This type cast is not implemented"
]
It doesn't seem like we do any validating of currency yet, I'd also add that to your TODOs or create a separate issue for it.
I'm approving to unblock merge. If you want to make changes in a future PR, feel free to merge and do that.
I can't replicate this (i.e., when I cast a |
@mathemancer It works, sorry, I forgot to install the type. 🤦 We should be able to set the currency using |
I don't quite understand. Do you mean setting a default value for the currency part of the composite, or something else? It's not possible (using standard |
Given that users are going to be able to define their own currencies by inserting into the column, I'm not sure what validation would entail. I had given thought to a "validated money" type (associated with the implementation of inference), or even a few specific money types ( |
@mathemancer I'm referring to the following requirements (quoted from #417's description):
This is to make sure that whatever is inserted into the I'm not sure what the best way to get a list of currencies is, but my inclination is to use a Python package (https://github.com/kalaspuff/stockholm seems newer than the one in the issue description) and sync the currencies it provides to the DB on install, that way we can just update the package when we need to and we can also use it in Python for validation etc. I'm open to other ideas, though.
We decided against allowing the user to change the decimal precision in favor of the maximum (this should be documented in the issue, btw, please update the description) but they should still be able to change the currency. If the user wanted to alter their I'm not sure what the benefit of a currency-specific type would be. |
Also on a completely separate note, I think numeric types should be valid target types for money, we'd just use the numeric component to figure out how to convert the data. |
Agreed. |
Related to #417
This adds a basic composite type in the DB called
MATHESAR_TYPES.MONEY
. The composite type is:Technical details
At the API (and Python) level, we use JSON to represent an entry, for example:
Note that in the DB layer,
JSON
(andJSONB
) numbers are in factNUMERIC
types, so there shouldn't be any loss of precision in the translation at the DB layer. All conversion between JSON and the actual composite type is happening via SQL functions in the DB.The intent is to use the standard ISO 3-character codes to represent real currencies. If a user wants to use a custom currency, they can either create or replace these codes.
TODO
server_default
setting doesn't work very smoothly yet. An issue Translateserver_default
values #648 is in the works to resolve this.Screenshots
Checklist
Update index.md
).master
branch of the repositoryvisible errors.
Developer Certificate of Origin
Developer Certificate of Origin