From 79ba570712870634130b5263b3e827041caf8f1f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=B9=8F=E5=AE=87?= <9664676+pengyuthon@user.noreply.gitee.com> Date: Thu, 18 Jun 2026 11:20:45 +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_official/models/yuthon_official.py | 43 +++++++++---------- .../views/yuthon_sub_enterprises_view.xml | 2 +- 2 files changed, 22 insertions(+), 23 deletions(-) diff --git a/yuthon_official/models/yuthon_official.py b/yuthon_official/models/yuthon_official.py index d5822b7d8..0616a883a 100644 --- a/yuthon_official/models/yuthon_official.py +++ b/yuthon_official/models/yuthon_official.py @@ -55,7 +55,7 @@ class YuthonOfficial(models.Model): date = fields.Datetime(string="拟稿日期", default=fields.Datetime.now) official_statu = fields.Selection([('done', '办结'), ('approval', '审核')], string="公文环节") users_id = fields.Many2one('res.users', string="拟稿人", default=lambda self: self.env.user) - department_id = fields.Many2one(related='users_id.employee_ids.department_id', string="拟稿部门") + department_id = fields.Many2one('hr.department', string="拟稿部门") company_id = fields.Many2one(related='users_id.company_id', string="公司") company_id1 = fields.Many2one('res.company', string="公司前缀", default=lambda self: self.env.company) is_meet = fields.Boolean(string="是否上会") @@ -90,6 +90,21 @@ class YuthonOfficial(models.Model): is_company = fields.Boolean(string="本公司", default=True, compute='_compute_is_company', search='_search_part_of_company') + @api.onchange('users_id') + def _onchange_users_id(self): + employee = self.users_id.employee_id + if employee: + self.department_id = employee.department_id + dept_ids = [employee.department_id.id] + employee.department_ids.ids + return {'domain': { + 'department_id': [('id', 'in', dept_ids)], + }} + else: + self.department_id = False + return {'domain': { + 'department_id': [('id', 'in', [])], + }} + @api.depends('code') def _compute_workflow(self): for record in self: @@ -109,25 +124,19 @@ class YuthonOfficial(models.Model): employee.is_company = employee.company_id in active_company_ids def _search_part_of_company(self, operator, value): - company_ids = self.env.companies.ids # 获取公司ID列表 - # 处理反向操作符 + company_ids = self.env.companies.ids if not value: operator = '!=' if operator == '=' else '=' - # 使用company_id in company_ids的结构 if operator == '=': return [('company_id', 'in', company_ids)] - else: # operator == '!=' + else: return [('company_id', 'not in', company_ids)] @api.depends('name') def _compute_text(self): - """ - 计算text字段,值等于name字段 - """ for record in self: record.text = record.name or '' - def end_approval(self): self.write({'work_end': True}) if any(flat.name == '广州市天河投资集团有限公司' for flat in self.main_flats_ids): @@ -304,12 +313,10 @@ class YuthonOfficial(models.Model): def button_transfer(self): """转交按钮""" - # 这里可以添加转交的逻辑 pass def button_withdraw(self): """收回按钮""" - # 这里可以添加收回的逻辑 pass @@ -319,7 +326,6 @@ class YuthonPropertyOfficial(models.Model): _inherit = ['soong.workflow.mixin', 'mail.thread.main.attachment', 'mail.activity.mixin'] _rec_name = 'name' - name = fields.Char(string="标题") text = fields.Text(string="标题", compute='_compute_text', store=True) code = fields.Char(string="编号", default=lambda self: self.env['ir.sequence'].next_by_code('official_code')) @@ -418,21 +424,16 @@ class YuthonPropertyOfficial(models.Model): employee.is_company = employee.company_id in active_company_ids def _search_part_of_company(self, operator, value): - company_ids = self.env.companies.ids # 获取公司ID列表 - # 处理反向操作符 + company_ids = self.env.companies.ids if not value: operator = '!=' if operator == '=' else '=' - # 使用company_id in company_ids的结构 if operator == '=': return [('company_id', 'in', company_ids)] - else: # operator == '!=' + else: return [('company_id', 'not in', company_ids)] @api.depends('name') def _compute_text(self): - """ - 计算text字段,值等于name字段 - """ for record in self: record.text = record.name or '' @@ -571,10 +572,8 @@ class YuthonPropertyOfficial(models.Model): def button_transfer(self): """转交按钮""" - # 这里可以添加转交的逻辑 pass def button_withdraw(self): """收回按钮""" - # 这里可以添加收回的逻辑 - pass \ No newline at end of file + pass diff --git a/yuthon_official/views/yuthon_sub_enterprises_view.xml b/yuthon_official/views/yuthon_sub_enterprises_view.xml index e05e1fe55..4819bd863 100644 --- a/yuthon_official/views/yuthon_sub_enterprises_view.xml +++ b/yuthon_official/views/yuthon_sub_enterprises_view.xml @@ -4,7 +4,7 @@ yuthon.sub.enterprises.tree yuthon.sub.enterprises - +