ooor 1.6.5 → 1.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,19 +1,8 @@
1
- # OOOR: Open Object On Rails
2
- # Copyright (C) 2009-2011 Akretion LTDA (<http://www.akretion.com>).
1
+ # OOOR: OpenObject On Ruby
2
+ # Copyright (C) 2009-2012 Akretion LTDA (<http://www.akretion.com>).
3
3
  # Author: Raphaël Valyi
4
- #
5
- # This program is free software: you can redistribute it and/or modify
6
- # it under the terms of the GNU Affero General Public License as
7
- # published by the Free Software Foundation, either version 3 of the
8
- # License, or (at your option) any later version.
9
- #
10
- # This program is distributed in the hope that it will be useful,
11
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
12
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
- # GNU Affero General Public License for more details.
14
- #
15
- # You should have received a copy of the GNU Affero General Public License
16
- # along with this program. If not, see <http://www.gnu.org/licenses/>.
4
+ # Licensed under the MIT license, see MIT-LICENSE file
5
+
17
6
  module Ooor
18
7
  class ActionWindow
19
8
  class << self
@@ -43,10 +32,15 @@ module Ooor
43
32
  act_win_class
44
33
  end
45
34
 
35
+ def get_url(mode='tree', id=nil, tab=nil) #TODO deal with visible tab in Javascript, possibly hacking web-client
36
+ url = "#{self.ooor.base_url.gsub("xmlrpc", "web/webclient/home")}#action_id=#{@openerp_act_window.id}&view_type=#{mode}"
37
+ url += "&id=#{id}" if id
38
+ end
39
+
46
40
  def get_view_id(mode)
47
- IrActionsAct_window.read(@openerp_act_window.id, ["view_ids"])["view_ids"]
48
- IrActionsAct_windowView.read([9,10], ["view_mode"]).each do |view_hash|
49
- return view_hash["id"] if view_hash["view_mode"] == mode.to_s
41
+ ids = IrActionsAct_window.read(@openerp_act_window.id, ["view_ids"])["view_ids"]
42
+ IrActionsAct_windowView.read(ids, ["view_mode", "view_id"]).each do |view_hash|
43
+ return view_hash["view_id"][0] if view_hash["view_id"] && view_hash["view_mode"] == mode.to_s
50
44
  end
51
45
  IrUiView.search([['model', '=', act_window_param.openerp_model], ['type', '=', mode.to_s]])
52
46
  end
@@ -99,4 +93,4 @@ module Ooor
99
93
 
100
94
 
101
95
  end
102
- end
96
+ end
@@ -1,31 +1,14 @@
1
- # OOOR: Open Object On Rails
2
- # Copyright (C) 2009-2011 Akretion LTDA (<http://www.akretion.com>).
1
+ # OOOR: OpenObject On Ruby
2
+ # Copyright (C) 2009-2012 Akretion LTDA (<http://www.akretion.com>).
3
3
  # Author: Raphaël Valyi
4
- #
5
- # This program is free software: you can redistribute it and/or modify
6
- # it under the terms of the GNU Affero General Public License as
7
- # published by the Free Software Foundation, either version 3 of the
8
- # License, or (at your option) any later version.
9
- #
10
- # This program is distributed in the hope that it will be useful,
11
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
12
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
- # GNU Affero General Public License for more details.
14
- #
15
- # You should have received a copy of the GNU Affero General Public License
16
- # along with this program. If not, see <http://www.gnu.org/licenses/>.
4
+ # Licensed under the MIT license, see MIT-LICENSE file
17
5
 
18
6
  require 'app/ui/form_model'
19
- require 'app/ui/menu'
20
7
  require 'app/ui/action_window'
21
8
 
22
9
  module Ooor
23
10
  module ClientBase
24
11
 
25
- def menu_class
26
- const_get('ir.ui.menu').send :include, MenuModule
27
- end
28
-
29
12
  def get_init_menu(user_id=@config[:user_id])
30
13
  const_get('res.users').read([user_id], ['menu_id', 'name'], @global_context)
31
14
  end
@@ -50,4 +33,4 @@ module Ooor
50
33
  FormModel.new(view['name'], view['view_id'], view['arch'], view['fields'], nil, models, context, view['view_id'])
51
34
  end
52
35
  end
53
- end
36
+ end
@@ -1,19 +1,8 @@
1
- # OOOR: Open Object On Rails
2
- # Copyright (C) 2009-2011 Akretion LTDA (<http://www.akretion.com>).
1
+ # OOOR: OpenObject On Ruby
2
+ # Copyright (C) 2009-2012 Akretion LTDA (<http://www.akretion.com>).
3
3
  # Author: Raphaël Valyi
4
- #
5
- # This program is free software: you can redistribute it and/or modify
6
- # it under the terms of the GNU Affero General Public License as
7
- # published by the Free Software Foundation, either version 3 of the
8
- # License, or (at your option) any later version.
9
- #
10
- # This program is distributed in the hope that it will be useful,
11
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
12
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
- # GNU Affero General Public License for more details.
14
- #
15
- # You should have received a copy of the GNU Affero General Public License
16
- # along with this program. If not, see <http://www.gnu.org/licenses/>.
4
+ # Licensed under the MIT license, see MIT-LICENSE file
5
+
17
6
  module Ooor
18
7
  class FormModel
19
8
  attr_accessor :name, :wizard_id, :datas, :arch, :fields, :type, :state, :view_id, :open_object_resources, :view_context
@@ -1,23 +1,10 @@
1
- # OOOR: Open Object On Rails
2
- # Copyright (C) 2009-2010 Akretion LTDA (<http://www.akretion.com>).
1
+ # OOOR: OpenObject On Ruby
2
+ # Copyright (C) 2009-2012 Akretion LTDA (<http://www.akretion.com>).
3
3
  # Author: Raphaël Valyi
4
- #
5
- # This program is free software: you can redistribute it and/or modify
6
- # it under the terms of the GNU Affero General Public License as
7
- # published by the Free Software Foundation, either version 3 of the
8
- # License, or (at your option) any later version.
9
- #
10
- # This program is distributed in the hope that it will be useful,
11
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
12
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
- # GNU Affero General Public License for more details.
14
- #
15
- # You should have received a copy of the GNU Affero General Public License
16
- # along with this program. If not, see <http://www.gnu.org/licenses/>.
4
+ # Licensed under the MIT license, see MIT-LICENSE file
17
5
 
18
6
  require 'logger'
19
7
  require 'app/models/open_object_resource'
20
- require 'app/models/uml'
21
8
  require 'app/models/db_service'
22
9
  require 'app/models/common_service'
23
10
  require 'app/models/base64'
@@ -27,9 +14,19 @@ module Ooor
27
14
  def self.new(*args)
28
15
  Ooor.send :new, *args
29
16
  end
17
+
18
+ def self.xtend(model_name, &block)
19
+ @extensions ||= {}
20
+ @extensions[model_name] ||= []
21
+ @extensions[model_name] << block
22
+ @extensions
23
+ end
24
+
25
+ def self.extensions
26
+ @extensions
27
+ end
30
28
 
31
29
  class Ooor
32
- include UML
33
30
  include DbService
34
31
  include CommonService
35
32
  include ClientBase
@@ -91,43 +88,50 @@ module Ooor
91
88
  def load_models(to_load_models=@config[:models])
92
89
  @global_context = @config[:global_context] || {}
93
90
  global_login(@config[:username] || 'admin', @config[:password] || 'admin')
91
+ ([File.dirname(__FILE__) + '/app/helpers/*'] + (@config[:helper_paths] || [])).each {|dir| Dir[dir].each { |file| require file }}
94
92
  @ir_model_class = define_openerp_model({'model' => 'ir.model'}, @config[:scope_prefix])
95
93
  if to_load_models #we load only a customized subset of the OpenERP models
96
94
  model_ids = @ir_model_class.search([['model', 'in', to_load_models]])
97
- else #we load all the models
98
- model_ids = @config[:search_models] && @ir_model_class.search() - [1] || @config[:nb_models] || (501.times.map{|i| i}[2..500])
95
+ else
96
+ model_ids = @ir_model_class.search() - [1]
99
97
  end
100
98
  models = @ir_model_class.read(model_ids, ['model'])#['name', 'model', 'id', 'info', 'state'])#, 'field_id', 'access_ids'])
101
99
  @global_context.merge!({}).merge!(@config[:global_context] || {})
102
- models.each {|openerp_model| define_openerp_model(openerp_model, @config[:scope_prefix])}
100
+ models.each {|openerp_model| define_openerp_model(openerp_model, @config[:scope_prefix], nil, nil, nil, nil, @config[:reload])}
103
101
  end
104
102
 
105
- def define_openerp_model(param, scope_prefix=nil, url=nil, database=nil, user_id=nil, pass=nil)
106
- klass = Class.new(OpenObjectResource)
107
- klass.ooor = self
108
- klass.site = url || @base_url
109
- klass.user = user_id
110
- klass.password = pass
111
- klass.database = database
112
- klass.openerp_model = param['model']
113
- klass.openerp_id = url || param['id']
114
- klass.info = (param['info'] || '').gsub("'",' ')
115
- model_class_name = klass.class_name_from_model_key
116
- klass.name = model_class_name
117
- klass.state = param['state']
118
- #klass.field_ids = param['field_id']
119
- #klass.access_ids = param['access_ids']
120
- klass.many2one_associations = {}
121
- klass.one2many_associations = {}
122
- klass.many2many_associations = {}
123
- klass.polymorphic_m2o_associations = {}
124
- klass.associations_keys = []
125
- klass.fields = {}
126
- klass.scope_prefix = scope_prefix
127
- @logger.debug "registering #{model_class_name} as an ActiveResource proxy for OpenObject #{param['model']} model"
128
- (scope_prefix ? Object.const_get(scope_prefix) : Object).const_set(model_class_name, klass)
129
- @loaded_models.push(klass)
130
- klass
103
+ def define_openerp_model(param, scope_prefix=nil, url=nil, database=nil, user_id=nil, pass=nil, reload=false)
104
+ model_class_name = OpenObjectResource.class_name_from_model_key(param['model'])
105
+ scope = scope_prefix ? Object.const_get(scope_prefix) : Object
106
+ if reload || !scope.const_defined?(model_class_name)
107
+ klass = Class.new(OpenObjectResource)
108
+ klass.ooor = self
109
+ klass.site = url || @base_url
110
+ klass.user = user_id
111
+ klass.password = pass
112
+ klass.database = database
113
+ klass.openerp_model = param['model']
114
+ klass.openerp_id = url || param['id']
115
+ klass.info = (param['info'] || '').gsub("'",' ')
116
+ klass.name = model_class_name
117
+ klass.state = param['state']
118
+ #klass.field_ids = param['field_id']
119
+ #klass.access_ids = param['access_ids']
120
+ klass.many2one_associations = {}
121
+ klass.one2many_associations = {}
122
+ klass.many2many_associations = {}
123
+ klass.polymorphic_m2o_associations = {}
124
+ klass.associations_keys = []
125
+ klass.fields = {}
126
+ klass.scope_prefix = scope_prefix
127
+ @logger.debug "registering #{model_class_name} as an ActiveResource proxy for OpenObject #{param['model']} model"
128
+ scope.const_set(model_class_name, klass)
129
+ (::Ooor.extensions[param['model']] || []).each {|block| klass.class_eval(&block)}
130
+ @loaded_models.push(klass)
131
+ return klass
132
+ else
133
+ return scope.const_get(model_class_name)
134
+ end
131
135
  end
132
136
  end
133
137
 
@@ -1,3 +1,8 @@
1
+ # OOOR: OpenObject On Ruby
2
+ # Copyright (C) 2009-2012 Akretion LTDA (<http://www.akretion.com>).
3
+ # Author: Raphaël Valyi
4
+ # Licensed under the MIT license, see MIT-LICENSE file
5
+
1
6
  require File.dirname(__FILE__) + '/../lib/ooor'
2
7
 
3
8
  #RSpec executable specification; see http://rspec.info/ for more information.
@@ -34,34 +39,30 @@ describe Ooor do
34
39
  end
35
40
 
36
41
  it "should be able to load a profile" do
37
- accounting_module_ids = IrModuleModule.search(['|', ['name','=', 'account'], ['name','=', 'account_voucher']])
42
+ accounting_module_ids = IrModuleModule.search(['|', ['name','=', 'sale'], ['name','=', 'account_voucher']])
38
43
  accounting_module_ids.each do |accounting_module_id|
39
- unless IrModuleModule.find(accounting_module_id).state == "installed"
40
- conf1= BaseSetupConfig.create
41
- conf1.config
42
- conf2 = ResConfigView.create(:view => 'extended')
43
- conf2.action_next
44
- conf3 = BaseSetupCompany.create(:name => 'Akretion')
45
- conf3.action_next
46
- conf4 = BaseSetupInstaller.create(:sale => 1)
47
- conf4.action_next
48
- @ooor.load_models
49
- config5 = AccountInstaller.create(:charts => 'configurable')
50
- config5.action_next
51
- @ooor.loaded_models.should_not be_empty
44
+ mod = IrModuleModule.find(accounting_module_id)
45
+ unless mod.state == "installed"
46
+ mod.button_install
52
47
  end
53
48
  end
49
+ wizard = BaseModuleUpgrade.create
50
+ wizard.upgrade_module
51
+ @ooor.load_models
52
+ # config5 = AccountInstaller.create(:charts => 'configurable')
53
+ # config5.action_next
54
+ @ooor.loaded_models.should_not be_empty
54
55
  end
55
56
 
56
57
  it "should be able to configure the database" do
57
- end
58
- if false
59
- chart_module_id = IrModuleModule.search([['category_id', '=', 'Account Charts'], ['name','=', 'l10n_fr']])[0]
60
- unless IrModuleModule.find(chart_module_id).state == "installed"
61
- w2 = @ooor.const_get('account.config.wizard').create(:charts => chart_module_id)
62
- w2.action_create
63
- w3 = @ooor.const_get('wizard.multi.charts.accounts').create
64
- w3.action_create
58
+ # chart_module_id = IrModuleModule.search([['category_id', '=', 'Account Charts'], ['name','=', 'l10n_fr']])[0]
59
+ if AccountTax.search.empty?
60
+ w1 = @ooor.const_get('account.installer').create(:charts => "configurable")
61
+ w1.action_next
62
+ w1 = @ooor.const_get('wizard.multi.charts.accounts').create(:charts => "configurable", :code_digits => 2)
63
+ w1.action_next
64
+ # w3 = @ooor.const_get('wizard.multi.charts.accounts').create
65
+ # w3.action_create
65
66
  end
66
67
  end
67
68
  end
@@ -111,8 +112,8 @@ describe Ooor do
111
112
  partners = ResPartner.find(:all, :params => {:supplier => true})
112
113
  partners.should_not be_empty
113
114
  end
114
-
115
- it "should mimic ActiveResource scoping with first" do
115
+
116
+ it "should mimic ActiveResource scopinging with first" do
116
117
  partner = ResPartner.find(:first, :params => {:customer => true})
117
118
  partner.should be_kind_of ResPartner
118
119
  end
@@ -133,7 +134,7 @@ describe Ooor do
133
134
  o = SaleOrder.find(1)
134
135
  o.date_order.should be_kind_of(Date)
135
136
  m = StockMove.find(1)
136
- m.date.should be_kind_of(Time)
137
+ m.date.should be_kind_of(DateTime)
137
138
  end
138
139
 
139
140
  it "should be able to call any Class method" do
@@ -383,15 +384,15 @@ describe Ooor do
383
384
  end
384
385
 
385
386
  it "should accept rendering options" do
386
- SaleOrder.print_uml(:all, :detailed).should be_true
387
+ SaleOrder.print_uml({:detailed => true}).should be_true
387
388
  end
388
389
  end
389
390
 
390
391
 
391
392
  describe "Multi-instance and class name scoping" do
392
393
  before(:all) do
393
- @ooor1 = Ooor.new(:url => @url, :username => @username, :password => @password, :database => @database, :scope_prefix => 'OE1', :models => ['product.product'])
394
- @ooor2 = Ooor.new(:url => @url, :username => @username, :password => @password, :database => @database, :scope_prefix => 'OE2', :models => ['product.product'])
394
+ @ooor1 = Ooor.new(:url => @url, :username => @username, :password => @password, :database => @database, :scope_prefix => 'OE1', :models => ['product.product'], :reload => true)
395
+ @ooor2 = Ooor.new(:url => @url, :username => @username, :password => @password, :database => @database, :scope_prefix => 'OE2', :models => ['product.product'], :reload => true)
395
396
  end
396
397
 
397
398
  it "should still be possible to find a ressource using an absolute id" do
@@ -405,4 +406,23 @@ describe Ooor do
405
406
  end
406
407
  end
407
408
 
408
- end
409
+
410
+ describe "Ruby OpenERP extensions" do
411
+ before(:all) do
412
+ @ooor = Ooor.new(:url => @url, :username => @username, :password => @password, :database => @database, :helper_paths => [File.dirname(__FILE__) + '/helpers/*'], :reload => true)
413
+ end
414
+
415
+ it "should have default core helpers loaded" do
416
+ mod = IrModuleModule.find(:first, :domain=>['name', '=', 'sale'])
417
+ mod.print_dependency_graph
418
+ end
419
+
420
+ it "should load custom helper paths" do
421
+ IrModuleModule.say_hello.should == "Hello"
422
+ mod = IrModuleModule.find(:first, :domain=>['name', '=', 'sale'])
423
+ mod.say_name.should == "sale"
424
+ end
425
+
426
+ end
427
+
428
+ end
metadata CHANGED
@@ -1,39 +1,44 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: ooor
3
- version: !ruby/object:Gem::Version
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.7.0
4
5
  prerelease:
5
- version: 1.6.5
6
6
  platform: ruby
7
- authors:
7
+ authors:
8
8
  - Raphael Valyi - www.akretion.com
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
-
13
- date: 2011-10-06 00:00:00 Z
14
- dependencies:
15
- - !ruby/object:Gem::Dependency
12
+ date: 2012-06-29 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
16
15
  name: activeresource
17
- prerelease: false
18
- requirement: &id001 !ruby/object:Gem::Requirement
16
+ requirement: !ruby/object:Gem::Requirement
19
17
  none: false
20
- requirements:
21
- - - ">="
22
- - !ruby/object:Gem::Version
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
23
21
  version: 2.3.5
24
22
  type: :runtime
25
- version_requirements: *id001
26
- description: OOOR exposes business object proxies to your Ruby (Rails or not) application, that maps seamlessly to your remote OpenObject/OpenERP server using webservices. It extends the standard ActiveResource API. Running on JRuby, OOOR also offers a convenient bridge between OpenERP and the Java eco-system
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: 2.3.5
30
+ description: OOOR exposes business object proxies to your Ruby (Rails or not) application,
31
+ that maps seamlessly to your remote OpenObject/OpenERP server using webservices.
32
+ It extends the standard ActiveResource API. Running on JRuby, OOOR also offers a
33
+ convenient bridge between OpenERP and the Java eco-system
27
34
  email: rvalyi@akretion.com
28
- executables:
35
+ executables:
29
36
  - ooor
30
37
  extensions: []
31
-
32
38
  extra_rdoc_files: []
33
-
34
- files:
39
+ files:
35
40
  - README.md
36
- - agpl-3.0-licence.txt
41
+ - MIT-LICENSE
37
42
  - lib/ooor.rb
38
43
  - ooor.yml
39
44
  - lib/app/models/open_object_resource.rb
@@ -48,35 +53,31 @@ files:
48
53
  - lib/app/ui/action_window.rb
49
54
  - lib/app/ui/client_base.rb
50
55
  - lib/app/ui/form_model.rb
51
- - lib/app/ui/menu.rb
56
+ - lib/app/helpers/core_helpers.rb
52
57
  - spec/ooor_spec.rb
53
58
  - bin/ooor
54
59
  homepage: http://github.com/rvalyi/ooor
55
60
  licenses: []
56
-
57
61
  post_install_message:
58
62
  rdoc_options: []
59
-
60
- require_paths:
63
+ require_paths:
61
64
  - lib
62
- required_ruby_version: !ruby/object:Gem::Requirement
65
+ required_ruby_version: !ruby/object:Gem::Requirement
63
66
  none: false
64
- requirements:
65
- - - ">="
66
- - !ruby/object:Gem::Version
67
- version: "0"
68
- required_rubygems_version: !ruby/object:Gem::Requirement
67
+ requirements:
68
+ - - ! '>='
69
+ - !ruby/object:Gem::Version
70
+ version: '0'
71
+ required_rubygems_version: !ruby/object:Gem::Requirement
69
72
  none: false
70
- requirements:
71
- - - ">="
72
- - !ruby/object:Gem::Version
73
- version: "0"
73
+ requirements:
74
+ - - ! '>='
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
74
77
  requirements: []
75
-
76
78
  rubyforge_project:
77
- rubygems_version: 1.8.10
79
+ rubygems_version: 1.8.24
78
80
  signing_key:
79
81
  specification_version: 3
80
82
  summary: OOOR - OpenObject On Ruby
81
83
  test_files: []
82
-