Odoo Ruby JSON client. Emulates ActiveRecord enough (as much as Mongoid; Implements ActiveModel) to make Rails development with an Odoo datastore straightforward
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:
avoid that () replacements screw time function.
deal with variable injections. JSon.parse won't let us bind variables. An idea would be to pass an Ooor object to the domain conversion method. For each field key, we would try to replace the key with its value (send key). To avoid overlapping, the idea would be to match [not azAZ ]key[not azAZ ].
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:
TODO: