From db4e315da9debe5f6d79de86462373beca9e7873 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=B9=8F=E5=AE=87?= Date: Tue, 20 Jan 2026 17:25:36 +0800 Subject: [PATCH] =?UTF-8?q?=E7=89=A9=E4=B8=9A=E4=BF=A1=E6=81=AF=E4=B8=8D?= =?UTF-8?q?=E9=87=8D=E5=A4=8D=E5=88=9B=E5=BB=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- yuthon_property/models/yuthon_property.py | 90 ++++++++++++++++++++++- 1 file changed, 89 insertions(+), 1 deletion(-) diff --git a/yuthon_property/models/yuthon_property.py b/yuthon_property/models/yuthon_property.py index e3806ed35..612f39ee6 100644 --- a/yuthon_property/models/yuthon_property.py +++ b/yuthon_property/models/yuthon_property.py @@ -727,6 +727,33 @@ class TitleInformationLine(models.Model): start_time = fields.Date(string="生效日期", default=fields.Date.today) end_date = fields.Date(string="失效日期") + def _check_duplicate_date(self, prop_id, date_val, exclude_id=None): + """Block duplicate effective dates for the same property.""" + if not prop_id or not date_val: + return + domain = [ + ('yuthon_property_id', '=', prop_id), + ('start_time', '=', date_val), + ] + if exclude_id: + domain.append(('id', '!=', exclude_id)) + if self.search_count(domain): + raise UserError('同一物业的产权信息生效日期不能重复。') + + @api.model + def create(self, vals): + prop_id = vals.get('yuthon_property_id') + date_val = vals.get('start_time') or fields.Date.context_today(self) + self._check_duplicate_date(prop_id, date_val) + return super().create(vals) + + def write(self, vals): + for rec in self: + prop_id = vals.get('yuthon_property_id', rec.yuthon_property_id.id) + date_val = vals.get('start_time', rec.start_time) + rec._check_duplicate_date(prop_id, date_val, exclude_id=rec.id) + return super().write(vals) + def message_record(self): return { "type": "ir.actions.act_window", @@ -753,6 +780,32 @@ class ManageInformationLine(models.Model): end_date = fields.Date(string="失效日期") create_date = fields.Date(string="创建日期", default=fields.Date.today) + def _check_duplicate_date(self, prop_id, date_val, exclude_id=None): + if not prop_id or not date_val: + return + domain = [ + ('yuthon_property_id', '=', prop_id), + ('start_time', '=', date_val), + ] + if exclude_id: + domain.append(('id', '!=', exclude_id)) + if self.search_count(domain): + raise UserError('同一物业的管理信息生效日期不能重复。') + + @api.model + def create(self, vals): + prop_id = vals.get('yuthon_property_id') + date_val = vals.get('start_time') or fields.Date.context_today(self) + self._check_duplicate_date(prop_id, date_val) + return super().create(vals) + + def write(self, vals): + for rec in self: + prop_id = vals.get('yuthon_property_id', rec.yuthon_property_id.id) + date_val = vals.get('start_time', rec.start_time) + rec._check_duplicate_date(prop_id, date_val, exclude_id=rec.id) + return super().write(vals) + @api.onchange('precinct_id') def _onchange_precinct_id(self): for record in self: @@ -823,4 +876,39 @@ class YuthonMajorEventLine(models.Model): major_id = fields.Many2one('major.event.setting', string="重大事件") inspector_html = fields.Html(related='major_id.inspector_html', string="内容") documents_ids = fields.Many2many(related='major_id.documents_ids', string="附件") - start_date = fields.Date(related='major_id.start_date') + start_date = fields.Date(related='major_id.start_date', store=True) + + def _get_date_from_vals(self, vals): + """Get start_date considering related major_id.""" + if vals.get('start_date'): + return vals['start_date'] + major_id = vals.get('major_id') + if major_id: + return self.env['major.event.setting'].browse(major_id).start_date + return None + + def _check_duplicate_date(self, prop_id, date_val, exclude_id=None): + if not prop_id or not date_val: + return + domain = [ + ('yuthon_property_id', '=', prop_id), + ('start_date', '=', date_val), + ] + if exclude_id: + domain.append(('id', '!=', exclude_id)) + if self.search_count(domain): + raise UserError('同一物业的重大事项生效日期不能重复。') + + @api.model + def create(self, vals): + prop_id = vals.get('yuthon_property_id') + date_val = self._get_date_from_vals(vals) + self._check_duplicate_date(prop_id, date_val) + return super().create(vals) + + def write(self, vals): + for rec in self: + prop_id = vals.get('yuthon_property_id', rec.yuthon_property_id.id) + date_val = self._get_date_from_vals(vals) if 'major_id' in vals or 'start_date' in vals else rec.start_date + rec._check_duplicate_date(prop_id, date_val, exclude_id=rec.id) + return super().write(vals)