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 @@ - - - + + +