cucumber-openerpscenario 0.1.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.
@@ -0,0 +1,51 @@
1
+ # -*- encoding: utf-8 -*-
2
+ #################################################################################
3
+ # #
4
+ # OERPScenario, OpenERP Functional Tests #
5
+ # Copyright (C) 2011 Akretion Benoît Guillot <benoit.guillot@akretion.com> #
6
+ # #
7
+ # This program is free software: you can redistribute it and/or modify #
8
+ # it under the terms of the GNU General Public License as published by #
9
+ # the Free Software Foundation, either version 3 Afero of the License, or #
10
+ # (at your option) any later version. #
11
+ # #
12
+ # This program is distributed in the hope that it will be useful, #
13
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of #
14
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
15
+ # GNU General Public License for more details. #
16
+ # #
17
+ # You should have received a copy of the GNU General Public License #
18
+ # along with this program. If not, see <http://www.gnu.org/licenses/>. #
19
+ # #
20
+ #################################################################################
21
+ require 'rubygems'
22
+ require 'ooor'
23
+ require 'pp'
24
+
25
+
26
+ begin
27
+ if Object.const_defined? 'AccountVoucher'
28
+
29
+ # Add useful methode on voucher handling
30
+ ##############################################################################
31
+ AccountVoucher.class_eval do
32
+ $utils.log.debug("Extending #{self.class} #{self.name}")
33
+
34
+ def self.create_voucher(options={})
35
+ if options[:invoice_id]
36
+ invoice = AccountInvoice.find(options[:invoice_id])
37
+ journal = AccountJournal.find(:first, :domain => [['type', '=', 'cash']])
38
+ toreturn = AccountVoucher.new(:currency_id => invoice.currency_id.id, :partner_id => invoice.partner_id.id, :account_id => journal.default_debit_account_id.id, :journal_id => journal.id, :type => 'receipt', :amount => invoice.amount_total)
39
+ toreturn.save
40
+ line = AccountVoucherLine.new(:voucher_id => toreturn.id, :type => 'cr', :account_id => invoice.account_id.id, :amount => invoice.amount_total, :name => invoice.origin)
41
+ line.save
42
+ return toreturn
43
+ end
44
+ end
45
+ end
46
+ else
47
+ $utils.log.debug("AccountVoucher helper not initialized")
48
+ end
49
+ rescue Exception => e
50
+ $utils.log.fatal("ERROR : #{e.to_s}")
51
+ end
@@ -0,0 +1,228 @@
1
+ ###############################################################################
2
+ #
3
+ # OERPScenario, OpenERP Functional Tests
4
+ # Author Nicolas Bessi & Joel Grand-Guillaume 2009
5
+ # Copyright Camptocamp SA
6
+ #
7
+ # This program is free software: you can redistribute it and/or modify
8
+ # it under the terms of the GNU General Public License as published by
9
+ # the Free Software Foundation, either version 3 Afero of the License, or
10
+ # (at your option) any later version.
11
+ #
12
+ # This program is distributed in the hope that it will be useful,
13
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
+ # GNU General Public License for more details.
16
+ #
17
+ # You should have received a copy of the GNU General Public License
18
+ # along with this program. If not, see <http://www.gnu.org/licenses/>.
19
+ #
20
+ ##############################################################################
21
+ require 'pp'
22
+ require 'rubygems'
23
+ require 'ooor'
24
+
25
+ begin
26
+ if Object.const_defined? 'IrModuleModule'
27
+ ###############################################################################
28
+ # Add useful methode on ir.module,module handling
29
+ ##############################################################################
30
+ IrModuleModule.class_eval do
31
+ $utils.log.debug("Extending #{self.class} #{self.name}")
32
+ ##########################################################################
33
+ # Run the upgrade wizard on all modules
34
+ # Input :
35
+ # -
36
+ # Return
37
+ # - True
38
+ # Usage Example:
39
+ # res = IrModuleModule.update_needed_modules()
40
+ # Deprecated
41
+ def self.update_needed_modules()
42
+ $utils.log.debug("DEBUG : update_needed_modules is deprecated")
43
+ # Call the wizard on whatever module
44
+ wizard = IrModuleModule.find(:first).old_wizard_step('module.upgrade.simple')
45
+ # Run all state of the wizard
46
+ step_dict = wizard.datas.merge({})
47
+ res=wizard.init(step_dict)
48
+
49
+ step_dict=res.datas.merge(step_dict)
50
+ res=wizard.next(step_dict)
51
+
52
+ step_dict=res.datas.merge(step_dict)
53
+ res=wizard.start(step_dict)
54
+
55
+ step_dict=res.datas.merge(step_dict)
56
+ res=wizard.end(step_dict)
57
+ $utils.ooor.load_models(false)
58
+ if res
59
+ return true
60
+ else
61
+ raise "!!! --- HELPER ERROR : update_needed_modules was unable to upgrade needed modules.."
62
+ end
63
+ end
64
+
65
+ ##########################################################################
66
+ # Run the quality check wizard on all requested modules
67
+ # Input :
68
+ # - modules : A [] of valid IrModuleModule instance
69
+ # Return
70
+ # - [] of Created ModuleQualityCheck instances
71
+ # Usage Example:
72
+ # result = IrModuleModule.run_base_quality_test(modules)
73
+ if Object.const_defined? 'ModuleQualityCheck'
74
+ def self.run_base_quality_test(modules)
75
+ # Take the id of already recorded tests result
76
+ # because we are unable to retrieve their ids from wizard
77
+ # cause it has only one step 'init'
78
+ already_stored_test_ids=[]
79
+ ModuleQualityCheck.find(:all).each do |stored_result|
80
+ already_stored_test_ids.push stored_result.id
81
+ end
82
+ modules.each do |m|
83
+ # Call the wizard on module
84
+ wizard = m.old_wizard_step('create_quality_check_wiz')
85
+ end
86
+
87
+ # Find all recorded tests, and substract old created ones
88
+ all_stored_test_ids=[]
89
+ ModuleQualityCheck.find(:all).each do |stored_result|
90
+ all_stored_test_ids.push stored_result.id
91
+ end
92
+ new_ids=all_stored_test_ids-already_stored_test_ids
93
+ res= ModuleQualityCheck.find(new_ids)
94
+
95
+ if res
96
+ return res
97
+ else
98
+ raise "!!! --- HELPER ERROR : run_base_quality_test was unable to upgrade needed modules.."
99
+ end
100
+ end
101
+ else
102
+ def self.run_base_quality_test(modules)
103
+ $utils.log.info("INFO : Function not available")
104
+ end
105
+ end
106
+
107
+ ##########################################################################
108
+ # Run the upgrade wizard on all installed module, after the demo checkbox
109
+ # had beend ticked and the state set to 'to upgrade' on the base module.
110
+ # Does nothing if module are already with demo data
111
+ # Input :
112
+ # -
113
+ # Return
114
+ # - True
115
+ # Usage Example:
116
+ # res = IrModuleModule.load_demo_data_on_installed_modules()
117
+ def self.load_demo_data_on_installed_modules()
118
+ # find installed modules
119
+ modules=IrModuleModule.find(:all, :domain => [['state', '=', 'installed']], :fields => ['id, demo, update', 'state'])
120
+ update=false
121
+ res=true
122
+ modules.each do |m|
123
+ if not m.demo
124
+ m.demo=true
125
+ update=true
126
+ m.save
127
+ m = nil
128
+ end
129
+ end
130
+ # Find module base and set it to to upgrade if there is some module to update
131
+ if update
132
+ m=IrModuleModule.find(:first, :domain => [['name', '=', 'base']], :fields => ['id, demo, update, state'])
133
+ m.state='to upgrade'
134
+ m.save
135
+ m = nil
136
+ end
137
+
138
+ if res
139
+ return true
140
+ else
141
+ raise "!!! --- HELPER ERROR : load_demo_data_on_installed_modules was unable to upgrade needed modules.."
142
+ end
143
+ res = IrModuleModule.update_needed_modules()
144
+ end
145
+
146
+
147
+ ##########################################################################
148
+ # Get recursively the whole list of modules dependencies
149
+ # for a list of modules.
150
+ # Do not add the module if it already exists in the input list
151
+ # Input :
152
+ # - modules : A [] of valid IrModuleModule instances with dependencies_id attribute
153
+ # Return
154
+ # - [] of dependencies
155
+ # Usage Example:
156
+ # dependency_modules = get_dependencies(modules)
157
+ def self.get_dependencies(modules)
158
+ dependency_modules = []
159
+ modules.select { |m| m.dependencies_id }.each do |mod|
160
+ mod.dependencies_id.each do |dep|
161
+ dep_module = IrModuleModule.find(:first,
162
+ :domain => [['name', '=', dep.name]],
163
+ :fields => ['id', 'state', 'dependencies_id'])
164
+ if dep_module.nil?
165
+ raise RuntimeError, "#{dep.name} not found"
166
+ end
167
+ dependency_modules << dep_module unless modules.map { |m| m.id }.include? dep_module.id
168
+ end
169
+ end
170
+ dependency_modules.concat(get_dependencies(dependency_modules)) if dependency_modules.count > 0
171
+ dependency_modules
172
+ end
173
+
174
+ ##########################################################################
175
+ # Run the upgrade wizard in order to install the required
176
+ # modules. Upgrade installed modules as well.
177
+ # Input :
178
+ # - modules : A [] of valid IrModuleModule instance
179
+ # Return
180
+ # - True
181
+ # Usage Example:
182
+ # res = IrModuleModule.install_modules(modules)
183
+ def self.install_modules(modules, dependencies=false)
184
+ res = true
185
+ if dependencies
186
+ dependency_modules = get_dependencies(modules)
187
+ modules.concat(dependency_modules) if dependency_modules
188
+ end
189
+ modules_toinstall_ids = []
190
+ modules_toupgrade_ids = []
191
+ # If not installed, do it. Otherwise update it
192
+ modules.each do |m|
193
+ if m.state == 'uninstalled'
194
+ m.state = 'to install'
195
+ m.save
196
+ modules_toinstall_ids << m.id
197
+ elsif m.state == 'installed'
198
+ m.state = 'to upgrade'
199
+ m.save
200
+ modules_toupgrade_ids << m.id
201
+ elsif m.state == 'to install'
202
+ modules_toinstall_ids << m.id
203
+ elsif m.state == 'to upgrade'
204
+ modules_toupgrade_ids << m.id
205
+ end
206
+ end
207
+ #First installed required modules, then upgrade the others
208
+ upgrade = BaseModuleUpgrade.create()
209
+ upgrade.upgrade_module()
210
+ # IrModuleModule.button_install(modules_toinstall_ids)
211
+ # IrModuleModule.button_upgrade(modules_toupgrade_ids)
212
+
213
+ if res
214
+ return true
215
+ else
216
+ raise "!!! --- HELPER ERROR : install_modules was unable to install needed modules.."
217
+ end
218
+ $utils.ooor.load_models() # reload in order to have model Classes for modules installed
219
+ end
220
+
221
+ end
222
+
223
+ else
224
+ $utils.log.debug("IrModuleModule helper not initialized")
225
+ end
226
+ rescue Exception => e
227
+ $utils.log.fatal("ERROR : #{e.to_s}")
228
+ end
@@ -0,0 +1,93 @@
1
+ ###############################################################################
2
+ #
3
+ # OERPScenario, OpenERP Functional Tests
4
+ # Author Joel Grand-Guillaume 2009
5
+ # Copyright Camptocamp SA
6
+ #
7
+ # This program is free software: you can redistribute it and/or modify
8
+ # it under the terms of the GNU General Public License as published by
9
+ # the Free Software Foundation, either version 3 Afero of the License, or
10
+ # (at your option) any later version.
11
+ #
12
+ # This program is distributed in the hope that it will be useful,
13
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
+ # GNU General Public License for more details.
16
+ #
17
+ # You should have received a copy of the GNU General Public License
18
+ # along with this program. If not, see <http://www.gnu.org/licenses/>.
19
+ #
20
+ ##############################################################################
21
+ require 'pp'
22
+ require 'rubygems'
23
+ require 'ooor'
24
+
25
+
26
+ # Add useful methode on base module quality check module handling
27
+ ##############################################################################
28
+ begin
29
+ if Object.const_defined? 'ModuleQualityCheck'
30
+ ModuleQualityCheck.class_eval do
31
+ $utils.log.debug("Extending #{self.class} #{self.name}")
32
+ ##########################################################################
33
+ # Print out the tests result
34
+ # Input :
35
+ # - qualityinstance : A Valid ModuleQualityCheck instance
36
+ # Return
37
+ # - Nice string to print
38
+ # Usage Example:
39
+ # print ModuleQualityCheck.get_formatted_results(qualityinstance)
40
+ def self.get_formatted_results(qualityinstance)
41
+ result=true
42
+ title=""
43
+ summary=""
44
+ # title="<pre>"+"\n"+"\n"
45
+ title+="Module : " + qualityinstance.name + " Scored : " + qualityinstance.final_score + "\n"
46
+ title+="-------------------------------------------------------"
47
+
48
+ # summary="\n"+"\n"
49
+ summary+= qualityinstance.final_score + " Scored for : " + qualityinstance.name + "\n"
50
+ # summary+=qualityinstance.name + " Scored : " + qualityinstance.final_score + "\n"
51
+
52
+
53
+ details="\n"
54
+ qualityinstance.check_detail_ids.each do |detail|
55
+ details+=detail.name + " (State: " + detail.state + ") Scored : " + detail.score.to_s + "\n"
56
+ details+="Ponderation: "+ detail.ponderation.to_s + "\n"
57
+ details+="Note: "+ detail.note + "\n"
58
+ end
59
+ result=title+details
60
+ # result=title+details+"</pre>"
61
+
62
+ if result
63
+ return {:summary => summary, :result => result}
64
+ else
65
+ raise "!!! --- HELPER ERROR :get_formatted_results !"
66
+ end
67
+ end
68
+ end
69
+
70
+ ModuleQualityDetail.class_eval do
71
+ ##########################################################################
72
+ # Print out the tests result
73
+ # Input :
74
+ # -
75
+ # Return
76
+ # - Nice print
77
+ # Usage Example:
78
+ # modules_ids = My_ModuleQualityInstance.print_formatted_results()
79
+ # def print_formatted_results()
80
+ #
81
+ # if result :
82
+ # return result
83
+ # else
84
+ # raise "!!! --- HELPER ERROR :get_supplier found #{type} named #{name}, but without adresses"
85
+ # end
86
+ # end
87
+ end
88
+ else
89
+ $utils.log.debug("ModuleQualityCheck helper not initialized")
90
+ end
91
+ rescue Exception => e
92
+ $utils.log.fatal("ERROR : #{e.to_s}")
93
+ end
@@ -0,0 +1,41 @@
1
+ # -*- encoding: utf-8 -*-
2
+ #################################################################################
3
+ # #
4
+ # OERPScenario, OpenERP Functional Tests #
5
+ # Copyright (C) 2011 Akretion Benoît Guillot <benoit.guillot@akretion.com> #
6
+ # #
7
+ # This program is free software: you can redistribute it and/or modify #
8
+ # it under the terms of the GNU General Public License as published by #
9
+ # the Free Software Foundation, either version 3 Afero of the License, or #
10
+ # (at your option) any later version. #
11
+ # #
12
+ # This program is distributed in the hope that it will be useful, #
13
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of #
14
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
15
+ # GNU General Public License for more details. #
16
+ # #
17
+ # You should have received a copy of the GNU General Public License #
18
+ # along with this program. If not, see <http://www.gnu.org/licenses/>. #
19
+ # #
20
+ #################################################################################
21
+ require 'pp'
22
+ require 'rubygems'
23
+ require 'ooor'
24
+
25
+ begin
26
+ Ooor.class_eval do
27
+ $utils.log.debug("Extending #{self.class} #{self.name}")
28
+ # Add useful methode on ooor handling
29
+
30
+ def self.to_ary
31
+ return [name]
32
+ end
33
+
34
+ def self.new_database(options)
35
+ @ooor = self.new(:url => options[:url])
36
+ @ooor.create(options[:db_password], options[:database], options[:demo_data], options[:lang], options[:password])
37
+ end
38
+ end
39
+ rescue Exception => e
40
+ $utils.log.fatal("ERROR : #{e.to_s}")
41
+ end
@@ -0,0 +1,126 @@
1
+ ###############################################################################
2
+ #
3
+ # OERPScenario, OpenERP Functional Tests
4
+ # Author Nicolas Bessi & Joel Grand-Guillaume 2009
5
+ # Copyright Camptocamp SA
6
+ #
7
+ # This program is free software: you can redistribute it and/or modify
8
+ # it under the terms of the GNU General Public License as published by
9
+ # the Free Software Foundation, either version 3 Afero of the License, or
10
+ # (at your option) any later version.
11
+ #
12
+ # This program is distributed in the hope that it will be useful,
13
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
+ # GNU General Public License for more details.
16
+ #
17
+ # You should have received a copy of the GNU General Public License
18
+ # along with this program. If not, see <http://www.gnu.org/licenses/>.
19
+ #
20
+ ##############################################################################
21
+
22
+ begin
23
+ if Object.const_defined? 'ProductProduct'
24
+ ProductProduct.class_eval do
25
+ $utils.log.debug("Extending #{self.class} #{self.name}")
26
+ # Add useful methode on product handling
27
+
28
+ def self.to_ary
29
+ return [name]
30
+ end
31
+
32
+ def self.get_valid_product(options={})
33
+ unless options
34
+ options = {}
35
+ end
36
+ if options.is_a? Integer
37
+ return ProductProduct.find(options)
38
+ end
39
+ product = false
40
+ # To avoid error when a supplier info or an orderpoint is needed a new product is always created
41
+ if not (options[:new] || options[:supplierinfo] || options[:ordepoint])
42
+ domain = options[:domain] || []
43
+ field = []
44
+ options.each do |key, value|
45
+ if key == :product_id
46
+ return ProductProduct.find(value, :fields => field)
47
+ elsif key == :name
48
+ domain.push ['name', 'ilike', value]
49
+ elsif key == :type
50
+ domain.push [value, '=', true]
51
+ elsif key == :fields
52
+ field = value
53
+ elsif key != domain
54
+ domain.push [key.to_s, '=', value]
55
+ end
56
+ end
57
+ product = find(:first, :domain => domain, :fields => field)
58
+ end
59
+ unless product
60
+ createoptions = {:name => 'scenarioproduct'}
61
+ options.each do |key, value|
62
+ if not [:domain, :fields, :new, :supplierinfo, :orderpoint].include?(key)
63
+ createoptions[key] = value
64
+ end
65
+ end
66
+ product = ProductProduct.new(createoptions)
67
+ product.save
68
+ if options[:supplierinfo]
69
+ @supplier = ResPartner.get_valid_partner(options[:supplierinfo][:supplier])
70
+ user_id = $utils.ooor.config[:user_id]
71
+ user = ResUsers.find(:id => user_id)
72
+ supplierinfo_options = {
73
+ :name => @supplier.id,
74
+ :product_name => product.name,
75
+ :min_qty => 1,
76
+ :qty => 1,
77
+ :product_id => product.id,
78
+ :company_id => user.company_id.id,
79
+ }
80
+ options[:supplierinfo].each do |key, value|
81
+ if key != :supplier
82
+ supplierinfo_options[key] = value
83
+ end
84
+ end
85
+ new_supplierinfo = ProductSupplierinfo.new(supplierinfo_options)
86
+ new_supplierinfo.save
87
+ end
88
+ if options[:orderpoint]
89
+ default_stock_location_id = StockLocation.search([['name', '=', 'Stock']])[0]
90
+ default_warehouse_id = StockWarehouse.search()[0]
91
+ user_id = $utils.ooor.config[:user_id]
92
+ user = ResUsers.find(:id => user_id)
93
+ orderpoint_options = {
94
+ :product_id => product.id,
95
+ :location_id => default_stock_location_id,
96
+ :warehouse_id => default_warehouse_id,
97
+ :company_id => user.company_id.id,
98
+ :product_max_qty => 0,
99
+ :product_uom => product.uom_id.id,
100
+ }
101
+ options[:orderpoint].each do |key, value|
102
+ orderpoint_options[key] = value
103
+ end
104
+ new_orderpoint = StockWarehouseOrderpoint.new(orderpoint_options)
105
+ new_orderpoint.save
106
+ end
107
+ end
108
+ if options[:qty_available]
109
+ location_id = StockLocation.search(:name => 'Stock')[0]
110
+ wizard = StockChangeProductQty.new(
111
+ :product_id => product.id,
112
+ :new_quantity => options[:qty_available],
113
+ :location_id => location_id
114
+ )
115
+ wizard.save
116
+ wizard.change_product_qty(context={:active_id => product.id})
117
+ end
118
+ return product
119
+ end
120
+ end
121
+ else
122
+ $utils.log.debug("ProductProduct helper not initialized")
123
+ end
124
+ rescue Exception => e
125
+ $utils.log.fatal("ERROR : #{e.to_s}")
126
+ end