Top Level Namespace
Defined Under Namespace
Modules: CucumberOpenERP, MemoizerUtils, OoorUtils, SequelUtils
Classes: BasicObject, OoorProxy, ScenarioUtils, SequelProxy
Instance Method Summary
collapse
Instance Method Details
#_manage_col_search(field_def, value) ⇒ Object
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
|
# File 'lib/cucumber/openerp/dsl.rb', line 43
def _manage_col_search(field_def, value)
oclass = Object.const_get(field_def['relation'].split('.').collect {|s| s.capitalize}.join)
oid = nil
if value.start_with? 'by '
comm_ext, arguments = prepare_args(value.gsub('by ', ''))
arguments.push({:fields=>['id']})
oid = oclass.send(('find_by_'+comm_ext).to_sym, *arguments)
else
eval "oid = oclass.#{value}"
end
unless oid
raise "Can not find #{value}"
end
return oid
end
|
#get_items(action, qty, model, args) ⇒ Object
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
|
# File 'lib/cucumber/openerp/dsl.rb', line 14
def get_items(action, qty, model, args)
@found_items = nil
@found_item = nil
oclass = Object.const_get(model.split('.').collect {|s| s.capitalize}.join)
unique_mode = ['create', 'need', 'find or create']
if qty == 'all'
if unique_mode.include? action
raise "#{unique_mode.inspect} does not allows 'all' keyword"
end
qty = 'all_'
else
qty = ''
end
command_map = {'create' => 'new', 'need' => 'find_or_initialize_by_', 'shoud_have' => "find_#{qty}by_", 'find' => "find_#{qty}by_", 'find or create' => 'find_or_initialize_by_'}
comm_ext, arguments = prepare_args(args)
arguments.push({:fields=>['id']})
if command_map[action] == 'create'
if oclass.send(('find_by_'+comm_ext).to_sym, *arguments)
raise "Error object allerady exist if this is not the wished behavior please use need keyword"
end
end
res = oclass.send((command_map[action]+comm_ext).to_sym, *arguments)
if @found_items.is_a? Array
@found_items = res
else
@found_item = res
end
end
|
#manage_item_table(item, table) ⇒ Object
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
|
# File 'lib/cucumber/openerp/dsl.rb', line 59
def manage_item_table(item, table)
fields = {}
fields.merge! item.class.many2one_associations
fields.merge! item.class.one2many_associations
fields.merge! item.class.many2many_associations
table.hashes.each do |dict|
if fields[dict['name']]
rel_item = _manage_col_search(fields[dict['name']], dict['value'])
eval "item.#{dict['name']} = rel_item.id"
else
value = dict['value']
v_type = item.class.fields.fetch(dict['name'],{}).fetch('type', nil)
if v_type == 'integer'
value = Integer(value)
elsif v_type == 'float'
value = Float(value)
elsif v_type == 'boolean'
if [nil, 0, false, ''].include? value
value = false
end
elsif ['date', 'datetime'].include? v_type
if value.include? "%"
value = Time.new().strftime(value)
end
end
eval "item.#{dict['name']} = value"
end
end
end
|
#prepare_args(args) ⇒ Object
1
2
3
4
5
6
7
8
9
10
11
12
|
# File 'lib/cucumber/openerp/dsl.rb', line 1
def prepare_args(args)
mixed = args.strip.split(' and ')
attrs = []
arguments = []
mixed.each do |set|
tmp = set.split(':')
attrs.push(tmp[0].strip)
arguments.push(tmp[1].strip)
end
attrs_string = attrs.join('_and_')
return attrs_string, arguments
end
|