44 lines
2.0 KiB
Python
44 lines
2.0 KiB
Python
from odoo import api, fields, models, tools
|
|
from odoo.exceptions import ValidationError
|
|
|
|
|
|
class IssueApprovalDecision(models.Model):
|
|
_name = "issue.approval.decision"
|
|
_description = '决策清单'
|
|
_order = 'sequence asc'
|
|
|
|
name = fields.Char(string='事项')
|
|
sequence = fields.Char(string='序号', store=True)
|
|
decision_id = fields.Many2one('issue.approval.decision', string='上级事项')
|
|
child_ids = fields.One2many('issue.approval.decision', 'decision_id', string='下级事项')
|
|
specifics = fields.Char(string='具体事项')
|
|
council = fields.Selection([('approval', '审'), ('decide', '决')], string='党总委员会')
|
|
team_meet = fields.Selection([('approval', '审'), ('decide', '决')], string='经营班子会')
|
|
board_meet = fields.Selection([('approval', '审'), ('decide', '决'), ('commission', '授权投决会')], string='董事会')
|
|
district_bureau = fields.Char(string='区政府、区财政局')
|
|
remarks = fields.Char(string='备注')
|
|
|
|
@api.onchange('sequence', 'decision_id')
|
|
def _onchange_department_code(self):
|
|
for code in self:
|
|
if code.sequence and code.decision_id:
|
|
code.sequence = code.decision_id.sequence + ('.' + code.sequence if code.sequence else '')
|
|
else:
|
|
code.sequence = code.sequence
|
|
code._update_child_sequences()
|
|
|
|
def _update_child_sequences(self):
|
|
def recursive_update(parent, parent_sequence):
|
|
# 遍历每个子记录
|
|
for child in parent.child_ids:
|
|
# 使用父级的 sequence 更新子级的 sequence
|
|
new_sequence = parent_sequence + ('.' + child.sequence.split('.')[-1] if child.sequence else '')
|
|
self.env['issue.approval.decision'].search([('id', '=', child.id.origin)]).write({'sequence': new_sequence})
|
|
# 递归处理孙级
|
|
recursive_update(child, new_sequence)
|
|
# 从当前记录开始递归更新所有子孙级别
|
|
recursive_update(self, self.sequence)
|
|
|
|
|
|
|