From 1c00b9477a64dd3f08b52049de9df96bcf0c2bb6 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: Wed, 3 Sep 2025 10:35:16 +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
---
.../wizard/soong_workflow_comment_wizard.py | 2 -
.../models/property_lease_contract.py | 2 +-
.../models/property_penalty_relief.py | 24 +++++---
.../models/property_rent_relief.py | 56 +++++++++++++++++--
.../views/property_penalty_relief.xml | 7 +--
.../views/property_rent_relief.xml | 44 +++++++++------
6 files changed, 97 insertions(+), 38 deletions(-)
diff --git a/soong_workflow/wizard/soong_workflow_comment_wizard.py b/soong_workflow/wizard/soong_workflow_comment_wizard.py
index 955cf701d..57a2651d3 100644
--- a/soong_workflow/wizard/soong_workflow_comment_wizard.py
+++ b/soong_workflow/wizard/soong_workflow_comment_wizard.py
@@ -154,8 +154,6 @@ class SoongWorkflowCommentWizard(models.TransientModel):
for record in self:
if not record.trans_link_id:
continue
- available_links = self.env['trans.link'].search([])
- record.invalid_link_ids = available_links[1:]
record_id = self.env[record.res_model].browse(record.res_id) if record.res_model and record.res_id else None
for link in record.trans_link_id:
employee_user_role_ids = self._get_approvers_for_link(link, record_id)
diff --git a/yuthon_property_approval/models/property_lease_contract.py b/yuthon_property_approval/models/property_lease_contract.py
index c0898308a..c69054d9b 100644
--- a/yuthon_property_approval/models/property_lease_contract.py
+++ b/yuthon_property_approval/models/property_lease_contract.py
@@ -398,7 +398,7 @@ class PropertyLeaseContract(models.Model):
'view_mode': 'form',
}
- @api.depends('contract_code', 'name', 'contract_type')
+ @api.depends('contract_code', 'name', 'contract_type', 'property_name')
def _compute_name(self):
contract_dict = {
'lease_renewal': '续租',
diff --git a/yuthon_property_approval/models/property_penalty_relief.py b/yuthon_property_approval/models/property_penalty_relief.py
index 959ee7c0f..a416a8af6 100644
--- a/yuthon_property_approval/models/property_penalty_relief.py
+++ b/yuthon_property_approval/models/property_penalty_relief.py
@@ -13,13 +13,12 @@ class PropertyPenaltyRelief(models.Model):
_rec_name = 'name'
name = fields.Char(string='标题')
- reason = fields.Text(string="正文")
+ reason = fields.Text(string="减免原因")
users_id = fields.Many2one('res.users', string="申请人", default=lambda self: self.env.user.id)
department_id = fields.Many2one('hr.department', string="部门", related='users_id.employee_id.department_id')
code = fields.Char(string="编号",
default=lambda self: self.env['ir.sequence'].next_by_code('property_rent_relief_code'))
- property_documents_ids = fields.Many2many('documents.document', string="违约金减免文件")
- reason_abatement = fields.Char(string="减免原因")
+ property_documents_ids = fields.Many2many('ir.attachment', string="违约金减免文件")
contract_id = fields.Many2one('property.lease.contract', string="合同")
lessee_id = fields.Many2one('property.tenant.information', string='承租方')
property_id = fields.Many2one('yuthon.property', string='物业')
@@ -53,6 +52,20 @@ class PropertyPenaltyRelief(models.Model):
'approval_date': fields.Datetime.now(),
})
+ @api.onchange('lessee_id')
+ def _onchange_lessee_id(self):
+ for record in self:
+ if record.lessee_id:
+ contract_id = self.env['property.lease.contract'].search([('lessee_id', '=', record.lessee_id.id)], limit=1)
+ if contract_id:
+ record.contract_id = contract_id.id
+
+ @api.onchange('contract_id')
+ def _onchange_contract_id(self):
+ for record in self:
+ if record.contract_id.lease_ids:
+ record.property_id = record.contract_id.lease_ids[0].address_id.id
+
class PropertyPenaltyReliefLine(models.Model):
_name = 'property.penalty.relief.line'
@@ -93,7 +106,4 @@ class PropertyPenaltyReliefLine(models.Model):
], limit=1)
if rental_record:
- record.rental_principal = rental_record.amount
-
-
-
+ record.rental_principal = rental_record.amount
\ No newline at end of file
diff --git a/yuthon_property_approval/models/property_rent_relief.py b/yuthon_property_approval/models/property_rent_relief.py
index 1bd89d84f..b8b852e2d 100644
--- a/yuthon_property_approval/models/property_rent_relief.py
+++ b/yuthon_property_approval/models/property_rent_relief.py
@@ -2,6 +2,7 @@
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from odoo import models, fields, api, exceptions, _
from odoo.exceptions import UserError, ValidationError
+from dateutil.relativedelta import relativedelta
class PropertyRentRelief(models.Model):
@@ -11,7 +12,7 @@ class PropertyRentRelief(models.Model):
_rec_name = 'name'
name = fields.Char(string='标题')
- reason = fields.Text(string="正文")
+ reason = fields.Text(string="减免原因")
code = fields.Char(string="编号",
default=lambda self: self.env['ir.sequence'].next_by_code('property_penalty_relief_code'))
users_id = fields.Many2one('res.users', string="申请人", default=lambda self: self.env.user.id)
@@ -22,7 +23,6 @@ class PropertyRentRelief(models.Model):
is_issues = fields.Boolean(string='是否上会')
issues_result = fields.Html(string="会议结果")
related_issues_id = fields.Many2one('issue.library', string="关联议题")
- abatement_reason = fields.Text(string="减免原因")
property_documents_ids = fields.Many2many('ir.document', string="附件")
property_rent_relief_ids = fields.One2many('property.rent.relief.line', 'property_rent_relief_id', string="租金列表")
urgency_level = fields.Selection([('normal', '普件'), ('urgent', '急件'), ('emergency', '特急件')], string='紧急度',
@@ -51,14 +51,58 @@ class PropertyRentRelief(models.Model):
'approval_date': fields.Datetime.now(),
})
+ @api.onchange('lessee_id')
+ def _onchange_lessee_id(self):
+ for record in self:
+ contract_id = self.env['property.lease.contract'].search([('lessee_id', '=', record.lessee_id.id)], limit=1)
+ if contract_id:
+ record.contract_id = contract_id.id
+
+ @api.onchange('contract_id')
+ def _onchange_contract_id(self):
+ for record in self:
+ if record.contract_id.lease_ids:
+ record.property_id = record.contract_id.lease_ids[0].address_id.id
+
class PropertyRentReliefLine(models.Model):
_name = 'property.rent.relief.line'
_description = '租金列表'
property_rent_relief_id = fields.Many2one('property.rent.relief', string="关联租金减免审批")
- rental_principal = fields.Float(string="租金本金")
- receivable_date = fields.Date(string="应收日期")
- penalty = fields.Float(string="违约金")
- deduction_amount = fields.Float(string="减免金额")
+ lessee_id = fields.Many2one('property.tenant.information', string='承租方')
+ property_id = fields.Many2one('yuthon.property', string='物业')
+ contract_id = fields.Many2one('property.lease.contract', string="合同")
+ penalty_id = fields.Many2one('property.accounts.receivable', string="违约金")
+ rental_principal = fields.Float(string="租金本金", compute="_compute_rental_principal")
+ start_time = fields.Date(related="penalty_id.due_date", string="应收开始", store=True)
+ end_time = fields.Date(related="penalty_id.due_date_end", string="应收结束", store=True)
+ penalty_amount = fields.Float(related="penalty_id.original_amount", string="违约金")
+ penalty_relief = fields.Float(related="penalty_id.discount_amount", string="减免金额")
+
+ @api.depends('start_time', 'property_id', 'contract_id')
+ def _compute_rental_principal(self):
+ for record in self:
+ # 初始化租金本金为0
+ record.rental_principal = 0.0
+ if not all([record.start_time, record.property_id, record.contract_id]):
+ continue
+
+ # 计算上个月的第一天和最后一天
+ start_date = fields.Date.from_string(record.start_time)
+ first_day_of_last_month = (start_date.replace(day=1) - relativedelta(days=1)).replace(day=1)
+ last_day_of_last_month = start_date.replace(day=1) - relativedelta(days=1)
+ first_day_str = fields.Date.to_string(first_day_of_last_month)
+ last_day_str = fields.Date.to_string(last_day_of_last_month)
+
+ rental_record = self.env['property.accounts.receivable'].search([
+ ('property_id', '=', record.property_id.id),
+ ('contract_id', '=', record.contract_id.id),
+ ('management_type_id.name', '=', '租金'),
+ ('due_date', '>=', first_day_str),
+ ('due_date', '<=', last_day_str)
+ ], limit=1)
+
+ if rental_record:
+ record.rental_principal = rental_record.amount
diff --git a/yuthon_property_approval/views/property_penalty_relief.xml b/yuthon_property_approval/views/property_penalty_relief.xml
index 68896446a..31c1d740a 100644
--- a/yuthon_property_approval/views/property_penalty_relief.xml
+++ b/yuthon_property_approval/views/property_penalty_relief.xml
@@ -47,12 +47,12 @@
-
+
-
+
@@ -84,9 +84,6 @@
-
-
-
diff --git a/yuthon_property_approval/views/property_rent_relief.xml b/yuthon_property_approval/views/property_rent_relief.xml
index 3d8856ec0..9da5abbfd 100644
--- a/yuthon_property_approval/views/property_rent_relief.xml
+++ b/yuthon_property_approval/views/property_rent_relief.xml
@@ -51,27 +51,37 @@
-
-
-
-
-
-
-
-
-
+
+
+
+
-
-
-
-
-
-
-
-
+ context="{
+ 'default_property_id': property_id,
+ 'default_contract_id': contract_id,
+ 'default_lessee_id': lessee_id,
+ }">
+
+
+
+
+
+
+
+
+
+
+
+
+