-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
[ADD] field_float_nullable: New field type float that supports NULL v… #3280
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
base: 16.0
Are you sure you want to change the base?
Conversation
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.
Code LGTM 💪 🍬
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.
Thanks for this contrib! A first round of questions on the backend field class.
e13775f
to
a5b7435
Compare
Thanks @sbidoul for the review! I've applied the suggested changes. |
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.
I just have one little question 😄
Code Looks good to me, great contribution !
|
||
ttype = fields.Selection( | ||
selection_add=[("float_nullable", "FloatNullable")], | ||
"cascade"}, |
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.
Did you consider 'set float' instead of 'cascade'?
Deleting every float_nullable
seems a bit risky.
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.
Thanks @AnizR, nice catch, I've updated the code accordingly.
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.
A few comments on the style of the tests.
with self.assertRaises(AssertionError): | ||
self.assertTrue( | ||
self._get_db_storge_value(self.record_empty, "value_float_nullable") | ||
== 0.0 | ||
) |
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.
with self.assertRaises(AssertionError): | |
self.assertTrue( | |
self._get_db_storge_value(self.record_empty, "value_float_nullable") | |
== 0.0 | |
) | |
self.assertFalse( | |
self._get_db_storge_value(self.record_empty, "value_float_nullable") | |
== 0.0 | |
) |
with self.assertRaises(AssertionError): | ||
self.assertIsNone( | ||
self._get_db_storge_value(self.record_empty, "value_float") | ||
) |
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.
with self.assertRaises(AssertionError): | |
self.assertIsNone( | |
self._get_db_storge_value(self.record_empty, "value_float") | |
) | |
self.assertTrue( | |
self._get_db_storge_value(self.record_empty, "value_float") is not None | |
) |
|
||
return res | ||
|
||
def _get_db_storge_value(self, record, field_name): |
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.
def _get_db_storge_value(self, record, field_name): | |
def _get_db_storage_value(self, record, field_name): |
This PR has the |
import {useInputField} from "@web/views/fields/input_field_hook"; | ||
import {useNumpadDecimal} from "@web/views/fields/numpad_decimal_hook"; | ||
|
||
export class FloatNullableField extends Component { |
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.
Is it not better to extend FloatField instead of Component, and call super in parse and get formattedValues to reuse the base logic of the float field. There are examples in Odoo, such as FloatScannableField.
…alues instead of defaulting to 0.0
a5b7435
to
435d723
Compare
if (value === "" || value === null) { | ||
return null; | ||
} | ||
return parseFloat(value); |
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.
any reason to not call super here?
if (this.props.value === null || this.props.value === false) { | ||
return ""; | ||
} | ||
return formatFloat(this.props.value, {digits: this.props.digits}); |
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.
any reason to not call super here?
(field.type === "float_nullable" && field.searchable && !field.deprecated) | ||
); | ||
}, | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed 900C to describe this comment to others. Learn more.
Why is this patch necessary?
New field type float that supports NULL values instead of defaulting to 0.0
In standard Odoo,
fields.Float
does not support distinguishingbetween
0.0
andNULL
(i.e., an unset value). By default, if afloat field is left empty in the UI, it is stored as
0.0
in thedatabase. The goal is to allow users and developers to identify whether
a float field has been filled in or not — something that cannot be
reliably determined when
0.0
is used by default. The module alsointegrates fully with Odoo’s UI (form views, list views, export, custom
filters