# -*- coding: utf-8 -*-
import logging
from odoo import api, fields, models
from odoo.exceptions import UserError, ValidationError

_logger = logging.getLogger(__name__)


class WxWorkApprovalTemplateSummary(models.Model):
    _name = 'wxwork.approval.template.summary'
    _description = "企业微信审批模板摘要"
    # _rec_name = "title"

    template_id = fields.Many2one('wxwork.approval.template', string='模板名称')
    text = fields.Char(string='摘要行显示文字', size=20)
    lang = fields.Selection([
        ('zh_CN', '中文'),
        ('en', '英文')
    ], string='控件类型', default='中文')

    # @api.constrains('template_id')
    # def _check_max_records(self):
    #     for record in self:
    #         # 统计与当前template_id相关联的记录数
    #         related_records_count = self.search_count([
    #             ('template_id', '=', record.template_id.id)
    #         ])
    #
    #         # 如果记录数大于3，则引发异常
    #         if related_records_count > 3:
    #             raise ValidationError("最多只能有三条记录")
