-
-
Notifications
You must be signed in to change notification settings - Fork 367
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
Backend work for Mathesar money custom type #417
Comments
MATHESAR_MONEY
custom type and handle it in the backendMATHESAR_MONEY
custom type
See my comment on #409 . We should create types in the |
MATHESAR_MONEY
custom type
@mathemancer Updated the issue. I made it uppercase to match other types, do you have any issues with that? |
I think it should be case-insensitive at the DB layer, and displayed as upper case in the API. This will be the most consistent with the way the default type names work. If we go that route, we'll have to either:
User-defined types are a ways off, though, so I think we should just enforce case-insensitive naming of types (and the |
@mathemancer Okay, thanks, makes sense. I'll update the existing custom types issues. |
@kgodey I'm going back-and-forth on whether to restrict the currencies allowed by the Also, I'm currently assuming we'll want to read / write composite types as JSON at the moment. This isn't the default, but the implementation was easy and seems to be more useful in the service / API than the default tuples. |
@kgodey Regarding precision: We can't set the precision of the numeric portion of a composite type on a column-by-column basis. Thus, in order to support storing in different precision levels depending on the currency, we'd need to have a different type for (at a minimum) each group of currencies with a given precision. I did a (small) bit of reading, and it seems that the standard for financial calculations is to do them in infinite (or best possible) precision, then display the result truncated or rounded. Otherwise, you end up with some odd results. For example, if we use 2 decimal places to store dollars, you'd end up with:
But, it should be back to Thus, I suggest we make the decimal precision a UI concern rather than storage in the type. This would also put it together with worrying about where to put commas and the like, which seems cleaner somehow. |
We should not restrict currencies, but we should ship Mathesar with a curated list of currencies that people can use. It's okay if we can only infer money within our curated list of currencies.
I'm not sure what this means in practical terms, but it sounds fine to me.
That sounds fine to me. |
In that case, I think it would make sense to use an actual table in the |
@mathemancer I think we should use something like https://github.com/kalaspuff/stockholm to source currency data so that we don't have to manage it ourselves. I assume having it in Python won't allow us to use it in inference, so that's why we'd need to create a table? Will it involve any more user permissions that we otherwise needed? |
Yes, that's correct. The testing of a type for a given value is done completely on the DB. Python just manages the looping and whatnot.
The user needs access to |
@mathemancer That works for now, please document the permission in #130 for future reference. |
Continuing a conversation from #647
I'd prefer to just use the ISO standard, which is available in XML format from the standards body. According to ISO, the standards are free-to-use. I've already written a script that makes the XML into a PostgreSQL table (that we can store in the One caveat: It doesn't include currency symbols, but only the 3-character codes. However, neither of the python packages seem to include symbols either. We may have to source those from somewhere else. For verification, I was imagining something where we just make it simple for users to use the currency code table in a foreign key relationship to make sure that the currency entries in their money entries are in the "official list" if desired.
The point there is that there isn't any sub-type for a column. I.e., you can't set a column to have a specific currency, since the currency is defined for each entry separately as a component of the composite type. This is because we wanted to be able to support having multiple currencies in the same column. If we want to have a column that's set to |
After some discussion, I've updated the main description to reflect the intended implementation. |
As @mathemancer mentioned, we talked on a call and decided to update the issue description. The confusion was that the implementation detail of each column having only a single currency (as decided in #118) was lost and we ended up with a type that could support a different currency for each record. We also decided that since we have the "mixed" money type already implemented, we will leave it as-is but remove it from the API to avoid confusion. I will create issues for designing how to use that type in the frontend and we'll work on it after the alpha release. @mathemancer please make sure to do that work somewhere. |
I've made the following issues to track frontend and design work coming out of this issue: |
I'm going to close this issue since we decided against a custom money type after trying a couple of implementations. We'll be using display options on Number types to represent money (for now), see #1063. |
This issue is to create a custom
Money
data type to handle monetary data. At the DB level, this will refer to a number of types such asMATHESAR_TYPES.MONEY_USD
,MATHESAR_TYPES.MONEY_JPY
, etc. Each underlying type should have a name of the formMATHESAR_TYPES.MONEY_<currency code>
, wherecurrency code
is one of the 3-character currency codes defined in ISO 4217.As part of this issue, we need to:
Money
friendly type name in the serviceMATHESAR_TYPES.MONEY_<currency code>
types in the database that store currency amounts. The amount should be aNUMERIC
type.MATHESAR_TYPES.MONEY_<currency code>
if it's possible to do so.MATHESAR_TYPES.MONEY_<currency code>
when it makes sense to do so.Additional Context
v0/databases/
's types list to show both Mathesar and DB type information. #368 for code that calculates which types are allowed for a column.The text was updated successfully, but these errors were encountered: