!4232 添加功能

Merge pull request !4232 from 李鹏宇/dev_zhou
This commit is contained in:
李鹏宇
2025-07-31 15:09:39 +00:00
committed by Gitee
2 changed files with 38 additions and 22 deletions
@@ -344,7 +344,7 @@ class PropertyAccountsReceivable(models.Model):
contract_id = fields.Many2one('property.lease.contract', string="关联租赁合同审批")
tenure_type = fields.Selection(related='property_id.tenure_type', string="权属类型", store=True)
precinct_id = fields.Many2one(related='property_id.precinct_id', string="所属片区", store=True)
penalty = fields.Float(string="违约金")
penalty = fields.Float(string="违约金基数")
penalty_date = fields.Date(string="违约金日期")
# 报表新增字段
rent_owed = fields.Float(string="欠租金额")
@@ -54,26 +54,40 @@ class PropertyReconciliationWizard(models.Model):
self.amount_reconciled = 0.0
return
# 没有精确匹配,按原逻辑分配
for index, line in enumerate(self.reconciliation_line_ids):
groups = {}
for line in self.reconciliation_line_ids:
key = (line.contract_id.id if line.contract_id else None,
line.property_id.id if line.property_id else None)
if key not in groups:
groups[key] = []
groups[key].append(line)
# 2. 每组内按due_date升序排序(日期最早的先分配)
sorted_lines = []
for group_key in groups:
sorted_group = sorted(
groups[group_key],
key=lambda x: x.due_date if x.due_date else fields.Date.max
)
sorted_lines.extend(sorted_group)
# 3. 按排序后的顺序分配金额
for line in sorted_lines:
rent = line.rent or 0
line.amount = 0 # 重置金额
if remaining_amount <= 0:
line.amount = 0
else:
if index < line_count - 1:
# 非最后一行:分配不超过rent的金额
line.amount = min(rent, remaining_amount)
remaining_amount -= line.amount
else:
# 最后一行:分配剩余所有金额
line.amount = min(rent, remaining_amount)
remaining_amount -= line.amount
continue
# 检查是否违约
if(line.due_date and self.actual_date and
line.collection_type != 'deposit'):
# 计算应收日期的下月1号
# 分配不超过租金和剩余金额的数值
assign_amount = min(rent, remaining_amount)
line.amount = assign_amount
remaining_amount -= assign_amount
# 检查是否违约(保留原有逻辑)
if (line.due_date and self.actual_date and
line.collection_type != 'deposit'):
# 计算应收日期的下月1号
next_month_first = (fields.Date.from_string(line.due_date) + relativedelta(months=1)).replace(day=1)
# 如果实收日期晚于下月1号,产生违约
@@ -88,13 +102,13 @@ class PropertyReconciliationWizard(models.Model):
penalty_line_vals = {
'property_id': line.property_id.id,
'contract_id': line.contract_id.id,
'rent_month': 0, # 违约金的当月租金为0
'rent_month': 0,
'due_date': line.due_date,
'rent': penalty_amount, # 违约金的应收租金为0
'rent': penalty_amount,
'amount': 0,
'collection_type': 'penalty', # 收款类型为违约金
'collection_type': 'penalty',
'remake': f'违约金 ({late_days}天)',
'sequence': int(line.sequence) + 1, # 顺序值为原记录+1
'sequence': int(line.sequence) + 1,
}
new_lines.append((0, 0, penalty_line_vals))
@@ -122,7 +136,7 @@ class PropertyReconciliationWizard(models.Model):
# 跳过金额为0的行
if line.amount == 0 and line.collection_type != 'penalty':
continue
first_day = self.actual_date.replace(day=1)
first_day = line.due_date.replace(day=1)
last_day = (first_day + relativedelta(months=1)) - relativedelta(days=1)
domain = [
('lessee_id', '=', first_line.tenant_id.id),
@@ -151,6 +165,7 @@ class PropertyReconciliationWizard(models.Model):
self.env['property.accounts.receivable'].create({
'is_reconciliation': True,
'due_date': line.due_date,
'penalty': line.amount,
'management_type_id': management_type_id.id,
'lessee_id': first_line.tenant_id.id,
'property_id': line.property_id.id,
@@ -162,6 +177,7 @@ class PropertyReconciliationWizard(models.Model):
})
class PropertyReconciliationLine(models.Model):
_name = 'property.reconciliation.line'
_description = '对账明细'