diff --git a/app_ui_enhance/__init__.py b/app_ui_enhance/__init__.py new file mode 100644 index 00000000..0f7cb6b2 --- /dev/null +++ b/app_ui_enhance/__init__.py @@ -0,0 +1,2 @@ +# -*- coding: utf-8 -*- +import models \ No newline at end of file diff --git a/app_ui_enhance/__openerp__.py b/app_ui_enhance/__openerp__.py new file mode 100644 index 00000000..d140ce38 --- /dev/null +++ b/app_ui_enhance/__openerp__.py @@ -0,0 +1,50 @@ +# -*- coding: utf-8 -*- + +# Created on 2017-11-05 +# author: 广州尚鹏,http://www.sunpop.cn +# email: 300883@qq.com +# resource of Sunpop +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +# Odoo在线中文用户手册(长期更新) +# http://www.sunpop.cn/documentation/user/10.0/zh_CN/index.html + +# Odoo10离线中文用户手册下载 +# http://www.sunpop.cn/odoo10_user_manual_document_offline/ +# Odoo10离线开发手册下载-含python教程,jquery参考,Jinja2模板,PostgresSQL参考(odoo开发必备) +# http://www.sunpop.cn/odoo10_developer_document_offline/ +# description: +{ + 'name': 'App Web UI Enhance', + 'version': '10.0.1.0', + 'author': 'Sunpop.cn', + 'category': 'web', + 'website': 'http://www.sunpop.cn', + 'license': 'AGPL-3', + 'sequence': 2, + 'summary': 'UI Enhance for Odoo', + 'description': """ + +Search by date or number range in List view and Pivot view +-------------------------------------------------- + + """, + 'depends': ['web','app_odoo_customize'], + 'data': [ + 'views/app_ui_config_settings_view.xml', + 'views/template_view.xml', + # data + 'data/ir_config_parameter.xml', + ], + 'qweb': [ + 'static/src/xml/*.xml', + ], + "price": 68.00, + "currency": "EUR", + + 'images': ['static/description/list_pivot.png'], + + 'installable': True, + 'auto_install': False, + 'application': True, +} diff --git a/app_ui_enhance/data/ir_config_parameter.xml b/app_ui_enhance/data/ir_config_parameter.xml new file mode 100644 index 00000000..d355ff7c --- /dev/null +++ b/app_ui_enhance/data/ir_config_parameter.xml @@ -0,0 +1,13 @@ + + + + + app_ui_show_search_date + True + + + app_ui_show_search_number + True + + + \ No newline at end of file diff --git a/app_ui_enhance/i18n/zh_CN.po b/app_ui_enhance/i18n/zh_CN.po new file mode 100644 index 00000000..0b61b2fa --- /dev/null +++ b/app_ui_enhance/i18n/zh_CN.po @@ -0,0 +1,145 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * app_ui_enhance +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 10.0+e-20171107\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2017-11-16 09:24+0000\n" +"PO-Revision-Date: 2017-11-16 09:24+0000\n" +"Last-Translator: <300883@qq.com>" +"Language-Team: Sunpop.cn" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: \n" + +#. module: app_ui_enhance +#. openerp-web +#: code:addons/app_ui_enhance/static/src/xml/pivot_view.xml:70 +#: code:addons/app_ui_enhance/static/src/xml/pivot_view.xml:91 +#, python-format +msgid "All" +msgstr "全部" + +#. module: app_ui_enhance +#: model:ir.model,name:app_ui_enhance.model_app_ui_config_settings +msgid "App Web UI enhance settings" +msgstr "界面优化设置" + +#. module: app_ui_enhance +#: model:ir.ui.view,arch_db:app_ui_enhance.view_app_ui_config_settings +msgid "Apply" +msgstr "应用" + +#. module: app_ui_enhance +#: model:ir.ui.view,arch_db:app_ui_enhance.view_app_ui_config_settings +msgid "Cancel" +msgstr "取消" + +#. module: app_ui_enhance +#: model:ir.model.fields,field_description:app_ui_enhance.field_app_ui_config_settings_create_uid +msgid "Created by" +msgstr "创建人" + +#. module: app_ui_enhance +#: model:ir.model.fields,field_description:app_ui_enhance.field_app_ui_config_settings_create_date +msgid "Created on" +msgstr "创建时间" + +#. module: app_ui_enhance +#: model:ir.model.fields,field_description:app_ui_enhance.field_app_ui_config_settings_display_name +msgid "Display Name" +msgstr "显示名称" + +#. module: app_ui_enhance +#. openerp-web +#: code:addons/app_ui_enhance/static/src/xml/pivot_view.xml:22 +#, python-format +msgid "End date" +msgstr "结束日期" + +#. module: app_ui_enhance +#. openerp-web +#: code:addons/app_ui_enhance/static/src/xml/pivot_view.xml:45 +#, python-format +msgid "From" +msgstr "从" + +#. module: app_ui_enhance +#: model:ir.model.fields,field_description:app_ui_enhance.field_app_ui_config_settings_id +msgid "ID" +msgstr "ID" + +#. module: app_ui_enhance +#: model:ir.ui.view,arch_db:app_ui_enhance.view_app_ui_config_settings +msgid "Item to Show" +msgstr "显示/隐藏菜单项" + +#. module: app_ui_enhance +#: model:ir.model.fields,field_description:app_ui_enhance.field_app_ui_config_settings___last_update +msgid "Last Modified on" +msgstr "最后修改日" + +#. module: app_ui_enhance +#: model:ir.model.fields,field_description:app_ui_enhance.field_app_ui_config_settings_write_uid +msgid "Last Updated by" +msgstr "最后更新人" + +#. module: app_ui_enhance +#: model:ir.model.fields,field_description:app_ui_enhance.field_app_ui_config_settings_write_date +msgid "Last Updated on" +msgstr "最后更新时间" + +#. module: app_ui_enhance +#: model:ir.ui.view,arch_db:app_ui_enhance.view_app_ui_config_settings +msgid "Search Enhance" +msgstr "搜索增加" + +#. module: app_ui_enhance +#: model:ir.model.fields,help:app_ui_enhance.field_app_ui_config_settings_app_ui_show_search_date +#: model:ir.model.fields,help:app_ui_enhance.field_app_ui_config_settings_app_ui_show_search_number +msgid "Set 'True' to show, Set 'False' to hide" +msgstr "设为 'True' 则显示,设为 'False' 则隐藏" + +#. module: app_ui_enhance +#: model:ir.model.fields,field_description:app_ui_enhance.field_app_ui_config_settings_app_ui_show_search_date +msgid "Show date range search in tree/pivot view" +msgstr "显示日期搜索,在tree/pivot视图生效" + +#. module: app_ui_enhance +#: model:ir.model.fields,field_description:app_ui_enhance.field_app_ui_config_settings_app_ui_show_search_number +msgid "Show number range search tree/pivot view" +msgstr "显示数值搜索,在tree/pivot视图生效" + +#. module: app_ui_enhance +#. openerp-web +#: code:addons/app_ui_enhance/static/src/xml/pivot_view.xml:18 +#, python-format +msgid "Start date" +msgstr "开始日期" + +#. module: app_ui_enhance +#. openerp-web +#: code:addons/app_ui_enhance/static/src/xml/pivot_view.xml:49 +#, python-format +msgid "To" +msgstr "至" + +#. module: app_ui_enhance +#: model:ir.actions.act_window,name:app_ui_enhance.action_app_ui_config +#: model:ir.ui.menu,name:app_ui_enhance.menu_app_ui_config +msgid "UI Enhance" +msgstr "界面增强" + +#. module: app_ui_enhance +#: model:ir.ui.view,arch_db:app_ui_enhance.view_app_ui_config_settings +msgid "odoo UI Enhance" +msgstr "odoo 界面增强" + +#. module: app_ui_enhance +#: model:ir.ui.view,arch_db:app_ui_enhance.view_app_ui_config_settings +msgid "odooApp UI Settings" +msgstr "界面增强设置" + diff --git a/app_ui_enhance/models/__init__.py b/app_ui_enhance/models/__init__.py new file mode 100644 index 00000000..233f369e --- /dev/null +++ b/app_ui_enhance/models/__init__.py @@ -0,0 +1,2 @@ +# -*- coding: utf-8 -*- +import app_ui_config_settings diff --git a/app_ui_enhance/models/app_ui_config_settings.py b/app_ui_enhance/models/app_ui_config_settings.py new file mode 100644 index 00000000..ffc8ff8a --- /dev/null +++ b/app_ui_enhance/models/app_ui_config_settings.py @@ -0,0 +1,50 @@ +# -*- coding: utf-8 -*- + +# Created on 2017-11-16 +# author: 广州尚鹏,http://www.sunpop.cn +# email: 300883@qq.com +# resource of Sunpop +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +# Odoo在线中文用户手册(长期更新) +# http://www.sunpop.cn/documentation/user/10.0/zh_CN/index.html + +# Odoo10离线中文用户手册下载 +# http://www.sunpop.cn/odoo10_user_manual_document_offline/ +# Odoo10离线开发手册下载-含python教程,jquery参考,Jinja2模板,PostgresSQL参考(odoo开发必备) +# http://www.sunpop.cn/odoo10_developer_document_offline/ +# description: + +import logging + +from openerp import api, fields, models, _ + +_logger = logging.getLogger(__name__) + + +class AppUiConfigSettings(models.TransientModel): + _inherit = 'res.config.settings' + _name = 'app.ui.config.settings' + + _description = u"App Web UI enhance settings" + app_ui_show_search_date = fields.Boolean('Show date range search in tree/pivot view', help=u"Set 'True' to show, Set 'False' to hide") + app_ui_show_search_number = fields.Boolean('Show number range search tree/pivot view', help=u"Set 'True' to show, Set 'False' to hide") + + @api.model + def get_default_all(self, fields): + ir_config = self.env['ir.config_parameter'] + app_ui_show_search_date = True if ir_config.get_param('app_ui_show_search_date') == "True" else False + app_ui_show_search_number = True if ir_config.get_param('app_ui_show_search_number') == "True" else False + + return dict( + app_ui_show_search_date=app_ui_show_search_date, + app_ui_show_search_number=app_ui_show_search_number + ) + + @api.multi + def set_default_all(self): + self.ensure_one() + ir_config = self.env['ir.config_parameter'] + ir_config.set_param("app_ui_show_search_date", self.app_ui_show_search_date or "False") + ir_config.set_param("app_ui_show_search_number", self.app_ui_show_search_number or "False") + return True diff --git a/app_ui_enhance/static/description/date_range.jpg b/app_ui_enhance/static/description/date_range.jpg new file mode 100644 index 00000000..8b702b90 Binary files /dev/null and b/app_ui_enhance/static/description/date_range.jpg differ diff --git a/app_ui_enhance/static/description/date_range.png b/app_ui_enhance/static/description/date_range.png new file mode 100644 index 00000000..317099b9 Binary files /dev/null and b/app_ui_enhance/static/description/date_range.png differ diff --git a/app_ui_enhance/static/description/icon.png b/app_ui_enhance/static/description/icon.png new file mode 100644 index 00000000..4c57f611 Binary files /dev/null and b/app_ui_enhance/static/description/icon.png differ diff --git a/app_ui_enhance/static/description/index.html b/app_ui_enhance/static/description/index.html new file mode 100644 index 00000000..c2632562 --- /dev/null +++ b/app_ui_enhance/static/description/index.html @@ -0,0 +1,91 @@ +
+
+
+

App Search By Date or Number Range

+
+

This moduld allows user to Search by date or number range in List view and Pivot view.

+
+
    +
  • 1.List all the date/datetime field to select range
  • +
  • 2.List all the integer/float/Monetary field to select range
  • +
  • 3.Auto get user timezone, global Timezone supported.
  • +
  • 4.Easy admin to enable/disable the search.
  • +
+
+
+
+
+
+
+

Date range

+
+ +
+
+
+ +
+
+

Value range

+
+ +
+
+
+ +
+
+

Pivot View

+
+ +
+
+
+ +
+
+

How to setup

+

Go to Menu: Settings->Technical->Parameters->System Parameters

+

You can find "app_ui_show_search_date" and "app_ui_show_search_number"

+

Go to Menu: Settings->Technical->Parameters->System Parameters.

+

Set the Value to "False" if you do not want to show the search. And set "True" to show.

+
+ +
+
+
+ +
+
+
+

Technical Help & Support

+
+
+
+

+ For any type of technical help & support requests, Feel free to contact us

+ + guohuadeng@hotmail.com +

+ Via QQ: 300883

+ + 300883@qq.com +
+
+

+ Visit our website for more support.

+ + http://www.sunpop.cn +
+
+
+
+ +
+
\ No newline at end of file diff --git a/app_ui_enhance/static/description/list_pivot.jpg b/app_ui_enhance/static/description/list_pivot.jpg new file mode 100644 index 00000000..6b9ff4e8 Binary files /dev/null and b/app_ui_enhance/static/description/list_pivot.jpg differ diff --git a/app_ui_enhance/static/description/list_pivot.png b/app_ui_enhance/static/description/list_pivot.png new file mode 100644 index 00000000..59bf05cd Binary files /dev/null and b/app_ui_enhance/static/description/list_pivot.png differ diff --git a/app_ui_enhance/static/description/setup.jpg b/app_ui_enhance/static/description/setup.jpg new file mode 100644 index 00000000..dcfaaf54 Binary files /dev/null and b/app_ui_enhance/static/description/setup.jpg differ diff --git a/app_ui_enhance/static/description/setup.png b/app_ui_enhance/static/description/setup.png new file mode 100644 index 00000000..0c79efd6 Binary files /dev/null and b/app_ui_enhance/static/description/setup.png differ diff --git a/app_ui_enhance/static/description/value_range.jpg b/app_ui_enhance/static/description/value_range.jpg new file mode 100644 index 00000000..424b1369 Binary files /dev/null and b/app_ui_enhance/static/description/value_range.jpg differ diff --git a/app_ui_enhance/static/description/value_range.png b/app_ui_enhance/static/description/value_range.png new file mode 100644 index 00000000..e1b33e3b Binary files /dev/null and b/app_ui_enhance/static/description/value_range.png differ diff --git a/app_ui_enhance/static/src/css/app_ui_enhance.css b/app_ui_enhance/static/src/css/app_ui_enhance.css new file mode 100644 index 00000000..673b57ff --- /dev/null +++ b/app_ui_enhance/static/src/css/app_ui_enhance.css @@ -0,0 +1,11 @@ +.tree_search_item { + cursor: pointer; +} + +.tree_search_item .selected a:before { + font-family: FontAwesome; + position: absolute; + left: 6px; + top: 3px; + content: ""; +} \ No newline at end of file diff --git a/app_ui_enhance/static/src/js/pivot.js b/app_ui_enhance/static/src/js/pivot.js new file mode 100644 index 00000000..a8102fbc --- /dev/null +++ b/app_ui_enhance/static/src/js/pivot.js @@ -0,0 +1,257 @@ +odoo.define('app_ui_enhance.pivot', function (require) { +"use strict"; + +var time = require('web.time'); +var core = require('web.core'); +var data = require('web.data'); +var session = require('web.session'); +var utils = require('web.utils'); +var Model = require('web.Model'); +var PivotView = require('web.PivotView'); +var datepicker = require('web.datepicker'); + +var _t = core._t; +var _lt = core._lt; +var QWeb = core.qweb; + +PivotView.include({ + + init: function() { + this._super.apply(this, arguments); + this.ts_fields = []; + }, + + tgl_on_button_click: function (event) { + var self = this; + var $target = $(event.target), + field, key, first_item; + + field = $target.parent().data('field'); + key = $target.parent().data('key'); + + if (field == -1) { + first_item = $target.parent().parent().children('.tgl_first_item.selected'); + if (!first_item.length) { + $target.parent().parent().children('li').removeClass('selected') + } + } else { + first_item = $target.parent().parent().children('.tgl_first_item').removeClass('selected'); + } + + $target.parent().toggleClass('selected'); + this.tgl_search() + event.stopPropagation(); + + }, + + + render_buttons: function($node) { + var self = this; + var ts_context = this.context.tree_search; + + this._super.apply(this, arguments); + + var l10n = _t.database.parameters; + var datepickers_options = { + pickTime: false, + startDate: moment({ y: 1900 }), + endDate: moment().add(200, "y"), + calendarWeeks: true, + icons : { + time: 'fa fa-clock-o', + date: 'fa fa-calendar', + up: 'fa fa-chevron-up', + down: 'fa fa-chevron-down' + }, + language : moment.locale(), + format : time.strftime_to_moment_format(l10n.date_format), + } + + // Dropdown list + + $(QWeb.render("TGL.TreeSearch.Placeholder", {})).appendTo($node); + + _.each(ts_context, function(item){ + var field = _.find(self.fields, function(value, key, list){ + return value.type == 'many2one' && value.relation && key === item.name; + }); + + if (field) { + self.ts_fields.push(item.name); + + new Model(field.relation).query(['id', 'display_name']).filter(new data.CompoundDomain(item.domain, field.domain)).context(new data.CompoundContext()).order_by('app_sequence').all().then(function (result) { + var $multi_search = $(QWeb.render("TGL.TreeSearch.Item", {'widget': { + 'string': item.string, + 'key': item.name, + 'class_name': 'app_multi_item_' + item.name, + 'fields': result, + }})) + + $multi_search.find('li').click(self.tgl_on_button_click.bind(self)); + + setTimeout(function(){ + $multi_search.appendTo($('.treesearch_placeholder')); + }, 2000); + }); + } + }); + // self.$buttons.find('.app-search').remove(); + + var date_fields = []; + // 增加参数控制app_ui_show_search_date + new Model('ir.config_parameter').call('search_read', [[['key', '=', 'app_ui_show_search_date']], ['value']]).then(function (show) { + if (show.length >= 1 && (show[0]['value'] == "True")) { + _.each(self.fields, function (value, key, list) { + if (value.store && value.type === "datetime" || value.type === "date") { + date_fields.push([key, value.string]); + } + }); + + if (date_fields.length > 0) { + self.$search_button = $(QWeb.render('odooApp.buttons', {'date_fields': date_fields})) + self.$search_button.find('.app_start_date').datetimepicker(datepickers_options); + self.$search_button.find('.app_end_date').datetimepicker(datepickers_options); + self.$search_button.find('.app_start_date').on('change', function () { + self.tgl_search(); + }); + self.$search_button.find('.app_end_date').on('change', function () { + self.tgl_search(); + }); + self.$search_button.find('.app_select_field').on('change', function () { + self.tgl_search(); + }); + setTimeout(function () { + self.$search_button.insertBefore($('.treesearch_placeholder')); + }, 500); + } + } + }); + + var number_fields = []; + + // 增加参数控制app_ui_show_search_number + new Model('ir.config_parameter').call('search_read', [[['key', '=', 'app_ui_show_search_number']], ['value']]).then(function (show) { + if (show.length >= 1 && (show[0]['value'] == "True")) { + number_fields = []; + _.each(self.fields, function (value, key, list) { + if (value.string && value.string.length > 1 && value.store && (value.type === "integer" || value.type === "float" || value.type === "monetary")) { + number_fields.push([key, value.string]); + } + }); + + if (number_fields.length > 0) { + self.$search_range = $(QWeb.render('odooApp.SearchRange', {'number_fields': number_fields})) + self.$search_range.find('.app_select_range_field').on('change', function () { + self.tgl_search(); + }); + self.$search_range.find('.app_start_range').on('change', function () { + self.tgl_search(); + }); + self.$search_range.find('.app_end_range').on('change', function () { + self.tgl_search(); + }); + setTimeout(function () { + self.$search_range.insertBefore($('.treesearch_placeholder')); + }, 500); + } + } + }); + }, + + do_search: function(domain, context, group_by) { + var self = this; + this.last_domain = domain; + this.last_context = context; + this.last_group_by = group_by; + this.old_search = _.bind(this._super, this); + return self.tgl_search(); + }, + + tgl_search: function() { + var self = this; + var domain = [], value, value_tmp; + + _.each(self.ts_fields, function(field){ + value = $('.app_item_' + field).val(); + + var select_fields = $('.app_multi_item_' + field).children('.selected'), + select_value = []; + if (select_fields.length > 0) { + _.each(select_fields, function(item){ + value_tmp = $(item).data('field'); + if (value_tmp > 0) { + select_value.push($(item).data('field')); + } + }); + if (select_value.length) { + domain.push([field, 'in', select_value]); + } + + } + }); + +// 注意,date和datetime型的处理是不同的,已处理完 + if (self.$search_button) { + var start_date = self.$search_button.find('.app_start_date').val(), + end_date = self.$search_button.find('.app_end_date').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; + return false; + } + }); + + moment.locale(tz); + var l10n = _t.database.parameters; + if (start_date) { + if (field_type == '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 (field_type == '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) { + var start_range = self.$search_range.find('.app_start_range').val(), + end_range = self.$search_range.find('.app_end_range').val(), + range_field = self.$search_range.find('.app_select_range_field').val(); + + if (start_range) { + domain.push([range_field, '>=', parseInt(start_range)]); + } + if (end_range) { + domain.push([range_field, '<=', parseInt(end_range)]); + } + } + // console.log(domain); + var compound_domain = new data.CompoundDomain(self.last_domain, domain); + self.dataset.domain = compound_domain.eval(); + return self.old_search(compound_domain, self.last_context, self.last_group_by); + }, + + +}); + +}); \ No newline at end of file diff --git a/app_ui_enhance/static/src/js/tree.js b/app_ui_enhance/static/src/js/tree.js new file mode 100644 index 00000000..37f45170 --- /dev/null +++ b/app_ui_enhance/static/src/js/tree.js @@ -0,0 +1,271 @@ +odoo.define('app_ui_enhance.tree', function (require) { +"use strict"; + +var time = require('web.time'); +var core = require('web.core'); +var data = require('web.data'); +var session = require('web.session'); +var utils = require('web.utils'); +var Model = require('web.Model'); +var ListView = require('web.ListView'); +var datepicker = require('web.datepicker'); +var ViewManager = require('web.ViewManager') +var _t = core._t; +var _lt = core._lt; +var QWeb = core.qweb; + +ListView.include({ + + init: function(parent, dataset, view_id, options) { + this._super.apply(this, arguments); + this.ts_context = dataset.context.tree_search; + this.fields_range = dataset.context.fields_range; + this.ts_fields = []; + }, + + on_button_click: function (event) { + var self = this; + var $target = $(event.target), + field, key, first_item; + + field = $target.parent().data('field'); + key = $target.parent().data('key'); + + if (field == -1) { + first_item = $target.parent().parent().children('.tgl_first_item.selected'); + if (!first_item.length) { + $target.parent().parent().children('li').removeClass('selected') + } + } else { + first_item = $target.parent().parent().children('.tgl_first_item').removeClass('selected'); + } + + $target.parent().toggleClass('selected'); + this.tgl_search() + event.stopPropagation(); + + }, + + render_buttons: function($node) { + var self = this; + this._super.apply(this, arguments); + + var l10n = _t.database.parameters; + var datepickers_options = { + pickTime: false, + startDate: moment({ y: 1900 }), + endDate: moment().add(200, "y"), + calendarWeeks: true, + icons : { + time: 'fa fa-clock-o', + date: 'fa fa-calendar', + up: 'fa fa-chevron-up', + down: 'fa fa-chevron-down' + }, + language : moment.locale(), + format : time.strftime_to_moment_format(l10n.date_format), + } + + self.$buttons.find('.app-search').remove(); + + var date_fields = []; + // 增加参数控制app_ui_show_search_date + new Model('ir.config_parameter').call('search_read', [[['key', '=', 'app_ui_show_search_date']], ['value']]).then(function (show) { + if (show.length >= 1 && (show[0]['value'] == "True")) { + _.each(self.columns, function (value, key, list) { + if (value.store && value.type === "datetime" || value.type === "date") { + date_fields.push([value.name, value.string, value.type]); + } + }); + if (date_fields.length > 0) { + self.$search_button = $(QWeb.render('odooApp.buttons', {'date_fields': date_fields})) + self.$search_button.find('.app_start_date').datetimepicker(datepickers_options); + self.$search_button.find('.app_end_date').datetimepicker(datepickers_options); + // self.$search_button.find('.app_search_date_rate').click(function() { + // self.tgl_search(); + // }); + self.$search_button.find('.app_start_date').on('change', function () { + self.tgl_search(); + }); + self.$search_button.find('.app_end_date').on('change', function () { + self.tgl_search(); + }); + self.$search_button.find('.app_select_field').on('change', function () { + self.tgl_search(); + }); + self.$search_button.appendTo(self.$buttons); + } + } + }); + + + var number_fields = []; + + // 增加参数控制app_ui_show_search_number + new Model('ir.config_parameter').call('search_read', [[['key', '=', 'app_ui_show_search_number']], ['value']]).then(function (show) { + if (show.length >= 1 && (show[0]['value'] == "True")) { + _.each(self.columns, function (value, key, list) { + if (value.string && value.string.length > 1 && value.store && (value.type === "integer" || value.type === "float" || value.type === "monetary")) { + number_fields.push([value.name, value.string]); + } + }); + + if (number_fields.length == 0) { + if (self.fields_range) { + number_fields = self.fields_range; + } + } + if (number_fields.length > 0) { + self.$search_range = $(QWeb.render('odooApp.SearchRange', {'number_fields': number_fields})) + // self.$search_range.find('.app_search_date_range').click(function() { + // self.tgl_search(); + // }); + self.$search_range.find('.app_select_range_field').on('change', function () { + self.tgl_search(); + }); + self.$search_range.find('.app_start_range').on('change', function () { + self.tgl_search(); + }); + self.$search_range.find('.app_end_range').on('change', function () { + self.tgl_search(); + }); + self.$search_range.appendTo(self.$buttons); + } + } + }); + + // Dropdown list + _.each(this.ts_context, function(item){ + var field = _.find(self.columns, function(column){ + return column.type == 'many2one' && column.relation && column.name === item.name; + }); + if (field) { + self.ts_fields.push(item.name); + new Model(field.relation).query(['id', 'display_name']).filter(new data.CompoundDomain(item.domain, field.domain)).context(new data.CompoundContext()).all().then(function (result) { + // var single_search = $(QWeb.render('odooApp.selection', { + // 'string': item.string, + // 'class_name': 'app_item_' + item.name, + // 'fields': result, + // })); + if (!$('.after_control_panel').length) { + // $(QWeb.render('odooApp.after_control_panel', {})).appendTo($('.o_control_panel')); + // $(QWeb.render('odooApp.after_control_panel', {})).appendTo($('.o_cp_left')); + + // $(QWeb.render('odooApp.after_control_panel', {})).appendTo(self.$buttons); + + var multi_search = $(QWeb.render("TGL.TreeSearch.Item", {'widget': { + 'string': item.string, + 'key': item.name, + 'class_name': 'app_multi_item_' + item.name, + 'fields': result, + }})) + + multi_search.find('li').click(self.on_button_click.bind(self)); + multi_search.appendTo(self.$buttons); + } + // single_search.appendTo($('.after_control_panel')); + // $('.app_item_' + item.name).on('change', function() { + // self.tgl_search(); + // }) + }); + } + }); + + + }, + + do_search: function(domain, context, group_by) { + var self = this; + this.last_domain = domain; + this.last_context = context; + this.last_group_by = group_by; + this.old_search = _.bind(this._super, this); + return self.tgl_search(); + }, + + tgl_search: function() { + var self = this; + var domain = [], value, value_tmp; + + _.each(self.ts_fields, function(field){ + value = $('.app_item_' + field).val(); + + var select_fields = $('.app_multi_item_' + field).children('.selected'), + select_value = []; + if (select_fields.length > 0) { + _.each(select_fields, function(item){ + value_tmp = $(item).data('field'); + if (value_tmp > 0) { + select_value.push($(item).data('field')); + } + }); + if (select_value.length) { + domain.push([field, 'in', select_value]); + } + + } + }); +// 注意,date和datetime型的处理是不同的,已处理完 + if (self.$search_button) { + var start_date = self.$search_button.find('.app_start_date').val(), + end_date = self.$search_button.find('.app_end_date').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; + return false; + } + }); + + moment.locale(tz); + var l10n = _t.database.parameters; + if (start_date) { + if (field_type === '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 (field_type === '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) { + var start_range = self.$search_range.find('.app_start_range').val(), + end_range = self.$search_range.find('.app_end_range').val(), + range_field = self.$search_range.find('.app_select_range_field').val(); + + if (start_range) { + domain.push([range_field, '>=', parseInt(start_range)]); + } + if (end_range) { + domain.push([range_field, '<=', parseInt(end_range)]); + } + } + // console.log(domain); + var compound_domain = new data.CompoundDomain(self.last_domain, domain); + self.dataset.domain = compound_domain.eval(); + return self.old_search(compound_domain, self.last_context, self.last_group_by); + }, + +}); + +}); \ No newline at end of file diff --git a/app_ui_enhance/static/src/xml/pivot_view.xml b/app_ui_enhance/static/src/xml/pivot_view.xml new file mode 100644 index 00000000..4ba3d0c3 --- /dev/null +++ b/app_ui_enhance/static/src/xml/pivot_view.xml @@ -0,0 +1,101 @@ + + + + + + + + + + +

+
+ + + +
+ + + +
+
+ +
+ + + +
+
+
+
+ + +
+ + + +
+ +
    +
  • All
  • +
  • + +
  • +
+
+ +
+ + + \ No newline at end of file diff --git a/app_ui_enhance/views/app_ui_config_settings_view.xml b/app_ui_enhance/views/app_ui_config_settings_view.xml new file mode 100644 index 00000000..7e22492f --- /dev/null +++ b/app_ui_enhance/views/app_ui_config_settings_view.xml @@ -0,0 +1,47 @@ + + + + + App Odoo Customize Settings + app.ui.config.settings + +
+
+
+ + + + + +
+
+ + + UI Enhance + ir.actions.act_window + app.ui.config.settings + form + inline + + + +
+
diff --git a/app_ui_enhance/views/template_view.xml b/app_ui_enhance/views/template_view.xml new file mode 100644 index 00000000..e55a45fc --- /dev/null +++ b/app_ui_enhance/views/template_view.xml @@ -0,0 +1,14 @@ + + + + + + + + \ No newline at end of file