akretion / ooor

Odoo Ruby JSON client. Emulates ActiveRecord enough (as much as Mongoid; Implements ActiveModel) to make Rails development with an Odoo datastore straightforward
MIT License
199 stars 59 forks source link

support string domain parsing #118

Open rvalyi opened 10 years ago

rvalyi commented 10 years ago

often Odoo gives us domains as string (in views for instance). But we may need to send them back in json to Odoo. This would help to translate forms better in Aktooor for instance.

Idea: change the domain string a bit and do a JSON.parse on it. Elements of code:

m = string_domain.match(/time\.strftime\(.*\)/)
m.each do |python_time|
  ruby_time = python_time.gsub("time.strftime(", "Time.now.strftime(")
  string_domain.gsub!(python_time, ruby_time)
end

replaces = {
"(" =>"[",
")" =>"]",
"True" =>"true",
"False" =>"false",
}

replaces.each do |k, v|
  string_domain.gsub!(k, v)
end

domain_rb = JSON.parse(string_domain)

TODO:

rvalyi commented 10 years ago

An other possibility would be https://github.com/byroot/parsr

not a lot of activity but the the guy seems to be doing very serious stuff at Shopify, so will probably do the job.