Skip to content

Instantly share code, notes, and snippets.

@rvalyi
Created February 7, 2010 00:12
Show Gist options
  • Save rvalyi/297076 to your computer and use it in GitHub Desktop.
Save rvalyi/297076 to your computer and use it in GitHub Desktop.
irb
irb(main):001:0>require 'rubygems' #we need our packaging tool
irb(main):001:0>require 'ooor' #we need ooor
irb(main):001:0>Ooor.new({:url => 'http://localhost:8069/xmlrpc', :database => 'mybase', :username => 'admin', :password => 'admin'}) #update mybase and the credentials to your own OpenERP
[blahblahblah: it introspects your OpenERP server and generate Ruby proxies for all your OpenERP entities]
irb(main):001:0>p=ProductProduct.find(1)
=> a Ruby instance of the ProductProduct holding all fields and relation of your OpenERP class
irb(main):001:0>p.name = 'Hello Word Product'
irb(main):001:0>p.save
irb(main):001:0>p.name
=> "Hello World Product"
irb(main):001:0>new_categ = ProductCategory.new(:name => 'Suckfree API')
irb(main):001:0>p.categ_id = new_categ.save #as in good REST, save returns the id of the created resource
irb(main):001:0>p.save
irb(main):001:0>p.categ_id.name
=> "Suckfree API"
irb(main):001:0>s=SaleOrder.find(1)
irb(main):001:0>s.date_order=2.days.ago #Rails 'activesupport' magic brought to OpenERP
irb(main):001:0>s.save
Let's validate all your draft invoices in just one line:
irb(main):001:0>AccountInvoice.find(:all, :domain => [['state', '=', 'draft']]).each{|invoice| invoice.wkf_action('invoice_open')}
Let's draw a simple UML diagram of 2 classes and their adjacent classes (will create an uml.png image in your current folder):
UML.print_uml([SaleOrder, SaleShop])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment