diff --git a/yuthon_ai_agent/__manifest__.py b/yuthon_ai_agent/__manifest__.py index ef3cd5e23..f16df757e 100644 --- a/yuthon_ai_agent/__manifest__.py +++ b/yuthon_ai_agent/__manifest__.py @@ -15,7 +15,7 @@ 'author': 'pengyuthon', 'version': '17.0.2.2.2', 'license': 'LGPL-3', - 'depends': ['base', 'web', 'hr', 'documents', 'sh_backmate_theme_adv_enterprise'], + 'depends': ['base', 'web', 'hr', 'documents'], 'data': [ 'security/ai_security.xml', 'security/ir.model.access.csv', diff --git a/yuthon_datetime_rounding/__init__.py b/yuthon_datetime_rounding/__init__.py new file mode 100644 index 000000000..0650744f6 --- /dev/null +++ b/yuthon_datetime_rounding/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/yuthon_datetime_rounding/__manifest__.py b/yuthon_datetime_rounding/__manifest__.py new file mode 100644 index 000000000..8e367c419 --- /dev/null +++ b/yuthon_datetime_rounding/__manifest__.py @@ -0,0 +1,27 @@ +{ + 'name': 'Yuthon Datetime Rounding', + 'version': '17.0.1.0.0', + 'category': 'Technical', + 'summary': '时间选择器默认分钟精确(rounding=1),可用系统参数 yuthon_datetime.rounding 调整', + 'description': """ +Yuthon Datetime Rounding +======================== +Odoo 时间选择器(DateTimePicker)默认 rounding=5(分钟只能选 0/5/10/.../55), +导致"选05变04"之类的分钟精度困惑。 + +本模块把默认改为分钟精确(rounding=1): +- 全局默认值:系统参数 yuthon_datetime.rounding(1=分钟精确,5=每5分钟,15=每15分钟...), + 修改后重新登录或刷新页面生效; +- 视图里字段若显式配置 options="{'rounding': N}",则以视图设置为准(不会被覆盖)。 +""", + 'depends': ['web'], + 'data': [], + 'assets': { + 'web.assets_backend': [ + 'yuthon_datetime_rounding/static/src/js/datetime_picker.js', + ], + }, + 'installable': True, + 'application': False, + 'auto_install': False, +} diff --git a/yuthon_datetime_rounding/models/__init__.py b/yuthon_datetime_rounding/models/__init__.py new file mode 100644 index 000000000..9a5eb7187 --- /dev/null +++ b/yuthon_datetime_rounding/models/__init__.py @@ -0,0 +1 @@ +from . import ir_http diff --git a/yuthon_datetime_rounding/models/ir_http.py b/yuthon_datetime_rounding/models/ir_http.py new file mode 100644 index 000000000..d460d8beb --- /dev/null +++ b/yuthon_datetime_rounding/models/ir_http.py @@ -0,0 +1,17 @@ +# -*- coding: utf-8 -*- +"""把系统参数 yuthon_datetime.rounding 注入前端 session_info,供 JS 读取。""" +from odoo import models + + +class IrHttp(models.AbstractModel): + _inherit = 'ir.http' + + def get_session_info(self): + res = super().get_session_info() + try: + rounding = int(self.env['ir.config_parameter'].get_param( + 'yuthon_datetime.rounding', '1') or '1') + except Exception: + rounding = 1 + res['yuthon_datetime_rounding'] = rounding + return res diff --git a/yuthon_datetime_rounding/static/src/js/datetime_picker.js b/yuthon_datetime_rounding/static/src/js/datetime_picker.js new file mode 100644 index 000000000..30a02b3eb --- /dev/null +++ b/yuthon_datetime_rounding/static/src/js/datetime_picker.js @@ -0,0 +1,51 @@ +/** @odoo-module **/ + +import { patch } from "@web/core/utils/patch"; +import { DateTimePicker } from "@web/core/datetime/datetime_picker"; + +// yuthon_datetime_rounding v2(Odoo 16 / 17 通用) +// --------------------------------------------------------------------------- +// 目的:Odoo 时间选择器(DateTimePicker)默认 rounding=5(分钟只能选 0/5/10/.../55), +// 导致"选05变04 / 选00变59"这类分钟精度困惑。 +// 本补丁把"未显式配置 rounding 的字段"默认改为分钟精确(rounding=1): +// - 全局默认值来自系统参数 yuthon_datetime.rounding(1=分钟精确,5=每5分钟,15=每15分钟...), +// 修改后重新登录或刷新页面(session_info 刷新)生效; +// - 视图里字段显式配置 options="{'rounding': N}" 且 N 非 5 时,尊重视图设置(不覆盖)。 +// 实现双保险:① 基类 setup 前修正 props.rounding,让基类初始计算即用新值; +// ② setup 后按需重算 availableMinutes,兼容基类内部实现差异。 +// --------------------------------------------------------------------------- + +function getForcedRounding() { + const raw = odoo.session_info && odoo.session_info.yuthon_datetime_rounding; + const n = parseInt(raw, 10); + return Number.isFinite(n) && n > 0 ? n : 1; +} + +function buildMinutes(step) { + const all = Array.from({ length: 60 }, (_, i) => [i, String(i).padStart(2, "0")]); + return step === 1 ? all : all.filter(([m]) => !(m % step)); +} + +patch(DateTimePicker.prototype, { + setup() { + const wasDefault = + this.props.rounding === undefined || this.props.rounding === 5; + if (wasDefault) { + this.props.rounding = getForcedRounding(); + } + super.setup(); + if (wasDefault && this.props.rounding > 0) { + this.availableMinutes = buildMinutes(this.props.rounding); + } + }, + onPropsUpdated(props) { + if (typeof super.onPropsUpdated === "function") { + super.onPropsUpdated(props); + } + const isDefault = + props.rounding === undefined || props.rounding === 5; + if (isDefault && this.props.rounding > 0) { + this.availableMinutes = buildMinutes(this.props.rounding); + } + }, +});