{"id":22307863,"url":"https://github.com/akretion/ooor","last_synced_at":"2025-04-04T13:09:44.441Z","repository":{"id":710572,"uuid":"357291","full_name":"akretion/ooor","owner":"akretion","description":"Odoo Ruby JSON client. Emulates ActiveRecord enough (as much as Mongoid; Implements ActiveModel) to make Rails development with an Odoo datastore straightforward","archived":false,"fork":false,"pushed_at":"2018-03-06T14:49:48.000Z","size":1046,"stargazers_count":200,"open_issues_count":32,"forks_count":60,"subscribers_count":39,"default_branch":"master","last_synced_at":"2025-03-28T12:05:52.737Z","etag":null,"topics":["activerecord","erp","odoo","rails","ruby"],"latest_commit_sha":null,"homepage":"","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/akretion.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"MIT-LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2009-11-01T20:50:51.000Z","updated_at":"2025-01-01T17:37:56.000Z","dependencies_parsed_at":"2022-08-16T10:45:20.093Z","dependency_job_id":null,"html_url":"https://github.com/akretion/ooor","commit_stats":null,"previous_names":["rvalyi/ooor"],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/akretion%2Fooor","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/akretion%2Fooor/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/akretion%2Fooor/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/akretion%2Fooor/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/akretion","download_url":"https://codeload.github.com/akretion/ooor/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247182335,"owners_count":20897379,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["activerecord","erp","odoo","rails","ruby"],"created_at":"2024-12-03T20:12:17.189Z","updated_at":"2025-04-04T13:09:44.418Z","avatar_url":"https://github.com/akretion.png","language":"Ruby","readme":"[![Build Status](https://secure.travis-ci.org/akretion/ooor.png?branch=master)](http://travis-ci.org/akretion/ooor) [![Code Climate](https://codeclimate.com/github/akretion/ooor.png)](https://codeclimate.com/github/akretion/ooor)\n[![Coverage Status](https://coveralls.io/repos/akretion/ooor/badge.png?branch=master)](https://coveralls.io/r/akretion/ooor?branch=master) [![Gem Version](https://badge.fury.io/rb/ooor.png)](http://badge.fury.io/rb/ooor) [![Dependency Status](https://www.versioneye.com/ruby/ooor/badge.png)](https://www.versioneye.com/ruby/ooor)\n\n[![OOOR by Akretion](https://s3.amazonaws.com/akretion/assets/ooor_by_akretion.png)](http://akretion.com)\n\n\nWhy use Ooor?\n-------------\n\n* Ooor is an administration **Swiss Army knife** in an interactive Ruby session. You connect remotely to any running Odoo instance without stopping it, without compromising its security. It has tab auto-completion and object introspection features. You can script anything you would do in the web interface or in an Odoo module with the same level of query optimization.\n* Ooor is the basis for unleashed **web development**. It is **Rack** based and inject proxies to Odoo entities in your Rack env just like you use them in your env registry in Odoo modules. You use it in popular Ruby web frameworks such as **Sinatra** or **Rails**.\n\nOdoo is all the rage for efficiently building an ERP back-office, but sometimes you want **freedom and scalablity** for your web front ends. Ooor enables you to model your web app using standard web frameworks like Rails while using Odoo as the persistence layer - **without data duplication or synchronization/mapping logic** - and reusing the Odoo business logic.\nOoor even has an optionnal Rack filter that enables you to proxy some Odoo applications of your choice (say the shopping cart for instance) and share the HTTP session with it.\n\nBecause Ooor is ActiveModel based and emulates the ActiveRecord API well enough, it just works with popular Ruby gems such as Devise for authentication, will_paginate for pagination, SimpleForm, Cocoon for nested forms...\n\nOoor is also a lot more advanced than its Python clones: it is very carefuly designed to save Odoo requests. It can avoid the N+1 queries and also works smartly with the Rails cache so that the meta-data used to define the Odoo proxies can be cached shared between concurrent Rails workers without the need to hit Odoo again with requests such as fields_get.\n\nRelated projects - a full web stack!\n------------------------------------\n\n* [Ooorest](http://github.com/akretion/ooorest), Ooor is the **Model** layer of **MVC**. Ooorest is the **Controller** layer, enforcing a clean Railish **REST API** and offering handy **helper** to use Odoo in your Rails application.\n* [Aktooor](http://github.com/akretion/aktooor), Aktooor is the missing **View** layer of **MVC**. It's based on [SimpleForm](https://github.com/plataformatec/simple_form), that is a clean minimalist framework that extend Rails form framework over [Twitter Bootstrap](http://getbootstrap.com)\n* [Erpify](http://github.com/akretion/erpify), Erpify is Odoo inside the Liquid non evaling language, that is the templating language of Shopify or LocomotiveCMS for instance.\n* [Locomotive-erpify](http://github.com/akretion/locomtive-erpify), Erpify for LocomotiveCMS, both the engine and the Wagon local editor\n* [Solarize](http://github.com/akretion/solarize), pulling data from Odoo relational database may not scale to your need. No problem with Solarize: you can index your OpenERP data with the [Solerp](http://github.com/akretion/solerp) OpenERP module, then search it using SolR API and even load it from SolR without even hitting OpenERP!\n* [TerminatOOOR](http://github.com/rvalyi/terminatooor), a Pentaho ETL Kettle plugin allowing to push/pull data into/from Odoo with an incomparable flexibility and yet benefit all standard ETL features, including the AgileBI OLAP business intelligence plugin.\n\n\nHow?\n------------\n\nOdoo is a Python based open source ERP. But every Odoo business method is actually exposed as a JSON-RPC webservice (SOA orientation, close to being RESTful).\nOoor doesn't connect to the Odoo database directly, Instead it uses the Odoo JSON-RPC API so it fully enforces Odoo security model and business logic.\n\nOoor is around 2000 lines of code and has a test coverage over 93%. The API it exposes is not invented but it is the one of Rails: it is modeled after Rails [ActiveModel](http://api.rubyonrails.org/classes/ActiveModel/Model.html), [ActiveResource](https://github.com/rails/activeresource) and [ActiveRecord](http://api.rubyonrails.org/classes/ActiveRecord/Base.html) layers.\n\nMore specifically, an Odoo Ooor proxy implements the ActiveModel API. Instead of depending on ActiveResource which is actually a bit different (not multi-tenant, little access right management), we copied a tiny subset of it in the `mini_active_resource.rb` file and Odoo proxies include this module. Finally Ooor emulates the ActiveRecord API wherever possible delegating its requests to Odoo using Odoo domain [S expressions](http://en.wikipedia.org/wiki/S-expression) instead of SQL. The ActiveRecord API emulation is actually pretty good: think **Ooor looks more like ActiveRecord than Mongoid**; it has associations, surface ARel API, Reflection API, can be paginated via Kaminary, can be integrated with SimpleForm or Cocoon seamlessly...\n\nOoor features **several session modes**: in the default IRB console usage it uses a global login scheme and generate constants for your OpenERP proxies, such as ProductProduct for the product.product OpenERP object much like Rails ActiveRecord. In web mode instead, you can have several sessions and do session['product.product'] to get a proxy to the Product object matching your current session credentials, chosen database and OpenERP url (yes Ooor is not only multi-database like OpenEP, it's in fact **multi-OpenERP**!)\n\n\nInstallation\n------------\n\n    $ gem install ooor\n\n**Warning Ooor has been ureleased for several months, don't hesitate to run the git version instead**\n\nTrying it simply\n------------\n\nOnce you installed the OOOR gem, you get a new OOOR command line. Basic usage is:\n\n    $ ooor username:password@host:port/database\n\n\nThis will bring you in a standard IRB interpreter with an ooor client already connected to your Odoo server so you can start playing with it.\n\n\n### Standalone (J)Ruby application:\n\nLet's test ooor in an irb console (irb command):\n\n```ruby\nrequire 'rubygems'\nrequire 'ooor'\nOoor.new(:url =\u003e 'http://localhost:8069/xmlrpc', :database =\u003e 'mybase', :username =\u003e 'admin', :password =\u003e 'admin')\n```\n\nThis should load all your Odoo models into Ruby proxy Activeresource objects. Of course there are option to load only some models.\nLet's try to retrieve the user with id 1:\n\n```ruby\nResUsers.find(1)\n```\n\n(in case you have an error like \"no such file to load -- net/https\", then on Debian/Ubuntu, you might need to do before: apt-get install libopenssl-ruby)\n\n\n### (J)Ruby on Rails application:\n\nPlease read details [https://github.com/rvalyi/ooor/wiki/(J)Ruby-on-Rails-application](here)\n\n\nAPI usage\n------------\n\nNote: Ruby proxy objects are named after Odoo models in but removing the '.' and using CamelCase.\n(we remind you that Odoo tables are also named after Odoo models but replacing the '.' by '_'.)\n\nBasic finders:\n\n```ruby\nProductProduct.find(1)\nProductProduct.find([1,2])\nProductProduct.find([1])\nProductProduct.find(:all)\nProductProduct.find(:last)\n```\n\nOdoo domain support (same as Odoo):\n\n```ruby\nResPartner.find(:all, :domain=\u003e[['supplier', '=', 1],['active','=',1]])\n#More subtle now, remember Odoo use a kind of inverse polish notation for complex domains,\n#here we look for a product in category 1 AND which name is either 'PC1' OR 'PC2':\nProductProduct.find(:all, :domain=\u003e[['categ_id','=',1],'|',['name', '=', 'PC1'],['name','=','PC2']])\n```\n\n\nOdoo context support (same as Odoo):\n\n```ruby\nProductProduct.find(1, :context =\u003e {:my_key =\u003e 'value'})\n```\n\nRequest params or ActiveResource equivalence of Odoo domain (but degraded as only the = operator is supported, else use domain):\n\n```ruby\nResPartner.find(:all, :params =\u003e {:supplier =\u003e true})\n```\n\nOdoo search method:\n\n```ruby\nResPartner.search([['name', 'ilike', 'a']], 0, 2)\n```\n\nArguments are: domain, offset=0, limit=false, order=false, context={}, count=false\n\n\nRelations (many2one, one2many, many2many) support:\n\n```ruby\nSaleOrder.find(1).order_line #one2many relation\np = ProductProduct.find(1)\np.product_tmpl_id #many2one relation\np.taxes_id #automagically reads man2many relation inherited via the product_tmpl_id inheritance relation\np.taxes_id = [1,2] #save a many2many relation, notice how we bypass the awkward Odoo syntax for many2many (would require [6,0, [1,2]]) ,\np.save #assigns taxes with id 1 and 2 as sale taxes,\nsee [the official Odoo documentation](http://doc.openerp.com/developer/5_18_upgrading_server/19_1_upgrading_server.html?highlight=many2many)```\n\n\nInherited relations support:\n\n```ruby\nProductProduct.find(1).categ_id #where categ_id is inherited from the ProductTemplate\n```\n\nPlease notice that loaded relations are cached (to avoid  hitting Odoo over and over)\nuntil the root object is reloaded (after save/update for instance).\n\n\nLoad only specific fields support (faster than loading all fields):\n\n```ruby\nProductProduct.find(1, :fields=\u003e[\"state\", \"id\"])\nProductProduct.find(:all, :fields=\u003e[\"state\", \"id\"])\nProductProduct.find([1,2], :fields=\u003e[\"state\", \"id\"])\nProductProduct.find(:all, :fields=\u003e[\"state\", \"id\"])\n```\n\n    even in relations:\n\n```ruby\nSaleOrder.find(1).order_line(:fields =\u003e [\"state\"])\n```\n\nCreate:\n\n```ruby\npc = ProductCategory.new(:name =\u003e 'Categ From Rails!')\n# \u003cProductCategory:0xb702c42c @prefix_options={}, @attributes={\"name\"=\u003e\"Categ From Rails!\"}\u003e\npc.create\npc.id\n# $ =\u003e 14\n```\n\n\nUpdate:\n\n```ruby\npc.name = \"A new name\"\npc.save\n```\n\nCopy:\n\n```ruby\ncopied_object = pc.copy({:categ_id =\u003e 2})  #first optionnal arg is new default values, second is context\n```\n\nDelete:\n\n```ruby\npc.destroy\n```\n\nCall workflow:\n\n```ruby\ns = SaleOrder.find(2)\ns.wkf_action('cancel')\ns.state\n# =\u003e 'cancel'\n```\n\nOn Change methods:\n\nNote: currently OOOR doesn't deal with the View layer, or has a very limited support for forms for the wizards.\nSo, it's not possible so far for OOOR to know an on_change signature. Because of this, the on_change syntax is  bit awkward\nas you will see (fortunately OpenERP SA announced they will fix that on_change API in subsequent v6 OpenERP releases):\nyou need to explicitely tell the on_change name, the parameter name that changed, the new value and finally\nenforce the on_change syntax (looking at the OpenERP model code or view or XML/RPC logs will help you to find out). But\nultimately it works:\n\n```ruby\nl = SaleOrderLine.new\nl.on_change('product_id_change', :product_id, 20, 1, 20, 1, false, 1, false, false, 7, 'en_US', true, false, false, false)\n# =\u003e #\u003cSaleOrderLine:0x7f76118b4348 @prefix_options={}, @relations={\"product_uos\"=\u003efalse, \"product_id\"=\u003e20, \"product_uom\"=\u003e1, \"tax_id\"=\u003e[]}, @loaded_relations={}, @attributes={\"name\"=\u003e\"[TOW1] ATX Mid-size Tower\", \"product_uos_qty\"=\u003e1, \"delay\"=\u003e1.0, \"price_unit\"=\u003e37.5, \"type\"=\u003e\"make_to_stock\", \"th_weight\"=\u003e0}\u003e\n```\nNotice that it reloads the Objects attrs and print warning message accordingly\n\n\nOn the fly one2many object graph update/creation:\n\nJust like the OpenERP GTK client (and unlike the web client), in OOOR you can pass create/update\none2many relation in place directly. For instance:\n\n```ruby\nso = SaleOrder.new\nso.on_change('onchange_partner_id', :partner_id, 1, 1, false) #auto-complete the address and other data based on the partner\nso.order_line = [SaleOrderLine.new(:name =\u003e 'sl1', :product_id =\u003e 1, :price_unit =\u003e 42, :product_uom =\u003e 1)] #create one order line\nso.save\nso.amount_total\n# =\u003e 42.0\n```\n\n\nCall aribtrary method:\n\n    $ use static ObjectClass.rpc_execute_with_all method\n    $ or object.call(method_name, args*) #were args is an aribtrary list of arguments\n\nClass methods from are osv.py/orm.py proxied to OpenERP directly (as the web client does):\n\n```ruby\nResPartner.name_search('ax', [], 'ilike', {})\nProductProduct.fields_view_get(132, 'tree', {})\n```\n\n\nCall old style wizards (OpenERP v5):\n\n```ruby\ninv = AccountInvoice.find(4)\n# in case the inv.state is 'draft', do inv.wkf_action('invoice_open')\nwizard = inv.old_wizard_step('account.invoice.pay') #tip: you can inspect the wizard fields, arch and datas\nwizard.reconcile({:journal_id =\u003e 6, :name =\u003e\"from_rails\"}) #if you want to pay all; will give you a reloaded invoice\ninv.state\n# =\u003e \"paid\"\n# or if you want a payment with a write off:\nwizard.writeoff_check({\"amount\" =\u003e 12, \"journal_id\" =\u003e 6, \"name\" =\u003e'from_rails'}) #use the button name as the wizard method\nwizard.reconcile({required missing write off fields...}) #will give you a reloaded invoice because state is 'end'\n# TODO test and document new osv_memory wizards API\n```\n\n\nAbsolute OpenERP ids aka ir_model_data:\n\njust like Rails fixtures, OpenERP supports absolute ids for its records, especially those imported from XML or CSV.\nWe are here speaking about the string id of the XML or CSV records, eventually prefixed by the module name.\nUsing those ids rather than the SQL ids is a good idea to avoid relying on a particular installation.\nIn OOOR, you can both retrieve one or several records using those ids, like for instance:\n\n```ruby\nProductCategory.find('product.product_category_3')\n```\n\nNotice that the 'product.' module prefix is optional here but important if you have similar ids in different module scopes.\nYou can also create a resource and it's ir_model_data record alltogether using the ir_mode_data_id param:\n\n```ruby\nProductCategory.create(:name =\u003e 'rails_categ', :ir_model_data_id =\u003e['product', 'categ_x']) #1st tab element is the module, 2nd the id in the module\n```\n\nObtain report binary data:\n\nTo obtain the binary data of an object report simply use the function get_report_data(report_name). This function returns a list that contains the binary data encoded in base64 and a string with the file format.\nExample:\n\n```ruby\ninv = AccountInvoice.find(3)\nreport = inv.get_report_data('account.invoice') #account.invoice is the service name defined in Invoices report\n# Save the report to a file\n# report[1] contains the file extension and report[0] contains the binary data of the report encoded in base64\nFile.open(\"invoice_report.#{report[1]}\", \"w\") {|f| f.write(Base64.decode64(report[0]))}\n```\n\nChange logged user:\n\nAn Ooor client can have a global user logged in, to change it:\n\n```ruby\nOoor.global_login('demo', 'demo')\ns = SaleOrder.find(2)\n# =\u003e 'Access denied error'\n```\n\nInstead, every Ooor business objects can also belong to some specific user. To achieve that, generate your object passing\nproper :user_id and :password parameters inside the context of the method creating the object (typically a find).\nNotice that methods invoked on an objet use the same credentials as the business objects.\nObjects generated by this object (by a call to an association for instance) will also have the same credentials.\n\n```ruby\np = ProductProduct.find(1, :context =\u003e {:user_id=\u003e3, :password=\u003e'test'})\n```\n\nThis is tipycally the system you will use in a Ruby (Rails or not) web application.\n\nChange log level:\n\nBy default the log level is very verbose (debug level) to help newcomers to jumpstart.\nHowever you might want to change that. 2 solutions:\n\n```ruby\nOoor.logger.level = 1 #available levels are those of the standard Ruby Logger class: 0 debug, 1 info, 2 error\n```\nIn the config yaml file or hash, set the :log_level parameter\n\n\n[Drawing OpenERP UML diagrams with OOOR](http://wiki.github.com/rvalyi/ooor/drawing-openerp-uml-diagrams-with-ooor)\n\n[Finger in the nose multi-OpenERP instances migration/management with OOOR](http://wiki.github.com/rvalyi/ooor/howto-connect-ooor-to-multiple-openerp-instance-easy-data-migration)\n\n\nDetailed API in the automated test suite\n------------\n\nOOOR ships with an [RSpec](http://rspec.info/) automated unit test suite to avoid regressions. This is also the place\nwhere you can easily read the exact API detail to master every OOOR features.\nYou can read the test suite here: [http://github.com/rvalyi/ooor/blob/master/spec/ooor_spec.rb](http://github.com/rvalyi/ooor/blob/master/spec/ooor_spec.rb)\nOf course this also shows you can use RSpec to specify and test your OpenERP modules.\nOOOR is actually used to test OpenERP complex features in a specification language business experts can read and even write!\nIn this case [CampToCamp](http://www.camptocamp.com/) used the famous [Cucumber functionnal test suite](http://cukes.info/) in the [OERPScenario project](https://launchpad.net/oerpscenario).\n\n\n\nFAQ\n------------\n\nPlease read the [FAQ here](https://github.com/rvalyi/ooor/wiki/FAQ)\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fakretion%2Fooor","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fakretion%2Fooor","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fakretion%2Fooor/lists"}