Commit 61906d14 authored by Xiaowu Zhang's avatar Xiaowu Zhang

erp5_travel_expense: improve query

1.use query factory instead of manually query
2.don't get all related object, use modification date to filter
3.synchronize only related service
parent 16db84fa
......@@ -109,7 +109,7 @@
doc = {
parent_relative_url: "expense_sheet_module",
portal_type: "Expense Sheet",
modification_date: new Date().toISOString()
modification_date: new Date().toISOString().slice(0, 10).replace(/-/g, "/")
};
for (i = 0; i < submit_event.target.length; i += 1) {
if ((form[i].type == "radio") && !form[i].checked){
......
......@@ -250,7 +250,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>989.27549.43950.31078</string> </value>
<value> <string>994.55194.7094.63129</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -268,7 +268,7 @@
</tuple>
<state>
<tuple>
<float>1613394000.22</float>
<float>1631870322.62</float>
<string>UTC</string>
</tuple>
</state>
......
......@@ -37,7 +37,7 @@
visible_in_html5_app_flag: 1,
record_revision: (gadget.options.doc.record_revision || 1),
photo_data: gadget.options.doc.photo_data || "",
modification_date: new Date().toISOString()
modification_date: new Date().toISOString().slice(0, 10).replace(/-/g, "/")
};
for (i = 0; i < form.length; i += 1) {
// XXX Should check input type instead
......
......@@ -249,7 +249,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>989.27549.43950.31078</string> </value>
<value> <string>994.55211.54129.37256</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -267,7 +267,7 @@
</tuple>
<state>
<tuple>
<float>1613394030.76</float>
<float>1631870156.36</float>
<string>UTC</string>
</tuple>
</state>
......
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width" />
<title>Jio Gadget</title>
<link rel="stylesheet" type="text/css" href="alertify.css" />
<!-- renderjs -->
<script src="rsvp.js" type="text/javascript"></script>
<script src="renderjs.js" type="text/javascript"></script>
<script src="jiodev.js" type="text/javascript"></script>
<script src="alertify.js" type="text/javascript"></script>
<!-- custom script -->
<script src="gadget_hr_jio.js" type="text/javascript"></script>
</head>
<body>
</body>
</html>
\ No newline at end of file
......@@ -59,7 +59,7 @@
latitude: gadget.geoLocation.coords.latitude,
source_title: gadget.author,
simulation_state: 'draft',
creation_date:new Date().toISOString().slice(0, 10)
modification_date:new Date().toISOString().slice(0, 10).replace(/-/g, "/")
});
});
});
......
......@@ -236,7 +236,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>956.50385.17297.63180</string> </value>
<value> <string>994.55194.7094.63129</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -254,7 +254,7 @@
</tuple>
<state>
<tuple>
<float>1485167188.03</float>
<float>1631882043.11</float>
<string>UTC</string>
</tuple>
</state>
......
......@@ -241,7 +241,7 @@
parent_relative_url: "record_module",
portal_type: "Leave Request Record",
source_reference: source_reference,
modification_date: new Date().toISOString()
modification_date: new Date().toISOString().slice(0, 10).replace(/-/g, "/")
};
for (i = 0; i < submit_event.target.length; i += 1) {
// XXX Should check input type instead
......
......@@ -250,7 +250,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>989.27549.43950.31078</string> </value>
<value> <string>994.55194.7094.63129</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -268,7 +268,7 @@
</tuple>
<state>
<tuple>
<float>1613394086.14</float>
<float>1631870226.12</float>
<string>UTC</string>
</tuple>
</state>
......
......@@ -250,7 +250,7 @@
source_reference: source_reference,
visible_in_html5_app_flag: 1,
record_revision: (gadget.options.doc.record_revision || 1),
modification_date: new Date().toISOString()
modification_date: new Date().toISOString().slice(0, 10).replace(/-/g, "/")
};
for (i = 0; i < submit_event.target.length; i += 1) {
// XXX Should check input type instead
......
......@@ -250,7 +250,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>989.27549.43950.31078</string> </value>
<value> <string>994.55194.7094.63129</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -268,7 +268,7 @@
</tuple>
<state>
<tuple>
<float>1613394114.93</float>
<float>1631870363.32</float>
<string>UTC</string>
</tuple>
</state>
......
......@@ -9,6 +9,7 @@
<script src="rsvp.js"></script>
<script src="renderjs.js"></script>
<script src="jiodev.js" type="text/javascript"></script>
<script src="gadget_officejs_hr_tool.js" type="text/javascript"></script>
<script src="gadget_officejs_page_jio_erp5_configurator.js"></script>
......
......@@ -246,7 +246,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>966.52991.40280.18790</string> </value>
<value> <string>994.52542.52680.32887</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -264,8 +264,8 @@
</tuple>
<state>
<tuple>
<float>1523626101.75</float>
<string>GMT+2</string>
<float>1631713807.8</float>
<string>UTC</string>
</tuple>
</state>
</object>
......
/*global window, rJS, RSVP, URI, location,
/*global window, rJS, RSVP, URI, location, getSynchronizeQuery,
btoa */
/*jslint nomen: true, indent: 2, maxerr: 3*/
(function (window, rJS, RSVP, loopEventListener) {
"use strict";
function setjIOERP5Configuration(gadget) {
var erp5_url = gadget.props.element.querySelector("input[name='erp5_url']").value;
var erp5_url = gadget.props.element.querySelector("input[name='erp5_url']").value,
original_query = getSynchronizeQuery(null);
return gadget.setSetting("me", '')
.push(function () {
var configuration = {
type: "replicate",
query: {
query: '(portal_type: "Expense Record" AND (simulation_state:"draft" OR simulation_state:"sent" OR simulation_state:"stopped")) ' +
'OR (portal_type: "Travel Request Record" AND (simulation_state:"draft" OR simulation_state:"sent" OR simulation_state:"stopped")) ' +
'OR (portal_type: "Leave Report Record" AND simulation_state:"stopped") ' +
'OR (portal_type: "Leave Request Record" AND (simulation_state:"draft" OR simulation_state:"sent" OR simulation_state:"stopped")) ' +
'OR (portal_type: "Localisation Record" AND (simulation_state:"draft" OR simulation_state:"stopped")) ' +
'OR (portal_type: "Expense Sheet" AND (reference: "expense_sheet")) ' +
'OR (portal_type: "Currency" AND validation_state:"validated") ' +
'OR (portal_type: "Service" AND validation_state:"validated") ',
query: original_query,
limit: [0, 1234567890]
},
use_remote_post: true,
......
......@@ -245,7 +245,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>989.27549.43950.31078</string> </value>
<value> <string>994.52549.19733.34850</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -263,7 +263,7 @@
</tuple>
<state>
<tuple>
<float>1613394309.96</float>
<float>1631711329.34</float>
<string>UTC</string>
</tuple>
</state>
......
......@@ -10,6 +10,8 @@
<script src="renderjs.js" type="text/javascript"></script>
<script src="jiodev.js" type="text/javascript"></script>
<script src="gadget_officejs_hr_tool.js" type="text/javascript"></script>
<!-- custom script -->
<script src="gadget_officejs_hr_jio.js" type="text/javascript"></script>
......
......@@ -246,7 +246,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>966.52672.52784.27187</string> </value>
<value> <string>994.52543.36230.12339</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -264,8 +264,8 @@
</tuple>
<state>
<tuple>
<float>1523518145.13</float>
<string>GMT+2</string>
<float>1631713769.69</float>
<string>UTC</string>
</tuple>
</state>
</object>
......
......@@ -56,6 +56,7 @@
.declareAcquiredMethod("redirect", "redirect")
.declareAcquiredMethod("getSetting", "getSetting")
.declareAcquiredMethod("getSettingList", "getSettingList")
.declareAcquiredMethod("setSetting", "setSetting")
.declareMethod('createJio', function (jio_options) {
......@@ -99,31 +100,87 @@
.declareMethod('repair', function () {
var gadget = this;
return this.getSetting("jio_storage_name")
.push(function (jio_storage_name) {
//try to specify me
if (jio_storage_name === 'ERP5') {
return gadget.getSetting('me')
.push(function (me) {
if (!me) {
return gadget.getSetting('jio_storage_description')
.push(function (configuration) {
gadget.state_parameter_dict.jio_storage = jIO.createJIO(configuration.remote_sub_storage);
return wrapJioCall(gadget, 'getAttachment', ['acl_users', configuration.remote_sub_storage.url, {format: "json"}])
.push(function (result) {
//recreate erp5 storage with indexeddb
me = result._links.me ? result._links.me.href : 'manager';
configuration.query.query += 'OR (portal_type: "Person" AND id: "' + me.split("/")[1] + '")',
gadget.state_parameter_dict.jio_storage = jIO.createJIO(configuration);
return gadget.setSetting('me', me);
})
.push(function () {
return gadget.setSetting('jio_storage_description', configuration);
});
});
}
});
.push(function (jio_storage_name) {
if (jio_storage_name === 'ERP5') {
return gadget.getSettingList(['jio_storage_description', 'me'])
.push(function (result_list) {
var additional_query_list = [],
service_query = new ComplexQuery({
operator: 'OR',
query_list: [],
type: "complex"
}),
me;
gadget.state_parameter_dict.jio_storage = jIO.createJIO(result_list[0].remote_sub_storage);
return wrapJioCall(gadget, 'allDocs', [
{
"query": '(selection_domain_use:"hr" AND translated_validation_state_title: "validated")',
"limit": [0, 1000]
}
])
.push(function (result) {
var i;
if (result.data.rows.length) {
for (i = 0; i < result.data.rows.length; i += 1) {
service_query.query_list.push(new SimpleQuery({
key: 'id',
operator: '',
type: "simple",
value: result.data.rows[i].id.split('/')[1]
}));
}
additional_query_list.push(new ComplexQuery({
operator: 'AND',
query_list: [
new SimpleQuery({
key: 'portal_type',
operator: '',
type: "simple",
value: 'Service'
}),
service_query
],
type: "complex"
}));
}
if (! result_list[1]) {
return wrapJioCall(gadget, 'getAttachment', ['acl_users', result_list[0].remote_sub_storage.url, {format: "json"}])
.push(function (result) {
me = result._links.me ? result._links.me.href : 'manager';
return gadget.setSetting('me', me);
})
} else {
me = result_list[1];
}
})
.push(function () {
additional_query_list.push(new ComplexQuery({
operator: 'AND',
query_list: [
new SimpleQuery({
key: 'portal_type',
operator: '',
type: "simple",
value: 'Person'
}),
new SimpleQuery({
key: 'id',
operator: '',
type: "simple",
value: me.split("/")[1]
})
],
type: "complex"
}));
result_list[0].query.query = getSynchronizeQuery(additional_query_list);
gadget.state_parameter_dict.jio_storage = jIO.createJIO(result_list[0]);
return gadget.setSetting('jio_storage_description', result_list[0]);
});
});
}
})
})
.push(function () {
return wrapJioCall(gadget, 'repair', arguments);
})
......
......@@ -245,7 +245,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>966.59878.54409.55825</string> </value>
<value> <string>994.52646.4747.8277</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -263,8 +263,8 @@
</tuple>
<state>
<tuple>
<float>1523950559.17</float>
<string>GMT+2</string>
<float>1631780404.96</float>
<string>UTC</string>
</tuple>
</state>
</object>
......
/*global window, RSVP, FileReader */
/*global window, RSVP, FileReader, QueryFactory, SimpleQuery, ComplexQuery, Query */
/*jslint indent: 2, maxerr: 3, unparam: true */
(function (window, RSVP) {
"use strict";
......@@ -96,4 +96,271 @@
}
return String.fromCharCode(random())+String.fromCharCode(random())+String.fromCharCode(random());
};
window.getSynchronizeQuery = function (additional_query_list) {
var basic_query,
expense_record_query,
travel_request_record_query,
leave_report_record_query,
leave_request_record_query,
localisation_record_query,
expense_sheet_query,
currency_query,
six_month_ago,
one_year_ago;
six_month_ago = new Date();
six_month_ago.setMonth(six_month_ago.getMonth() - 6);
six_month_ago = six_month_ago.toISOString().slice(0, 10).replace(/-/g, "/");
one_year_ago = new Date();
one_year_ago.setFullYear(one_year_ago.getFullYear() - 1);
one_year_ago = one_year_ago.toISOString().slice(0, 10).replace(/-/g, "/");
expense_record_query = new ComplexQuery({
operator: 'AND',
query_list: [
new SimpleQuery({
key: 'portal_type',
operator: '',
type: "simple",
value: 'Expense Record'
}),
new SimpleQuery({
key: 'modification_date',
operator: '>',
type: "simple",
value: six_month_ago
}),
new ComplexQuery({
operator: 'OR',
query_list: [
new SimpleQuery({
key: 'simulation_state',
operator: '',
type: "simple",
value: "draft"
}),
new SimpleQuery({
key: 'simulation_state',
operator: '',
type: "simple",
value: "sent"
}),
new SimpleQuery({
key: 'simulation_state',
operator: '',
type: "simple",
value: "stopped"
})
],
type: "complex"
})
],
type: "complex"
});
travel_request_record_query = new ComplexQuery({
operator: 'AND',
query_list: [
new SimpleQuery({
key: 'portal_type',
operator: '',
type: "simple",
value: 'Travel Request Record'
}),
new SimpleQuery({
key: 'modification_date',
operator: '>',
type: "simple",
value: six_month_ago
}),
new ComplexQuery({
operator: 'OR',
query_list: [
new SimpleQuery({
key: 'simulation_state',
operator: '',
type: "simple",
value: "draft"
}),
new SimpleQuery({
key: 'simulation_state',
operator: '',
type: "simple",
value: "sent"
}),
new SimpleQuery({
key: 'simulation_state',
operator: '',
type: "simple",
value: "stopped"
})
],
type: "complex"
})
],
type: "complex"
});
leave_report_record_query = new ComplexQuery({
operator: 'AND',
query_list: [
new SimpleQuery({
key: 'portal_type',
operator: '',
type: "simple",
value: 'Leave Report Record'
}),
new SimpleQuery({
key: 'modification_date',
operator: '>',
type: "simple",
value: six_month_ago
}),
new SimpleQuery({
key: 'simulation_state',
operator: '',
type: "simple",
value: "stopped"
})
],
type: "complex"
});
leave_request_record_query = new ComplexQuery({
operator: 'AND',
query_list: [
new SimpleQuery({
key: 'portal_type',
operator: '',
type: "simple",
value: 'Leave Request Record'
}),
new SimpleQuery({
key: 'modification_date',
operator: '>',
type: "simple",
value: one_year_ago
}),
new ComplexQuery({
operator: 'OR',
query_list: [
new SimpleQuery({
key: 'simulation_state',
operator: '',
type: "simple",
value: "draft"
}),
new SimpleQuery({
key: 'simulation_state',
operator: '',
type: "simple",
value: "sent"
}),
new SimpleQuery({
key: 'simulation_state',
operator: '',
type: "simple",
value: "stopped"
})
],
type: "complex"
})
],
type: "complex"
});
localisation_record_query = new ComplexQuery({
operator: 'AND',
query_list: [
new SimpleQuery({
key: 'portal_type',
operator: '',
type: "simple",
value: 'Localisation Record'
}),
new SimpleQuery({
key: 'modification_date',
operator: '>',
type: "simple",
value: six_month_ago
}),
new ComplexQuery({
operator: 'OR',
query_list: [
new SimpleQuery({
key: 'simulation_state',
operator: '',
type: "simple",
value: "draft"
}),
new SimpleQuery({
key: 'simulation_state',
operator: '',
type: "simple",
value: "stopped"
})
],
type: "complex"
})
],
type: "complex"
});
expense_sheet_query = new ComplexQuery({
operator: 'AND',
query_list: [
new SimpleQuery({
key: 'portal_type',
operator: '',
type: "simple",
value: 'Expense Sheet'
}),
new SimpleQuery({
key: 'reference',
operator: '',
type: "simple",
value: "expense_sheet"
})
],
type: "complex"
});
currency_query = new ComplexQuery({
operator: 'AND',
query_list: [
new SimpleQuery({
key: 'portal_type',
operator: '',
type: "simple",
value: 'Currency'
}),
new SimpleQuery({
key: 'validation_state',
operator: '',
type: "simple",
value: "validated"
})
],
type: "complex"
});
basic_query = new ComplexQuery({
operator: 'OR',
type: 'complex',
query_list: [
expense_record_query,
travel_request_record_query,
leave_report_record_query,
leave_request_record_query,
localisation_record_query,
expense_sheet_query,
currency_query
]
});
if (additional_query_list) {
basic_query.query_list = basic_query.query_list.concat(additional_query_list);
}
return Query.objectToSearchText(basic_query);
};
}(window, RSVP));
\ No newline at end of file
......@@ -240,7 +240,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>956.57355.19823.14643</string> </value>
<value> <string>994.42603.26741.38963</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -258,7 +258,7 @@
</tuple>
<state>
<tuple>
<float>1485347131.83</float>
<float>1631713737.85</float>
<string>UTC</string>
</tuple>
</state>
......
......@@ -4,6 +4,7 @@
</portal_type>
<portal_type id="Expense Validation Request">
<item>ExpenseValidationRequest</item>
<item>ExpenseValidationRequestConstraint</item>
</portal_type>
<portal_type id="Leave Request Record">
<item>LeaveRequestRecord</item>
......
......@@ -279,7 +279,7 @@
<dictionary>
<item>
<key> <string>_text</string> </key>
<value> <string>python: here.getModificationDate().HTML4()</string> </value>
<value> <string>python: here.getModificationDate().Date()</string> </value>
</item>
</dictionary>
</pickle>
......
......@@ -279,7 +279,7 @@
<dictionary>
<item>
<key> <string>_text</string> </key>
<value> <string>python: here.getModificationDate().HTML4()</string> </value>
<value> <string>python: here.getModificationDate().Date()</string> </value>
</item>
</dictionary>
</pickle>
......
......@@ -279,7 +279,7 @@
<dictionary>
<item>
<key> <string>_text</string> </key>
<value> <string>python: here.getModificationDate().HTML4()</string> </value>
<value> <string>python: here.getModificationDate().Date()</string> </value>
</item>
</dictionary>
</pickle>
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment