This repository has been archived by the owner on Apr 28, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 140
[ENH] Custom Float Value Enhancements #86
Open
richard-willdooit
wants to merge
3
commits into
pledra:10.0
Choose a base branch
from
richard-willdooit:10.0-minmax-float
base: 10.0
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,3 +2,4 @@ | |
|
||
from . import test_create | ||
from . import test_configuration_rules | ||
from . import test_numeric_customvals |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
from odoo.tests.common import TransactionCase | ||
from odoo.exceptions import ValidationError | ||
|
||
|
||
class ConfigurationRules(TransactionCase): | ||
|
||
def setUp(self): | ||
super(ConfigurationRules, self).setUp() | ||
|
||
self.attr_repeater = self.env['product.attribute'].create( | ||
{'name': 'Repeater', | ||
'value_ids': [ | ||
(0, 0, {'name': '1'}), | ||
(0, 0, {'name': '2'}), | ||
], | ||
'custom_type': 'int', | ||
'min_val': 3, | ||
'max_val': 10, | ||
} | ||
) | ||
self.attr_flux = self.env['product.attribute'].create( | ||
{'name': 'Flux Adjustment', | ||
'value_ids': [ | ||
(0, 0, {'name': 'Standard'}), | ||
], | ||
'custom_type': 'float', | ||
'custom_digits': 3, | ||
'min_fval': 0.750, | ||
'max_fval': 1.823, | ||
} | ||
) | ||
self.flux_capacitor = self.env['product.template'].create( | ||
{'name': 'Flux Capacitor', | ||
'config_ok': True, | ||
'type': 'product', | ||
'categ_id': self.env['ir.model.data'] .xmlid_to_res_id( | ||
'product.product_category_5' | ||
), | ||
'attribute_line_ids': [ | ||
(0, 0, {'attribute_id': self.attr_repeater.id, | ||
'value_ids': [ | ||
(6, 0, self.attr_repeater.value_ids.ids), | ||
], | ||
'required': True, | ||
'custom': True, | ||
}), | ||
(0, 0, {'attribute_id': self.attr_flux.id, | ||
'value_ids': [ | ||
(6, 0, self.attr_flux.value_ids.ids), | ||
], | ||
'required': True, | ||
'custom': True, | ||
}) | ||
] | ||
} | ||
) | ||
|
||
def test_without_custom(self): | ||
attr_val_ids = [self.attr_repeater.value_ids[0].id, | ||
self.attr_flux.value_ids[0].id, | ||
] | ||
custom_vals = {} | ||
validation = self.flux_capacitor.validate_configuration( | ||
attr_val_ids, custom_vals) | ||
self.assertTrue( | ||
validation, | ||
"Configuration with custom values rejected with all " | ||
"standard selections" | ||
) | ||
|
||
def test_valid_custom_numerics(self): | ||
attr_val_ids = [] | ||
custom_vals = { | ||
self.attr_repeater.id: '5', | ||
self.attr_flux.id: '1.234', | ||
} | ||
validation = self.flux_capacitor.validate_configuration( | ||
attr_val_ids, custom_vals) | ||
self.assertTrue( | ||
validation, | ||
"Configuration with valid custom numeric values rejected" | ||
) | ||
|
||
def test_invalid_custom_numerics(self): | ||
attr_val_ids = [] | ||
validation_method = self.flux_capacitor.validate_configuration | ||
|
||
custom_vals = { | ||
self.attr_repeater.id: '2', | ||
self.attr_flux.id: '1.234', | ||
} | ||
self.assertRaises(ValidationError, | ||
validation_method, attr_val_ids, custom_vals) | ||
|
||
custom_vals = { | ||
self.attr_repeater.id: '11', | ||
self.attr_flux.id: '1.234', | ||
} | ||
self.assertRaises(ValidationError, | ||
validation_method, attr_val_ids, custom_vals) | ||
|
||
custom_vals = { | ||
self.attr_repeater.id: '5', | ||
self.attr_flux.id: '0.749', | ||
} | ||
self.assertRaises(ValidationError, | ||
validation_method, attr_val_ids, custom_vals) | ||
|
||
custom_vals = { | ||
self.attr_repeater.id: '5', | ||
self.attr_flux.id: '1.824', | ||
} | ||
self.assertRaises(ValidationError, | ||
validation_method, attr_val_ids, custom_vals) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Can't we keep one float field for min/max of int and float since there can only be one custom field type per attribute?
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.
@PCatinean True, but it needs to be a float min or max, not an integer. Our requirement was that the minimum was 0.573, and the maximum was 20.127 (a length).
I think this is a little cleaner, though, because it implies the validation steps are dependent on the type, which could be extended to other types at another time...
Also, if a float min is used, then we need to ensure the error converts the min to an integer before displaying so it does not say "Value cannot be greater than 20.0"