ooor 1.3.2 → 1.4.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,20 @@
1
+ # OOOR: Open Object On Rails
2
+ # Copyright (C) 2009-2010 Akretion LTDA (<http://www.akretion.com>).
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/>.
17
+
1
18
  require 'app/ui/form_model'
2
19
  require 'app/ui/menu'
3
20
  require 'app/ui/action_window'
@@ -1,3 +1,20 @@
1
+ # OOOR: Open Object On Rails
2
+ # Copyright (C) 2009-2010 Akretion LTDA (<http://www.akretion.com>).
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/>.
17
+
1
18
  class FormModel
2
19
  attr_accessor :name, :wizard_id, :datas, :arch, :fields, :type, :state, :view_id, :open_object_resources, :view_context
3
20
 
@@ -1,3 +1,20 @@
1
+ # OOOR: Open Object On Rails
2
+ # Copyright (C) 2009-2010 Akretion LTDA (<http://www.akretion.com>).
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/>.
17
+
1
18
  require 'app/ui/action_window'
2
19
 
3
20
  module MenuModule
@@ -1,8 +1,26 @@
1
+ # OOOR: Open Object On Rails
2
+ # Copyright (C) 2009-2010 Akretion LTDA (<http://www.akretion.com>).
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/>.
17
+
1
18
  require 'logger'
2
19
  require 'app/models/open_object_resource'
3
20
  require 'app/models/uml'
4
21
  require 'app/models/db_service'
5
22
  require 'app/models/common_service'
23
+ require 'app/models/base64'
6
24
  require 'app/ui/client_base'
7
25
 
8
26
  class Ooor
@@ -29,7 +47,7 @@ class Ooor
29
47
  def initialize(config, env=false)
30
48
  @config = config.is_a?(String) ? Ooor.load_config(config, env) : config
31
49
  @config.symbolize_keys!
32
- @logger = ((defined?(Rails) && $0 != 'irb' || config[:force_rails_logger]) ? Rails.logger : Logger.new(STDOUT))
50
+ @logger = ((defined?(Rails) && $0 != 'irb' || config[:force_rails_logger]) ? Rails.logger : Logger.new($stdout))
33
51
  @logger.level = config[:log_level] if config[:log_level]
34
52
  OpenObjectResource.logger = @logger
35
53
  @base_url = config[:url].gsub(/\/$/,'')
@@ -47,22 +65,18 @@ class Ooor
47
65
  def load_models(to_load_models=@config[:models])
48
66
  @global_context = @config[:global_context] || {}
49
67
  global_login(@config[:username] || 'admin', @config[:password] || 'admin')
50
- @ir_model_class = define_openerp_model("ir.model", @config[:scope_prefix])
51
- define_openerp_model("ir.model.fields", @config[:scope_prefix])
68
+ @ir_model_class = define_openerp_model({'model' => 'ir.model'}, @config[:scope_prefix])
52
69
  if to_load_models #we load only a customized subset of the OpenERP models
53
- models = @ir_model_class.find(:all, :domain => [['model', 'in', to_load_models]])
70
+ model_ids = @ir_model_class.search([['model', 'in', to_load_models]])
54
71
  else #we load all the models
55
- models = @ir_model_class.find(:all).reject {|model| ["ir.model", "ir.model.fields"].index model.model}
72
+ model_ids = @ir_model_class.search() - [1, 2]
56
73
  end
74
+ models = @ir_model_class.read(model_ids, ['name', 'model', 'id', 'info', 'state', 'field_id', 'access_ids'])
57
75
  @global_context.merge!({}).merge!(@config[:global_context] || {})
58
76
  models.each {|openerp_model| define_openerp_model(openerp_model, @config[:scope_prefix])}
59
77
  end
60
78
 
61
- def define_openerp_model(arg, scope_prefix=nil, url=nil, database=nil, user_id=nil, pass=nil)
62
- if arg.is_a?(String) && arg != 'ir.model' && arg != 'ir.model.fields'
63
- arg = @ir_model_class.find(:first, :domain => [['model', '=', arg]])
64
- end
65
- param = (arg.is_a? OpenObjectResource) ? arg.attributes.merge(arg.relations) : {'model' => arg}
79
+ def define_openerp_model(param, scope_prefix=nil, url=nil, database=nil, user_id=nil, pass=nil)
66
80
  klass = Class.new(OpenObjectResource)
67
81
  klass.ooor = self
68
82
  klass.site = url || @base_url
data/ooor.yml CHANGED
@@ -6,8 +6,7 @@ development:
6
6
  database: database_name #the OpenERP database you want to connect to
7
7
  username: admin
8
8
  password: admin
9
- #comment the following line if you want to load ALL the available models (slower startup), or complete it with all the OpenERP models you want to be loaded
10
- models: [res.partner, product.template, product.product, product.category, sale.order, sale.order.line, account.invoice]
9
+ #models: [res.partner, product.template, product.product, product.category, sale.order, sale.order.line, account.invoice] #you can allow only some models if you like
11
10
  bootstrap: true #true if you want to load OpenObject models (will hit OpenERP server) at startup; else use Ooor.reload!(lambda {}) to reload the Ooor models at any time
12
11
  #log_level: 0
13
12
  #global_context:
@@ -18,7 +17,6 @@ test:
18
17
  database: database_name
19
18
  username: admin
20
19
  password: admin
21
- models: [res.partner, product.template, product.product, product.category, sale.order, sale.order.line, account.invoice]
22
20
  bootstrap: true
23
21
 
24
22
  production:
@@ -26,5 +24,4 @@ production:
26
24
  database: database_name
27
25
  username: admin
28
26
  password: admin
29
- models: [res.partner, product.template, product.product, product.category, sale.order, sale.order.line, account.invoice]
30
27
  bootstrap: true
@@ -101,6 +101,11 @@ describe Ooor do
101
101
  partners = ResPartner.find(:all, :params => {:supplier => true})
102
102
  partners.should_not be_empty
103
103
  end
104
+
105
+ it "should mimic ActiveResource scoping with first" do
106
+ partner = ResPartner.find(:first, :params => {:customer => true})
107
+ partner.should be_kind_of ResPartner
108
+ end
104
109
 
105
110
  it "should support OpenERP context in finders" do
106
111
  p = ProductProduct.find(1, :context => {:my_key => 'value'})
@@ -136,12 +141,17 @@ describe Ooor do
136
141
  it "should read one2many relations" do
137
142
  o = SaleOrder.find(1)
138
143
  o.order_line.each do |line|
139
- line.should be_kind_of(SaleOrderLine)
144
+ line.should be_kind_of(SaleOrderLine)
140
145
  end
141
146
  end
142
147
 
143
148
  it "should read many2many relations" do
144
- SaleOrder.find(1).order_line[1].invoice_ids.should be_kind_of(Array)
149
+ s = SaleOrder.find(1)
150
+ s.order_policy = 'manual'
151
+ s.save
152
+ s.wkf_action('order_confirm')
153
+ s.wkf_action('manual_invoice')
154
+ SaleOrder.find(1).order_line[1].invoice_lines.should be_kind_of(Array)
145
155
  end
146
156
 
147
157
  it "should read polymorphic references" do
@@ -159,6 +169,23 @@ describe Ooor do
159
169
  p.categ_id.id.should == 1
160
170
  end
161
171
 
172
+ it "should support the context at object creation" do
173
+ p = ProductProduct.new({:name => "testProduct1", :categ_id => 1}, false, {:lang => 'en_US', :user_id=>1, :password => 'admin'})
174
+ p.object_session[:context][:lang] .should == 'en_US'
175
+ p.object_session[:user_id].should == 1
176
+ p.object_session[:password].should == "admin"
177
+ p.save
178
+ end
179
+
180
+ it "should support context when instanciating collections" do
181
+ products = ProductProduct.find([1, 2, 3], :context => {:lang => 'en_US', :user_id=>1, :password => 'admin'})
182
+ p = products[0]
183
+ p.object_session[:context][:lang] .should == 'en_US'
184
+ p.object_session[:user_id].should == 1
185
+ p.object_session[:password].should == "admin"
186
+ p.save
187
+ end
188
+
162
189
  it "should be able to create an order" do
163
190
  o = SaleOrder.create(:partner_id => ResPartner.search([['name', 'ilike', 'Agrolait']])[0],
164
191
  :partner_order_id => 1, :partner_invoice_id => 1, :partner_shipping_id => 1, :pricelist_id => 1)
@@ -193,7 +220,8 @@ describe Ooor do
193
220
  end
194
221
 
195
222
  it "should skipped inherited default fields properly, for instance at product variant creation" do
196
- ProductProduct.create(:product_tmpl_id => 25, :code => 'OOOR variant').should be_kind_of(ProductProduct)
223
+ #note that we force [] here for the default_get_fields otherwise OpenERP will blows up while trying to write in the product template!
224
+ ProductProduct.create({:product_tmpl_id => 25, :code => 'OOOR variant'}, {}, []).should be_kind_of(ProductProduct)
197
225
  end
198
226
  end
199
227
 
metadata CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
6
  - 1
7
- - 3
8
- - 2
9
- version: 1.3.2
7
+ - 4
8
+ - 0
9
+ version: 1.4.0
10
10
  platform: ruby
11
11
  authors:
12
12
  - Raphael Valyi - www.akretion.com
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-03-12 00:00:00 -03:00
17
+ date: 2010-07-05 00:00:00 -03:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -41,11 +41,12 @@ extra_rdoc_files: []
41
41
 
42
42
  files:
43
43
  - README.md
44
- - MIT-LICENSE
44
+ - agpl-3.0-licence.txt
45
45
  - lib/ooor.rb
46
46
  - ooor.yml
47
47
  - lib/app/models/open_object_resource.rb
48
48
  - lib/app/models/uml.rb
49
+ - lib/app/models/base64.rb
49
50
  - lib/app/models/db_service.rb
50
51
  - lib/app/models/common_service.rb
51
52
  - lib/app/ui/action_window.rb
@@ -1,20 +0,0 @@
1
- Copyright (c) 2009 [Raphaël Valyi]
2
-
3
- Permission is hereby granted, free of charge, to any person obtaining
4
- a copy of this software and associated documentation files (the
5
- "Software"), to deal in the Software without restriction, including
6
- without limitation the rights to use, copy, modify, merge, publish,
7
- distribute, sublicense, and/or sell copies of the Software, and to
8
- permit persons to whom the Software is furnished to do so, subject to
9
- the following conditions:
10
-
11
- The above copyright notice and this permission notice shall be
12
- included in all copies or substantial portions of the Software.
13
-
14
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
- LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
- OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
- WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.