Skip to content

Instantly share code, notes, and snippets.

View rvalyi's full-sized avatar

Raphaël Valyi rvalyi

View GitHub Profile
#Basic finders:
ProductProduct.find(1)
ProductProduct.find([1,2])
ProductProduct.find([1])
ProductProduct.find(:all)
ProductProduct.find(:last)
#OpenERP domain support:
UML.print_uml([ResPartner, ResPartnerAddress, ProductTemplate, ProductProduct, ProductCategory, SaleOrder, AccountInvoice, StockMove])
Inst2ProductProduct.find(:all, :fields=>['name', 'categ_id']).each{|inst1_product| Inst1ProductProduct.create(:name=>inst1_product.name, :categ_id=>1)}
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
v=ClientCore::MenuItem.new(127, OOOR).open.to_s
require "rubygems"
require "ooor"
@ooor = Ooor.new(:url => 'http://localhost:8069/xmlrpc', :username => 'admin', :password => 'admin')
@ooor.create("admin", "ooor_test") #will take some time, OOOR will automatically poll the server for notification
manufacturing_module_id = IrModuleModule.search([['name','=', 'profile_manufacturing']])[0]
w = @ooor.old_wizard_step('base_setup.base_setup')
w.company(:profile => manufacturing_module_id)
w.update(:name => 'Akretion.com', :state_id => false)
#provided the product_variant_multi module is installed
#notice that variant dimensions values are shared
require "rubygems"
require "ooor"
ooor = Ooor.new(:url => 'http://localhost:8069/xmlrpc', :username => 'admin', :password => 'admin', :database=>'mybase')
tmpl_id = ProductTemplate.create(:name => "My Product Template", :categ_id=> 1).id
dim_id = ProductVariantDimensionType.create(:product_tmpl_id => tmpl_id, :name => "Color").id
ids=StockPicking.search([['state', '=', 'confirmed']])
ids.each do |id|
puts "************** #{id}"
p=StockPicking.find(id)
p.force_assign
w=p.old_wizard_step('stock.partial_picking')
lines=w.open_object_resources[0].relations['move_lines']
h={}
lines.each do |move_id|
h["move#{move_id}"] = StockMove.read(move_id, ['product_qty'])["product_qty"]
t.each{|line| StockInventoryLine.create(:location_id => 11, :product_id=>line.split(',')[0], :product_uom =>1, :product_qty =>line.split(',')[1], :inventory_id=>1) unless ProductProduct.search([['id', '=', line.split(',')[0]]]).empty?; puts line}
p_id=ProjectProject.create(:name => "Alarme Perimetral").id
s="""Lançamento de cabos
Fixação de caixas de Proteção ou Domes
Instalação das câmeras e fontes
Montagem do computador e ligação das câmeras
Testes finais"""
t=s.split("\n")