Merge lp:~domsense/domsense-agilebg-addons/ea_import_catching_value_error into lp:~domsense/domsense-agilebg-addons/ea_import

Proposed by Alex Comba - Agile BG
Status: Merged
Merged at revision: 26
Proposed branch: lp:~domsense/domsense-agilebg-addons/ea_import_catching_value_error
Merge into: lp:~domsense/domsense-agilebg-addons/ea_import
Diff against target: 65 lines (+20/-3)
1 file modified
ea_import/ea_import_template_line.py (+20/-3)
To merge this branch: bzr merge lp:~domsense/domsense-agilebg-addons/ea_import_catching_value_error
Reviewer Review Type Date Requested Status
Agile Business Group Pending
Review via email: mp+148678@code.launchpad.net

Commit message

[ADD] ValueError catching and logging for template_line_type

Description of the change

Added ValueError catching and logging for template_line_type

To post a comment you must log in.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'ea_import/ea_import_template_line.py'
2--- ea_import/ea_import_template_line.py 2012-12-28 14:01:09 +0000
3+++ ea_import/ea_import_template_line.py 2013-02-15 11:52:24 +0000
4@@ -23,7 +23,9 @@
5 import datetime
6 from tools.translate import _
7 import base64
8+import logging
9
10+_logger = logging.getLogger('ea_import')
11
12 class ea_import_template_line(osv.osv):
13
14@@ -177,33 +179,48 @@
15 if template_line_type == 'binary':
16 return base64.b32encode(target_string)
17 elif template_line_type == 'integer':
18- return int(target_string)
19+ try:
20+ return int(target_string)
21+ except ValueError, e:
22+ _logger.warning('message: %s target_string: %s' % (e.message,target_string))
23+ return None
24 elif template_line_type == 'float':
25- return float(target_string)
26+ try:
27+ return float(target_string)
28+ except ValueError, e:
29+ _logger.warning('message: %s target_string: %s' % (e.message,target_string))
30+ return None
31 elif template_line_type == 'boolean':
32 if template_line.boolean_field_ids:
33 return template_line_boolean_field_pool.get_value(cr, uid,
34 [boolean_field.id for boolean_field in template_line.boolean_field_ids],
35 target_string, context=context)
36 else:
37- return bool(target_string)
38+ try:
39+ return bool(target_string)
40+ except ValueError, e:
41+ _logger.warning('message: %s target_string: %s' % (e.message,target_string))
42+ return None
43 elif template_line_type == 'date':
44 try:
45 target_time = datetime.datetime.strptime(target_string, template_line.time_format)
46 return target_time.strftime("%Y-%m-%d")
47 except ValueError:
48+ _logger.warning('message: %s target_string: %s' % (e.message,target_string))
49 return None
50 elif template_line_type == 'datetime':
51 try:
52 target_time = datetime.datetime.strptime(target_string, template_line.time_format)
53 return target_time.strftime("%Y-%m-%d %H:%M:%S")
54 except ValueError:
55+ _logger.warning('message: %s target_string: %s' % (e.message,target_string))
56 return None
57 elif template_line_type == 'time':
58 try:
59 target_time = datetime.datetime.strptime(target_string, template_line.time_format)
60 return target_time.strftime("%H:%M:%S")
61 except ValueError:
62+ _logger.warning('message: %s target_string: %s' % (e.message,target_string))
63 return None
64 elif template_line_type == 'many2one':
65 target_obj_pool = self.pool.get(template_line.target_field.relation)

Subscribers

People subscribed via source and target branches

to all changes: