Merge lp:~openerp-dev/openobject-addons/7.0-opw-596732DashboardActionDomainEvaluation-msh into lp:openobject-addons/7.0

Proposed by Mohammed Shekha(Open ERP)
Status: Needs review
Proposed branch: lp:~openerp-dev/openobject-addons/7.0-opw-596732DashboardActionDomainEvaluation-msh
Merge into: lp:openobject-addons/7.0
Diff against target: 73 lines (+29/-5)
1 file modified
board/static/src/js/dashboard.js (+29/-5)
To merge this branch: bzr merge lp:~openerp-dev/openobject-addons/7.0-opw-596732DashboardActionDomainEvaluation-msh
Reviewer Review Type Date Requested Status
Mohammed Shekha(Open ERP) (community) Disapprove
Naresh(OpenERP) Pending
Martin Trigaux (OpenERP) Pending
Review via email: mp+215357@code.launchpad.net

Description of the change

Hello,

Fixed the issue of add to dashboard and evaluated domain, while adding dashboard we should add row domain as it is and should evaluate it when dashboard action is loaded otherwise dynamic domain value like context.today etc will not work, instead evaluated date is applied and dashboard will not give proper result.

Demo:- Open any tree view which has Filter based on date/relative_delta/today, filter your data using that date, say for example I have filter like ('date_action','<=', (context_today() + relativedelta(days=7)).strftime('%Y-%m-%d’)) so when I filter data with this filter and then add this view into dashboard then next day that view will give wrong result.
To test this issue I added a filter in search view of Opportuity something like,
<filter icon="terp-personal+" string="Last 7 Days' Opportunity" name="opportunity" domain="[('type','=','opportunity'), ('date_action','&lt;=', (context_today() + relativedelta(days=-7)).strftime('%%Y-%%m-%%d')) ]" help="Show only opportunity"/>

Reason: While Adding view into dashbaord, evaluated domain and context stored in the dashboard action, domain and context should be stored as it is and when action is loaded at that time action domain and context should be evaluated.

Solution: Added a domain as it is without evaluating it while Adding view into dashboard and evaluated that domain while dashboard actions are loading, added a toJSON method in instance.web.CompoundDomain which return JSON stringify domain(include method in dashboard.js itself instead of putting it into web module).

Thanks.

To post a comment you must log in.
Revision history for this message
Mohammed Shekha(Open ERP) (msh-openerp) :
review: Disapprove

Unmerged revisions

9974. By Mohammed Shekha(Open ERP)

[FIX]Re-fixed the issue of add to dashboard and evaluated domain, while adding dashboard we should add row domain as it is and should evaluate it when dashboard action is loaded otherwise dynamic domain value like context.today etc will not work, instead evaluated date is applied and dashboard will not give proper result.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'board/static/src/js/dashboard.js'
2--- board/static/src/js/dashboard.js 2013-08-08 15:00:40 +0000
3+++ board/static/src/js/dashboard.js 2014-04-11 07:10:21 +0000
4@@ -176,13 +176,20 @@
5 action = result,
6 view_mode = action_attrs.view_mode;
7
8- // evaluate action_attrs context and domain
9 action_attrs.context_string = action_attrs.context;
10 action_attrs.context = instance.web.pyeval.eval(
11 'context', action_attrs.context || {});
12 action_attrs.domain_string = action_attrs.domain;
13- action_attrs.domain = instance.web.pyeval.eval(
14+
15+ // evaluate action_attrs context and domain
16+ if(_.isString(action_attrs.domain)) {
17+ action_attrs.domain = instance.web.pyeval.eval(
18 'domain', action_attrs.domain || [], action_attrs.context);
19+ } else {
20+ var comp_domain = new instance.web.CompoundDomain().set_eval_context(action_attrs.context);
21+ _.each(action_attrs.domain, comp_domain.add, comp_domain);
22+ action_attrs.domain = comp_domain.eval();
23+ }
24 if (action_attrs.context['dashboard_merge_domains_contexts'] === false) {
25 // TODO: replace this 6.1 workaround by attribute on <action/>
26 action.context = action_attrs.context || {};
27@@ -377,7 +384,9 @@
28 }
29 var data = getParent.build_search_data();
30 var context = new instance.web.CompoundContext(getParent.dataset.get_context() || []);
31- var domain = new instance.web.CompoundDomain(getParent.dataset.get_domain() || []);
32+ //used dataset.domain instead of dataset.get_domain, because model domain will be evaluated domain
33+ //We need unevaluated domain of action as well as search build
34+ var domain = new instance.web.CompoundDomain(getParent.dataset.domain || []);
35 _.each(data.contexts, context.add, context);
36 _.each(data.domains, domain.add, domain);
37
38@@ -393,13 +402,12 @@
39 }
40 // TODO: replace this 6.1 workaround by attribute on <action/>
41 c.dashboard_merge_domains_contexts = false;
42- var d = instance.web.pyeval.eval('domain', domain);
43
44 this.rpc('/board/add_to_dashboard', {
45 menu_id: this.$el.find("select").val(),
46 action_id: view_parent.action.id,
47 context_to_save: c,
48- domain: d,
49+ domain: domain.toJSON(),
50 view_mode: view_parent.active_view,
51 name: this.$el.find("input").val()
52 }).done(function(r) {
53@@ -430,4 +438,20 @@
54 }
55 });
56
57+instance.web.CompoundDomain.include({
58+ toJSON: function() {
59+ var self = this;
60+ var dd = [];
61+ _.each(this.__domains, function(dom) {
62+ if (dom instanceof instance.web.CompoundDomain) {
63+ //No need to do recusrive call, if dom again have compoundDomain, pyeval.eval will manage it
64+ dd.push(instance.web.pyeval.eval('domain', dom));
65+ } else if (dom.length) {
66+ dd.push(dom);
67+ }
68+ });
69+ return JSON.stringify(dd);
70+ },
71+});
72+
73 };