Merge lp:~openerp-dev/openobject-addons/5.0-opw-599251-msh into lp:openobject-addons/5.0

Proposed by Mohammed Shekha(Open ERP)
Status: Needs review
Proposed branch: lp:~openerp-dev/openobject-addons/5.0-opw-599251-msh
Merge into: lp:openobject-addons/5.0
Diff against target: 37 lines (+6/-3)
1 file modified
crm/crm.py (+6/-3)
To merge this branch: bzr merge lp:~openerp-dev/openobject-addons/5.0-opw-599251-msh
Reviewer Review Type Date Requested Status
Martin Trigaux (OpenERP) Pending
Vinay Rana (OpenERP) Pending
Naresh(OpenERP) Pending
Review via email: mp+194984@code.launchpad.net

Description of the change

Hello,

Fixed the issue of crm.case.rule, next action date set wrong, it becomes lesser than last action, it should be atleast >= then last action, also we should execute action if last action is <= then next action because there is possibility that while defining rule user don't give any delay so last action and next action becomes equal, once it becomes equal then other rules will fails to satisy the condition always.

Demo:- Create a new rule in "CRM &amp;
SRM/Configuration/Cases/Rules" with
the values:
Case State : Pending
Trigger Date: Deadline
Set state to: Open
Active :True
Save it.

Now create a new case in " CRM &amp;
SRM/Reporting/All Cases/All Cases"
with a deadline.
For example 17.10.2013
12:30:55
Set the
state to pending and save it
Run

the cron "Check cases rules" before the deadline has passed. The field "Next Action" will be written.
Then run the cron after the deadline has passed. Now the state of the case is open and the field "Last Action" is
higher than "Next Action".
Now Set the state of the case to pending again, set a new deadline that is in the future and save it.
Run the cron again after the new deadline has passed.

Expected result:
The case in state open after the deadline has passed.

Real result:
Nothing changed.

The field "Next Action" will be written only once with the lowest date that the "_action" method can find.
In every run of the cron the condition result in the method "_action" (crm/crm.py:456-465 )   is always false, because the date of the last action is bigger then the next action.

Reason: next action date is not written when rule is executed, so when rule executed also write next action date with delay added, also we should check last_action <= next_action instead of last_action < next_action because there may be no delay at all so next_action and last_action will be the same.

Thanks.

To post a comment you must log in.

Unmerged revisions

2937. By Mohammed Shekha(OpenERP)<email address hidden>

[FIX]CRM: Refixed the issue of crm.case.rule, next action date goes wron, it becomes lesser than last action, it should be atleast >= then last action, also we should execute action if last action is <= then next action because there is possibility that while defining rule user don't give any delay so last action and next action becomes equal, once it becomes equal then other rules will fails to satisy the condition always.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'crm/crm.py'
2--- crm/crm.py 2010-07-28 09:29:48 +0000
3+++ crm/crm.py 2013-11-13 05:08:28 +0000
4@@ -446,19 +446,19 @@
5 base = mx.DateTime.strptime(case.date_deadline, '%Y-%m-%d %H:%M:%S')
6 elif action.trg_date_type=='date' and case.date:
7 base = mx.DateTime.strptime(case.date, '%Y-%m-%d %H:%M:%S')
8- if base:
9- fnct = {
10+ fnct = {
11 'minutes': lambda interval: mx.DateTime.RelativeDateTime(minutes=interval),
12 'day': lambda interval: mx.DateTime.RelativeDateTime(days=interval),
13 'hour': lambda interval: mx.DateTime.RelativeDateTime(hours=interval),
14 'month': lambda interval: mx.DateTime.RelativeDateTime(months=interval),
15 }
16+ if base:
17 d = base + fnct[action.trg_date_range_type](action.trg_date_range)
18 dt = d.strftime('%Y-%m-%d %H:%M:%S')
19 ok = (dt <= time.strftime('%Y-%m-%d %H:%M:%S')) and \
20 ((not case.date_action_next) or \
21 (dt >= case.date_action_next and \
22- case.date_action_last < case.date_action_next))
23+ case.date_action_last <= case.date_action_next))
24 if not ok:
25 if not case.date_action_next or dt < case.date_action_next:
26 case.date_action_next = dt
27@@ -488,7 +488,10 @@
28 write['email_cc'] = case.email_cc+','+action.act_email_cc
29 else:
30 write['email_cc'] = action.act_email_cc
31+ next_date = mx.DateTime.strptime(time.strftime('%Y-%m-%d %H:%M:%S'), '%Y-%m-%d %H:%M:%S') + fnct[action.trg_date_range_type](action.trg_date_range)
32+ next_date = next_date.strftime('%Y-%m-%d %H:%M:%S')
33 write['date_action_last'] = time.strftime('%Y-%m-%d %H:%M:%S')
34+ write['date_action_next'] = next_date
35 self.write(cr, uid, [case.id], write, context)
36 caseobj = self.pool.get('crm.case')
37 if action.act_remind_user: