cucumber-openerpscenario 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/.DS_Store ADDED
Binary file
data/README.txt ADDED
File without changes
File without changes
@@ -0,0 +1,14 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = %q{cucumber-openerpscenario}
3
+ s.version = "0.1.0"
4
+ s.date = %q{2013-03-06}
5
+ s.authors = ["Nicolas Bessi - Camptocamp"]
6
+ s.summary = %q{cucumber on OpenERP}
7
+ s.description = %q{cucumber on OpenERP}
8
+ s.add_dependency(%q<ooor>, [">= 1.6.5"])
9
+ s.add_dependency(%q<ooor-finders>)
10
+ s.add_dependency(%q<cucumber>)
11
+ s.add_dependency(%q<parseconfig>)
12
+ s.files = `bzr ls -R`.split("\n")
13
+ s.require_path = 'lib'
14
+ end
data/lib/.DS_Store ADDED
Binary file
Binary file
Binary file
@@ -0,0 +1,75 @@
1
+ ###############################################################################
2
+ #
3
+ # OERPScenario, OpenERP Functional Tests
4
+ # Author Nicolas Bessi 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
+ # This class map OpenERP XMLRPC logins and common stuff
22
+ class ScenarioUtils
23
+ include MemoizerUtils
24
+ include OoorUtils
25
+ include SequelUtils
26
+
27
+ attr_accessor :log
28
+
29
+ def initialize
30
+ @uid = false
31
+ @log = Logger.new(STDOUT)
32
+ @log.level = Logger::WARN
33
+ end
34
+
35
+ def config
36
+ @config ||= get_config
37
+ end
38
+
39
+ def config_path
40
+ ENV['CONF'] || 'base.conf'
41
+ end
42
+ private :config_path
43
+
44
+ def get_config
45
+ my_config = ParseConfig.new(config_path)
46
+
47
+ {# ooor options
48
+ :port => my_config.get_value('port'),
49
+ :user => my_config.get_value('user'),
50
+ :dbname => my_config.get_value('database'),
51
+ :pwd => my_config.get_value('password'),
52
+ :host => my_config.get_value('host'),
53
+ :log_level => Logger::ERROR,
54
+
55
+ # sequel options
56
+ :db_host => my_config.get_value('db_host'),
57
+ :db_port => my_config.get_value('db_port'),
58
+ :db_user => my_config.get_value('db_user'),
59
+ :db_password => my_config.get_value('db_password')}
60
+ end
61
+ private :get_config
62
+
63
+ def helpers_absolute_path
64
+ #File.expand_path("Helpers/*", File.dirname(__FILE__))
65
+ end
66
+ private :helpers_absolute_path
67
+
68
+ def load_helpers
69
+ # TODO generic method to load each helper
70
+ # actually each ruby file contains the same
71
+ # code : test if class exists, run a class_eval
72
+ # Dir[helpers_absolute_path].each { |file| load file }
73
+ end
74
+ private :load_helpers
75
+ end
@@ -0,0 +1,156 @@
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 'rubygems'
22
+ require 'ooor'
23
+ require 'pp'
24
+
25
+
26
+ begin
27
+ if Object.const_defined? 'AccountBankStatement'
28
+
29
+ # Add useful methode on bank statement handling
30
+ ##############################################################################
31
+ AccountBankStatement.class_eval do
32
+ $utils.log.debug("Extending #{self.class} #{self.name}")
33
+ ############################################################################
34
+ # Import invoices into the given bank statements
35
+ # Input :
36
+ # - invoices : A valid dict of AccountInvoice instance
37
+ # - statement : A valid AccountBankStatement instance
38
+ # - options {
39
+ # date (Default today) : date used into the first screen of the wizard (date
40
+ # imported in lines)
41
+ # }
42
+ # Return
43
+ # - The AccountBankStatement as a instance of the class¨
44
+ # Usage Example:
45
+ # statement = AccountBankStatement.import_invoice(invoices,statement)
46
+ #
47
+ # TODO implement journals
48
+ # TODO filter acc_move_line_ids to take the right one
49
+ # TODO Remove self to use it from an instance of the class
50
+ def import_invoice(invoices, options={}, *args)
51
+ o = {:date => false, :journals => []}.merge(options)
52
+ if o[:date]
53
+ o[:date] = Date.parse(str=o[:date]).to_s
54
+ else
55
+ o[:date] = Date.today.to_s
56
+ end
57
+
58
+ # Parse the given journal ids if provided
59
+ journal_ids=[]
60
+ o[:journals].each do |journal|
61
+ journal_ids.push journal.id
62
+ end
63
+ invoice_move_line_ids=[]
64
+ inv_total=0.0
65
+ self.balance_start=inv_total
66
+
67
+ # # For each invoices, add the right account.move.line and compute total
68
+ invoices.each do |inv|
69
+ unless inv.class == AccountInvoice
70
+ raise "!!! --- HELPER ERROR :import_invoice received a #{inv.class.to_s} instead of AccountInvoice"
71
+ end
72
+ # Take the move ids from concerned invoice
73
+ # TODO add journal support and (journal_ids.include? move_line.journal_id or journal_ids == []
74
+ # TODO : Debug the problem of undefined method `[]' for nil:NilClass (NoMethodError)
75
+ # pp inv.move_id.line_id
76
+ # inv.move_id.line_id.each do |move_line|
77
+ #
78
+ # # if move_line.reconcile_id == false
79
+ # if move_line.account_id.reconcile == true
80
+ # invoice_move_line_ids.push move_line.id
81
+ # end
82
+ # end
83
+
84
+ inv.move_id.line_id.each do |move_line|
85
+ if (not move_line.reconcile_id) && move_line.account_id.reconcile
86
+ invoice_move_line_ids.push move_line.id
87
+ inv_total = inv_total + move_line.amount_currency
88
+ end
89
+ end
90
+ end
91
+ # Save the start and end values
92
+ self.balance_end_real=inv_total
93
+ self.save
94
+ unless self.class == AccountBankStatement
95
+ raise "!!! --- HELPER ERROR :import_invoice received a #{self.class.to_s} instead of AccountBankStatement"
96
+ end
97
+
98
+ # Call the wizard
99
+ wizard = self.old_wizard_step('populate_statement_from_inv')
100
+ # Set the wizard with given values
101
+ step_dict = wizard.datas.merge({:date => o[:date]})
102
+ step_dict=step_dict.merge({:journal_id => [[[], [], journal_ids]]})
103
+ # Search the invoices and update values
104
+ res=wizard.go(step_dict)
105
+ step_dict=res.datas.merge(step_dict)
106
+ # Update the step_dict with invoice we want
107
+ step_dict=step_dict.merge({:lines => [[[], [], invoice_move_line_ids]]})
108
+ # Ask to populate the statement with given invoice linked account move
109
+ res=wizard.finish(step_dict)
110
+ # step_dict = step_dict.merge({:writeoff_acc_id => @journal.default_debit_account_id.id, :writeoff_journal_id=>@journal.id})
111
+ # return res
112
+ end
113
+
114
+ ############################################################################
115
+ # Create an statement with given informations
116
+ # Input :
117
+ # - options {
118
+ # journal : A valid AccountJournal instance
119
+ # currency_code (Default : EUR) : An ISO code for currency
120
+ # name (Default : computed by OpenERP sequence) : A valid name if you wanna set it
121
+ # }
122
+ # Return
123
+ # - The created AccountBankStatement as a instance of the class¨
124
+ # Usage Example:
125
+ # statement = AccountBankStatement.create_statement_with_currency({currency_code =>'CHF'})
126
+ def self.create_statement_with_currency(options={}, *args)
127
+ o = {:currency_code => 'EUR', :journal => false, :name => false}.merge(options)
128
+ if not o[:journal]
129
+ # Take the currency
130
+ currency_id = ResCurrency.find(:first, :domain => [['name', '=', o[:currency_code]]]).id
131
+ if currency_id
132
+ # Look for the asked cash journal currency
133
+ journal = AccountJournal.find(:first, :domain => [['type', '=', 'cash'], ['currency', '=', currency_id]])
134
+ else
135
+ raise "!!! --- HELPER ERROR : create_statement_with_currency #{o[:currency_code]} currency not found"
136
+ end
137
+ else
138
+ journal = o[:journal]
139
+ end
140
+ toreturn = AccountBankStatement.new()
141
+ toreturn.journal_id = journal.id
142
+ toreturn.create
143
+ if o[:name]
144
+ toreturn.name=o[:name]
145
+ toreturn.save
146
+ end
147
+ return toreturn
148
+ end
149
+
150
+ end
151
+ else
152
+ $utils.log.debug("AccountBankStatement helper not initialized !")
153
+ end
154
+ rescue Exception => e
155
+ $utils.log.fatal("ERROR : #{e.to_s}")
156
+ end
@@ -0,0 +1,122 @@
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 'rubygems'
22
+ require 'ooor'
23
+ require 'pp'
24
+
25
+
26
+ begin
27
+ if Object.const_defined? 'AccountInvoice'
28
+ # Add useful methode on invoice handling
29
+ ##############################################################################
30
+ AccountInvoice.class_eval do
31
+ $utils.log.debug("Extending #{self.class} #{self.name}")
32
+ ##########################################################################
33
+ # Create an invoice with given informations
34
+ # Add a line if amount <> false, the account could be provided or not
35
+ # Input :
36
+ # - name : Name of the invoice
37
+ # - partner : A valid ResPartner instance
38
+ # - option {
39
+ # currency_code (Default : EUR) : An ISO code for currency
40
+ # date (Default : false) : A date in this text format : 1 jan 2009
41
+ # amount (Default : false) : An amount for the invoice => this will create a line
42
+ # account (Default : false) : An valide AccountAccount
43
+ # type (Default : out_invoice) : the invoice type
44
+ # }
45
+ # Return
46
+ # - The created AccountInvoice as a instance of the class¨
47
+ # Usage Example:
48
+ # part = ResPartner.find(:first)
49
+ # puts part.id
50
+ # inv = AccountInvoice.create_cust_invoice_with_currency('my name',part,{currency_code =>'CHF'})
51
+ def self.create_invoice_with_currency(name, partner, options={}, *args)
52
+ o = {:type => 'out_invoice', :currency_code => 'EUR', :date => false, :amount => false, :account => false}.merge(options)
53
+ if o[:date]
54
+ date_invoice = Date.parse(str=o[:date]).to_s
55
+ else
56
+ date_invoice = Date.today.to_s
57
+ end
58
+ toreturn = AccountInvoice.new()
59
+
60
+ unless partner.class == ResPartner
61
+ raise "!!! --- HELPER ERROR :create_cust_invoice_with_currency received a #{partner.class.to_s} instead of ResPartner"
62
+ end
63
+ # Set partner
64
+ #We use this syntax for optimisation reason, helper have to be fast
65
+ if ResPartnerAddress.find(:first, :domain => [['partner_id', '=', partner.id]], :fields => ['id'])
66
+ toreturn.partner_id = partner.id
67
+ else
68
+ raise "!!! --- HELPER ERROR :create_cust_invoice_with_currency received a partner : #{partner.name} without adresses"
69
+ end
70
+ toreturn.on_change('onchange_partner_id', :partner_id, partner.id, o[:type], partner.id, date_invoice, false, false)
71
+ toreturn.save
72
+ # Set name & date
73
+ toreturn.name = name
74
+ toreturn.date_invoice=date_invoice
75
+
76
+ # Set type of invoice
77
+ toreturn.type = o[:type]
78
+ curr = ResCurrency.find(:first, :domain => [['name', '=', o[:currency_code]]], :fields => ['id'])
79
+ # Set currency
80
+ if curr
81
+ toreturn.currency_id = curr.id
82
+ else
83
+ raise "!!! --- HELPER ERROR :#{o[:currency_code]} currency not found"
84
+ end
85
+
86
+ # Set amount and line if asked for
87
+ toreturn.save
88
+
89
+ if o[:amount]
90
+
91
+ if ['in_invoice', 'in_refund'].include? o[:type]
92
+ toreturn.check_total = o[:amount]
93
+ end
94
+ if o[:account]
95
+ unless account.class == AccountAccount
96
+ raise "!!! --- HELPER ERROR :create_cust_invoice_with_currency received a #{o[:account].class.to_s} instead of AccountAccount"
97
+ end
98
+ account_id = o[:account].id
99
+ else
100
+ # If no account, take on of type 'other' and a non-reconciliable account
101
+ account_id = AccountAccount.find(:first, :domain => [['type', '=', 'other'], ['reconcile', '=', false]], :fields => ['id']).id
102
+ # Create a line = amount for the created invoice
103
+ line=AccountInvoiceLine.new(
104
+ :account_id => account_id,
105
+ :quantity => 1,
106
+ :name => name+' line',
107
+ :price_unit => o[:amount],
108
+ :invoice_id => toreturn.id
109
+ )
110
+ line.create
111
+ end
112
+ end
113
+ toreturn.save
114
+ return toreturn
115
+ end
116
+ end
117
+ else
118
+ $utils.log.debug("AccountInvoice helper not initialized")
119
+ end
120
+ rescue Exception => e
121
+ $utils.log.fatal("ERROR : #{e.to_s}")
122
+ end
@@ -0,0 +1,85 @@
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 'rubygems'
22
+ require 'ooor'
23
+ require 'pp'
24
+
25
+
26
+ begin
27
+ if Object.const_defined? 'AccountTax'
28
+ # Add useful methode on taxes handling
29
+ ##############################################################################
30
+ AccountTax.class_eval do
31
+ $utils.log.debug("Extending #{self.class} #{self.name}")
32
+ ##########################################################################
33
+ # Create a tax and tax code with given informations
34
+ # Input :
35
+ # - name : Name of the tax
36
+ # - option {
37
+ # :type=>'percent',
38
+ # :amount=>0.196,
39
+ # :type_tax_use=>'sale',
40
+ # # For refund
41
+ # :ref_base_sign=>-1.0,
42
+ # :ref_tax_sign=>-1.0,
43
+ # # For VAT declaration
44
+ # :base_sign=>1.0,
45
+ # :tax_sign=>1.0,
46
+ # }
47
+ # Return
48
+ # - The created AccountTax as a instance of the class¨
49
+ # Usage Example:
50
+ # tax = AccountTax.create_tax_and_code('my name',{:type=>'percent',:amount=>rate,:type_tax_use=>'purchase',})
51
+ def self.create_tax_and_code(name, options={}, *args)
52
+ # debugger
53
+ # Set default values
54
+ o = {
55
+ :type => 'percent',
56
+ :amount => 0.196,
57
+ :type_tax_use => 'sale',
58
+ # For refund
59
+ :ref_base_sign => -1.0,
60
+ :ref_tax_sign => -1.0,
61
+ # For VAT declaration
62
+ :base_sign => 1.0,
63
+ :tax_sign => 1.0,
64
+ }.merge(options)
65
+
66
+ toreturn = AccountTax.new(o)
67
+ toreturn.name = name
68
+ toreturn.type = o[:type]
69
+ toreturn.amount = o[:amount]
70
+ toreturn.type_tax_use = o[:type_tax_use]
71
+ toreturn.ref_base_sign = o[:ref_base_sign]
72
+ toreturn.ref_tax_sign = o[:ref_tax_sign]
73
+ toreturn.base_sign = o[:base_sign]
74
+ toreturn.tax_sign = o[:tax_sign]
75
+
76
+ toreturn.create
77
+ return toreturn
78
+ end
79
+ end
80
+ else
81
+ $utils.log.debug("AccountTax helper not initialized")
82
+ end
83
+ rescue Exception => e
84
+ $utils.log.fatal("ERROR : #{e.to_s}")
85
+ end