-
Notifications
You must be signed in to change notification settings - Fork 88
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #78 from latera/HOMS-154
HOMS-154 Add orders filter by custom fields
- Loading branch information
Showing
19 changed files
with
501 additions
and
70 deletions.
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
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,37 @@ | ||
module CustomFields | ||
module DataTypes | ||
class DatetimeRange < CustomFields::Base | ||
def validate_definition | ||
true | ||
end | ||
|
||
def validate_value(attribute_name, value) | ||
return true if value.empty? | ||
return true if (value[:from].is_a?(Time) || value[:from].is_a?(Date)) && | ||
(value[:to].is_a?(Time) || value[:to].is_a?(Date)) | ||
|
||
coerce_value(value) | ||
rescue ArgumentError | ||
errors[attribute_name] << t('invalid_value', | ||
attribute_name: attribute_name, | ||
type: 'DateTimeFilter', | ||
value: value) | ||
end | ||
|
||
def coerce_value(value) | ||
unless value.is_a?(Hash) | ||
raise NotImplementedError | ||
end | ||
|
||
{ | ||
from: datetime_obj.coerce_value(value[:from]), | ||
to: datetime_obj.coerce_value(value[:to]) | ||
} | ||
end | ||
|
||
def datetime_obj | ||
Datetime.new(options) | ||
end | ||
end | ||
end | ||
end |
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
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
Oops, something went wrong.