物业信息不重复创建
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user