Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- require 'xmlrpc/client'
- Facter.add(:odoo_ref) do
- confine :virtual => 'physical'
- setcode do
- mac = Facter.value(:discovery_bootif)
- sn = Facter.value(:serialnumber)
- url = 'http://odoo-server:8069'
- db = 'production'
- username = 'username'
- password = 'password'
- common = XMLRPC::Client.new2("#{url}/xmlrpc/2/common")
- uid = common.call('authenticate', db, username, password, {})
- models = XMLRPC::Client.new2("#{url}/xmlrpc/2/object").proxy
- records = models.execute_kw(db, uid, password,
- 'stock.production.lot', 'search_read',
- [['|', ['serialnumber', '=', mac], ['serialnumber', '=', sn]]],
- {:fields => ['ref']})
- if records.length == 1
- records.first['ref']
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement