From 55d644eea87879127dc74acf93c1766c1cd25646 Mon Sep 17 00:00:00 2001
From: zhou <123@>
Date: Thu, 8 May 2025 10:12:28 +0800
Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=8A=9F=E8=83=BD?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
yuthon_notice/data/notice_code_data.xml | 3 ++-
yuthon_notice/models/yuthon_notice.py | 9 ++++++++-
2 files changed, 10 insertions(+), 2 deletions(-)
diff --git a/yuthon_notice/data/notice_code_data.xml b/yuthon_notice/data/notice_code_data.xml
index 2c5bc2d1c..d6bfa7ed5 100644
--- a/yuthon_notice/data/notice_code_data.xml
+++ b/yuthon_notice/data/notice_code_data.xml
@@ -3,8 +3,9 @@
通知公告编号
notice_code
- TZ%(y)s%(month)s%(day)s
+ TZ
3
+
diff --git a/yuthon_notice/models/yuthon_notice.py b/yuthon_notice/models/yuthon_notice.py
index 51ddfd026..b639a37e8 100644
--- a/yuthon_notice/models/yuthon_notice.py
+++ b/yuthon_notice/models/yuthon_notice.py
@@ -1,7 +1,9 @@
# -*- coding: utf-8 -*-
from odoo import api, fields, models, tools, _
from odoo.exceptions import ValidationError, UserError
+import logging
+_logger = logging.getLogger(__name__)
class YuthonNotice(models.Model):
_name = "yuthon.notice"
@@ -11,7 +13,7 @@ class YuthonNotice(models.Model):
_order = "sequence desc"
name = fields.Char(string='标题')
- code = fields.Char(string="编号", default=lambda self: self.env['ir.sequence'].next_by_code('notice_code'))
+ code = fields.Char(string="编号", default=lambda self: self._get_default_code())
users_id = fields.Many2one('res.users', string="发布人", default=lambda self: self.env.user)
department_id = fields.Many2one(related='users_id.employee_id.department_id', string="部门")
notice_type_id = fields.Many2one('yuthon.notice.type', string="类型")
@@ -39,6 +41,11 @@ class YuthonNotice(models.Model):
active = fields.Boolean('Active', default=True, tracking=True)
work_end = fields.Boolean(string="结束")
+ def _get_default_code(self):
+ sequence_code = self.env['ir.sequence'].next_by_code('notice_code')
+ _logger.info("Generated sequence code: %s", sequence_code)
+ return sequence_code
+
@api.model_create_multi
def create(self, vals_list):
for i in vals_list: