From 9b37ccf4e29c54271d767140b80bdc75a67815c9 Mon Sep 17 00:00:00 2001 From: "Daniel Watkins (credativ)" Date: Thu, 9 Sep 2010 15:13:28 +0100 Subject: [PATCH] Extract strptime calls to make code look clearer. bzr revid: daniel.watkins@credativ.co.uk-20100909141328-3qz1ome23ani3yrm --- addons/base_action_rule/base_action_rule.py | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/addons/base_action_rule/base_action_rule.py b/addons/base_action_rule/base_action_rule.py index 3038b43136a..73fd96f93c9 100644 --- a/addons/base_action_rule/base_action_rule.py +++ b/addons/base_action_rule/base_action_rule.py @@ -29,6 +29,11 @@ import re import time import tools + +def get_datetime(date_field): + return datetime.strptime(date_field[:19], '%Y-%m-%d %H:%M:%S') + + class base_action_rule(osv.osv): """ Base Action Rules """ @@ -216,24 +221,24 @@ the rule to mark CC(mail to any other person defined in actions)."), model_pool = self.pool.get(model) last_run = False if rule.last_run: - last_run = datetime.strptime(rule.last_run[:19], '%Y-%m-%d %H:%M:%S') + last_run = get_datetime(rule.last_run) now = datetime.now() for obj_id in model_pool.search(cr, uid, [], context=context): obj = model_pool.browse(cr, uid, obj_id, context=context) # Calculate when this action should next occur for this object base = False if rule.trg_date_type=='create' and hasattr(obj, 'create_date'): - base = datetime.strptime(obj.create_date[:19], '%Y-%m-%d %H:%M:%S') + base = get_datetime(obj.create_date) elif rule.trg_date_type=='action_last' and hasattr(obj, 'create_date'): if hasattr(obj, 'date_action_last') and obj.date_action_last: - base = datetime.strptime(obj.date_action_last, '%Y-%m-%d %H:%M:%S') + base = get_datetime(obj.date_action_last) else: - base = datetime.strptime(obj.create_date[:19], '%Y-%m-%d %H:%M:%S') + base = get_datetime(obj.create_date) elif rule.trg_date_type=='deadline' and hasattr(obj, 'date_deadline') \ and obj.date_deadline: - base = datetime.strptime(obj.date_deadline, '%Y-%m-%d %H:%M:%S') + base = get_datetime(obj.date_deadline) elif rule.trg_date_type=='date' and hasattr(obj, 'date') and obj.date: - base = datetime.strptime(obj.date, '%Y-%m-%d %H:%M:%S') + base = get_datetime(obj.date) if base: fnct = { 'minutes': lambda interval: timedelta(minutes=interval),