Giter VIP home page Giter VIP logo

domain_to_sql's Introduction

Convert Odoo Domain to SQL


Actually this module is based on Odoo _search method on models.py file this module will return SQL when you pass domain instead pass it to psycopg2 then execute it

to use this module first install then call get_query method with domain as argument, like this

domain = ['|',('name','ilike','agus'), '&', ('street','ilike', 'Street 2'), ('email', 'ilike', 'gmail')]
query = self.env['res.partner'].get_query(domain)

print(query)

then the result is like this

SELECT "res_partner".id FROM "res_partner" WHERE (("res_partner"."active" = 'True')  AND  (("res_partner"."name"::text ilike '%agus%')  OR  (("res_partner"."street"::text ilike '%Street 2%')  AND  ("res_partner"."email"::text ilike '%gmail%'))))

If pass apply_ir_rules argument with value True, like this

domain = ['|',('name','ilike','agus'), '&', ('street','ilike', 'Street 2'), ('email', 'ilike', 'gmail')]
query = self.env['res.partner'].get_query(domain, apply_ir_rules=True)

The result query will add some extra where clause based on ir_rule (Access Right) and user that currently login, like this

SELECT "res_partner".id FROM "res_partner" WHERE (("res_partner"."active" = 'True')  AND  (("res_partner"."name"::text ilike '%agus%')  OR  (("res_partner"."street"::text ilike '%Street 2%')  AND  ("res_partner"."email"::text ilike '%gmail%')))) AND (((("res_partner"."partner_share" IS NULL or "res_partner"."partner_share" = false )  OR  ("res_partner"."company_id" in ('1')))  OR  "res_partner"."company_id" IS NULL )  AND  ((("res_partner"."type" != 'private') OR "res_partner"."type" IS NULL)  OR  "res_partner"."type" IS NULL ))

If you want to ignore model being active or not, you can pass active_test context like this

query = self.env['res.partner'].with_context({'active_test': False}).get_query(domain)

Visit my website to get Odoo tutorial tips and tricks

domain_to_sql's People

Contributors

znry27 avatar

Forkers

luisdalmasso

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.