From e3e09f29c24f9bf8eb8fa4033d7beba767d61622 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=B9=8F=E5=AE=87?= Date: Mon, 16 Mar 2026 12:07:47 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=A1=E6=89=B9=E6=84=8F=E8=A7=81=E5=88=9B?= =?UTF-8?q?=E5=BB=BA=E4=BF=AE=E6=94=B9=E8=AE=B0=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- soong_workflow/models/soong_note.py | 44 +++++++++++------------ soong_workflow/views/soong_note_views.xml | 6 ++-- 2 files changed, 24 insertions(+), 26 deletions(-) diff --git a/soong_workflow/models/soong_note.py b/soong_workflow/models/soong_note.py index 8281b7527..152819dbe 100644 --- a/soong_workflow/models/soong_note.py +++ b/soong_workflow/models/soong_note.py @@ -10,39 +10,37 @@ class SoongNote(models.Model): name = fields.Char(string="审批意见") sequence = fields.Char(string='序号', store=True) note_setting_id = fields.Many2one('soong.note.setting', string="意见类型") - create_note = fields.Char(string="创建信息", readonly=True) - write_note = fields.Char(string="修改信息", readonly=True) + create_note = fields.Text(string="创建信息", readonly=True) + write_note = fields.Text(string="修改信息", readonly=True) use_info = fields.Text(string="使用信息", readonly=True) - create_note_display = fields.Char(string="创建信息", compute='_compute_display_fields') - write_note_display = fields.Char(string="修改信息", compute='_compute_display_fields') - use_info_display = fields.Text(string="使用信息", compute='_compute_display_fields') - @api.depends('create_note', 'write_note', 'use_info', 'name') - def _compute_display_fields(self): - for rec in self: - suffix = f"\n{rec.name}" if rec.name else '' - rec.create_note_display = (rec.create_note or '') + suffix - rec.write_note_display = (rec.write_note or '') + suffix - rec.use_info_display = (rec.use_info or '') + suffix - - def _format_user_time(self): - """返回'当前用户名 YYYY-MM-DD HH:MM:SS'格式字符串(转换为东八区时间)""" - user = self.env.user + def _get_tz_now(self): + """返回东八区当前时间字符串""" tz = pytz.timezone('Asia/Shanghai') - now = datetime.now(pytz.utc).astimezone(tz).strftime('%Y-%m-%d %H:%M:%S') - return f"{user.name} {now}" + return datetime.now(pytz.utc).astimezone(tz).strftime('%Y-%m-%d %H:%M:%S') @api.model_create_multi def create(self, vals_list): - info = self._format_user_time() + now = self._get_tz_now() + user_name = self.env.user.name for vals in vals_list: - vals['create_note'] = info - vals['write_note'] = info + note_name = vals.get('name', '') + line = f"{user_name} {now} {note_name}" + vals['create_note'] = line + vals['write_note'] = line return super().create(vals_list) def write(self, vals): - vals['write_note'] = self._format_user_time() - return super().write(vals) + now = self._get_tz_now() + user_name = self.env.user.name + for rec in self: + note_name = vals.get('name', rec.name or '') + line = f"{user_name} {now} {note_name}" + old = rec.write_note or '' + vals_copy = dict(vals) + vals_copy['write_note'] = (old + '\n' + line) if old else line + super(SoongNote, rec).write(vals_copy) + return True # type = fields.Selection([('agree', '同意'), ('return', '退回'), ('refuse', '拒绝'), ('super', '督办')], # string="意见类型") diff --git a/soong_workflow/views/soong_note_views.xml b/soong_workflow/views/soong_note_views.xml index 9f2789198..28971e1b9 100644 --- a/soong_workflow/views/soong_note_views.xml +++ b/soong_workflow/views/soong_note_views.xml @@ -8,9 +8,9 @@ - - - + + +