处理datetime与date类型的区别
todo:处理pivot视图
BIN
app_search_range/static/description/date_range.jpg
Normal file
|
After Width: | Height: | Size: 68 KiB |
|
Before Width: | Height: | Size: 113 KiB After Width: | Height: | Size: 325 KiB |
@@ -2,7 +2,7 @@
|
|||||||
<div class="oe_row oe_spaced">
|
<div class="oe_row oe_spaced">
|
||||||
<h2 class="oe_slogan" style="color:#875A7B;">Date range</h2>
|
<h2 class="oe_slogan" style="color:#875A7B;">Date range</h2>
|
||||||
<div class="oe_demo oe_picture oe_screenshot">
|
<div class="oe_demo oe_picture oe_screenshot">
|
||||||
<img src="date_range.png">
|
<img src="date_range.jpg">
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</section>
|
</section>
|
||||||
@@ -11,7 +11,16 @@
|
|||||||
<div class="oe_row oe_spaced">
|
<div class="oe_row oe_spaced">
|
||||||
<h2 class="oe_slogan" style="color:#875A7B;">Value range</h2>
|
<h2 class="oe_slogan" style="color:#875A7B;">Value range</h2>
|
||||||
<div class="oe_demo oe_picture oe_screenshot">
|
<div class="oe_demo oe_picture oe_screenshot">
|
||||||
<img src="value_range.png">
|
<img src="value_range.jpg">
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
<section class="oe_container oe_dark">
|
||||||
|
<div class="oe_row oe_spaced">
|
||||||
|
<h2 class="oe_slogan" style="color:#875A7B;">Pivot View</h2>
|
||||||
|
<div class="oe_demo oe_picture oe_screenshot">
|
||||||
|
<img src="list_pivot.jpg">
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</section>
|
</section>
|
||||||
|
|||||||
BIN
app_search_range/static/description/list_pivot.jpg
Normal file
|
After Width: | Height: | Size: 48 KiB |
|
Before Width: | Height: | Size: 56 KiB After Width: | Height: | Size: 205 KiB |
BIN
app_search_range/static/description/value_range.jpg
Normal file
|
After Width: | Height: | Size: 51 KiB |
|
Before Width: | Height: | Size: 90 KiB After Width: | Height: | Size: 246 KiB |
@@ -52,7 +52,7 @@ ListView.include({
|
|||||||
|
|
||||||
var l10n = _t.database.parameters;
|
var l10n = _t.database.parameters;
|
||||||
var datepickers_options = {
|
var datepickers_options = {
|
||||||
pickTime: true,
|
pickTime: false,
|
||||||
startDate: moment({ y: 1900 }),
|
startDate: moment({ y: 1900 }),
|
||||||
endDate: moment().add(200, "y"),
|
endDate: moment().add(200, "y"),
|
||||||
calendarWeeks: true,
|
calendarWeeks: true,
|
||||||
@@ -74,7 +74,7 @@ ListView.include({
|
|||||||
if (show.length >= 1 && (show[0]['value'] == "True")) {
|
if (show.length >= 1 && (show[0]['value'] == "True")) {
|
||||||
_.each(self.columns, function (value, key, list) {
|
_.each(self.columns, function (value, key, list) {
|
||||||
if (value.store && value.type === "datetime" || value.type === "date") {
|
if (value.store && value.type === "datetime" || value.type === "date") {
|
||||||
date_fields.push([value.name, value.string]);
|
date_fields.push([value.name, value.string, value.type]);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
if (date_fields.length > 0) {
|
if (date_fields.length > 0) {
|
||||||
@@ -213,22 +213,46 @@ ListView.include({
|
|||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
});
|
});
|
||||||
// todo: 时区处理
|
// todo: 注意,date和datetime型的处理是不同的,已处理完datetime类型,还有date类型
|
||||||
if (self.$search_button) {
|
if (self.$search_button) {
|
||||||
var start_date = self.$search_button.find('.app_start_date').val(),
|
var start_date = self.$search_button.find('.app_start_date').val(),
|
||||||
end_date = self.$search_button.find('.app_end_date').val(),
|
end_date = self.$search_button.find('.app_end_date').val(),
|
||||||
field = self.$search_button.find('.app_select_field').val();
|
field = self.$search_button.find('.app_select_field').val(),
|
||||||
|
field_type = 'datetime';
|
||||||
|
var tz = session.user_context.tz,
|
||||||
|
start_utc,
|
||||||
|
end_utc;
|
||||||
|
|
||||||
|
_.each(self.columns, function (value, key, list) {
|
||||||
|
if (value.name == field) {
|
||||||
|
field_type = value.type;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
moment.locale(tz);
|
||||||
var l10n = _t.database.parameters;
|
var l10n = _t.database.parameters;
|
||||||
if (start_date) {
|
if (start_date) {
|
||||||
start_date = moment(moment(start_date, time.strftime_to_moment_format(l10n.date_format))).format('YYYY-MM-DD');
|
if (field_type = 'date') {
|
||||||
domain.push([field, '>=', start_date]);
|
//日期类型,无须utc处理
|
||||||
|
start_date = moment(moment(start_date, time.strftime_to_moment_format(l10n.date_format))).format('YYYY-MM-DD');
|
||||||
|
domain.push([field, '>=', start_date]);
|
||||||
|
} else {
|
||||||
|
//日期时间,处理utc
|
||||||
|
start_date = moment(moment(start_date, time.strftime_to_moment_format(l10n.date_format))).format('YYYY-MM-DD 00:00:00');
|
||||||
|
start_utc = moment(start_date)
|
||||||
|
domain.push([field, '>=', start_utc]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (end_date) {
|
if (end_date) {
|
||||||
end_date = moment(moment(end_date, time.strftime_to_moment_format(l10n.date_format))).format('YYYY-MM-DD');
|
if (field_type = 'date') {
|
||||||
domain.push([field, '<=', end_date]);
|
end_date = moment(moment(end_date, time.strftime_to_moment_format(l10n.date_format))).format('YYYY-MM-DD');
|
||||||
|
domain.push([field, '>=', end_date]);
|
||||||
|
} else {
|
||||||
|
end_date = moment(moment(end_date, time.strftime_to_moment_format(l10n.date_format))).format('YYYY-MM-DD 00:00:00');
|
||||||
|
end_utc = moment(end_date)
|
||||||
|
domain.push([field, '<=', end_utc]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (self.$search_range) {
|
if (self.$search_range) {
|
||||||
|
|||||||
@@ -8,7 +8,7 @@
|
|||||||
<span style="float: left;">
|
<span style="float: left;">
|
||||||
|
|
||||||
<select class="app_select_field form-control" style="height: 30px;" >
|
<select class="app_select_field form-control" style="height: 30px;" >
|
||||||
<option t-foreach="date_fields" t-as="field" t-att-value="field[0]">
|
<option t-foreach="date_fields" t-as="field" t-att-value="field[0]" t-att-type="field[2]">
|
||||||
<t t-esc="field[1]"/>
|
<t t-esc="field[1]"/>
|
||||||
</option>
|
</option>
|
||||||
</select>
|
</select>
|
||||||
|
|||||||