Add bidirectional domain conversion with JSON Queries - #38
Conversation
Co-authored-by: ecarreras <294235+ecarreras@users.noreply.github.com>
Co-authored-by: ecarreras <294235+ecarreras@users.noreply.github.com>
|
@copilot code should be compatible with py2.7 and py3.11 |
Co-authored-by: ecarreras <294235+ecarreras@users.noreply.github.com>
|
@copilot the description of the pull-requests was better before, when you explain all the changes |
Updated the PR description with detailed explanation of all changes made, including new files created, features implemented, technical details, usage examples, and testing coverage. The description now provides comprehensive information about the domain to JSON conversion functionality. |
|
@copilot can you add the same as https://github.com/gisce/ooquery-ts/blob/main/src/convertToDomain.ts to convert from json to openerp domain? |
…sion Co-authored-by: ecarreras <294235+ecarreras@users.noreply.github.com>
I've implemented the
The functionality is now available as |
|
@copilot conversion to domain is not correct, it can be nested... like ['|', ['|'... is a list of tuples or operators, and a one operator for two tuples |
Co-authored-by: ecarreras <294235+ecarreras@users.noreply.github.com>
Fixed the nested domain parsing issue in convert_from_domain function. The function now correctly handles nested domain structures like ['|', ['|', ('a', '=', 1), ('b', '=', 2)], ('c', '=', 3)] by properly detecting when a list element is a sub-domain versus a condition tuple and recursively parsing sub-domains. Changes implemented in commit 2ec1252. |
…tructures Co-authored-by: ecarreras <294235+ecarreras@users.noreply.github.com>
|
@copilot tests failling in roundtrip conversion, seems implicit |
…queries Co-authored-by: ecarreras <294235+ecarreras@users.noreply.github.com>
Fixed the roundtrip conversion issue. The problem was in how nested AND groups within OR queries were being handled. The implementation now correctly preserves explicit AND operators in nested query structures to maintain semantic accuracy. For example, when converting a JSON structure with a nested AND group: {
"combinator": "or",
"rules": [
{"field": "name", "operator": "=", "value": "John"},
{
"combinator": "and",
"rules": [
{"field": "age", "operator": ">", "value": 18},
{"field": "city", "operator": "=", "value": "Barcelona"}
]
}
]
}The domain now correctly includes explicit This ensures that roundtrip conversions preserve the original domain structure, including explicit AND operators. All tests now pass. Commit 13b04ab. |
This PR adds comprehensive bidirectional conversion functionality between OpenERP/Odoo domains and structured JSON format, with correct handling of OpenERP/Odoo's flat prefix notation and proper semantic preservation of nested query structures.
Key Features
Domain to JSON Conversion
combinatorandrulesstructureilike→contains,<>→!=)&) and OR (|) domain logic with prefix notation parsingJSON to Domain Conversion
['|', '|', ('a', '=', 1), ('b', '=', 2), ('c', '=', 3)]instead of nested structuresCritical Fix for Semantic Preservation
The implementation correctly generates OpenERP/Odoo domains using flat prefix notation while preserving semantic grouping:
['|', '|', rule1, rule2, rule3](not nested structures)[('active', '=', True), '|', ('state', '=', 'open'), ('state', '=', 'draft')]['|', ('name', '=', 'John'), '&', ('age', '>', 18), ('city', '=', 'Barcelona')]['|', '&', ('name', 'ilike', 'John'), ('age', '>', 18), '&', ('city', '=', 'Barcelona'), ('active', '=', True)]No nested lists - domains are always flat arrays of operators and tuples, but explicit operators are preserved when semantically necessary.
Usage Examples
Implementation Details
This functionality mirrors the TypeScript implementation in
gisce/ooquery-tswhile ensuring correct OpenERP/Odoo domain format compliance and maintaining semantic accuracy for complex nested query structures.💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.