Skip to main content

Convert human-readable expressions to Odoo domain format

Project description

odoo-domain-converter

This tool converts human-readable logical expressions into Odoo domain format and validates them against an Odoo server using OdooRPC.

Installation

You can install the package directly from PyPI:

pip install odoo-domain-converter

Or install from source:

git clone https://github.com/0yik/odoo-domain-converter.git
cd odoo-domain-converter
pip install -e .

Usage

As a Command Line Tool

odoo-domain-converter --host localhost --port 8069 --database mydb \
                     --username admin --password admin \
                     --model res.partner \
                     --expression "name = 'John' & is_company = True"

As a Python Package

from odoo_domain_converter import ComplexDomainConverter

# Initialize the converter
converter = ComplexDomainConverter()

# Convert an expression to Odoo domain
expression = "name = 'John' & is_company = True"
domain = converter.to_domain(expression)
print(domain)  # ['&', ('name', '=', 'John'), ('is_company', '=', True)]

# Test the domain against an Odoo server
from odoo_domain_converter import test_in_odoo

success, message = test_in_odoo(
    domain=domain,
    model='res.partner',
    host='localhost',
    db='mydb',
    username='admin',
    password='admin'
)
print(message)  # "Valid (found X records)"

Example Expressions

All examples below use real fields from res.partner model:

# Basic conditions
name = 'John'                           -> [('name', '=', 'John')]
email = 'john@example.com'              -> [('email', '=', 'john@example.com')]
is_company = True                       -> [('is_company', '=', True)]
active = True                           -> [('active', '=', True)]

# Logical combinations
name = 'John' & is_company = False      -> ['&', ('name', '=', 'John'), ('is_company', '=', False)]
email ilike '%@example.com' | email ilike '%@test.com'  
-> ['|', ('email', 'ilike', '%@example.com'), ('email', 'ilike', '%@test.com')]

# Nested conditions
(name = 'John' & is_company = True) | active = True
-> ['|', '&', ('name', '=', 'John'), ('is_company', '=', True), ('active', '=', True)]

# Special operators
parent_id child_of 1                    -> [('parent_id', 'child_of', 1)]
name not_like 'Test%'                   -> [('name', 'not like', 'Test%')]
name not_ilike 'test%'                  -> [('name', 'not ilike', 'test%')]
category_id in [1, 2]                   -> [('category_id', 'in', [1, 2])]
user_ids not_in [1, 2, 3]              -> [('user_ids', 'not in', [1, 2, 3])]

# Odoo expressions
user_id = self.env.user.id             -> [('user_id', '=', self.env.user.id)]
company_id = self.env.company.id       -> [('company_id', '=', self.env.company.id)]

Note on Operators

For operators with spaces, use underscore:

  • Use not_like instead of not like
  • Use not_ilike instead of not ilike
  • Use not_in instead of not in

License

This project is licensed under the MIT License - see the LICENSE file for details.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

odoo_domain_converter-0.1.0.tar.gz (7.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

odoo_domain_converter-0.1.0-py3-none-any.whl (9.0 kB view details)

Uploaded Python 3

File details

Details for the file odoo_domain_converter-0.1.0.tar.gz.

File metadata

  • Download URL: odoo_domain_converter-0.1.0.tar.gz
  • Upload date:
  • Size: 7.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.13.0

File hashes

Hashes for odoo_domain_converter-0.1.0.tar.gz
Algorithm Hash digest
SHA256 b2f4c876719d6e5fa0e102a3f248bb5ef7296042d7b58e70802e16f60698f5b8
MD5 3179a9da2d80aaa2bcb42f9b7d3883f9
BLAKE2b-256 b7e6b4f8cf1b8c12b7939e3324bb64a1f627caa81ad97ca652c32758f5234b96

See more details on using hashes here.

File details

Details for the file odoo_domain_converter-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for odoo_domain_converter-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 7ab4dbbd8c37977d43b315eb93ab5d2fe3c44851288beb45e7da8367dc8c20d8
MD5 b291c98cc9b3a2dcea5b3e38bf1ab9d3
BLAKE2b-256 930965362518ac6fd8cdb4d4627cf67ee48f01d39d14f6a1c5d6be92d9a1a161

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page