添加功能
This commit is contained in:
@@ -1018,72 +1018,8 @@ class PropertyAccountsReceivable(models.Model):
|
||||
|
||||
def generate_penalty(self):
|
||||
"""根据选中的租金应收生成违约金应收(仅对已对账部分,逾期判定 + 去重)"""
|
||||
created = skipped = 0
|
||||
for receivable in self:
|
||||
if receivable.management_type_id.name != '租金':
|
||||
continue
|
||||
if not receivable.is_liquidated_damages:
|
||||
continue
|
||||
if not receivable.is_overdue:
|
||||
continue
|
||||
if not receivable.contract_id:
|
||||
continue
|
||||
|
||||
percentage = receivable.contract_id.percentage_liquidated_damages
|
||||
if not percentage or not percentage.name:
|
||||
continue
|
||||
|
||||
first_day = (receivable.due_date_end).replace(day=1)
|
||||
penalty_days = (receivable.payout_date - first_day).days + 1
|
||||
modify_line = self.env['receivable.modify.line'].search([
|
||||
('receivable_id', '=', receivable.id),
|
||||
('reconciliation_date', '!=', False),
|
||||
('is_penalty', '=', False)
|
||||
], order='reconciliation_date asc', limit=1)
|
||||
if receivable.number_of_payments == 1:
|
||||
original_amount = receivable.original_amount
|
||||
elif modify_line:
|
||||
original_amount = receivable.original_amount - modify_line.amount
|
||||
penalty_amount = penalty_days * round(original_amount * float(percentage.name), 2)
|
||||
if penalty_amount <= 0:
|
||||
continue
|
||||
|
||||
existing = self.env['property.accounts.receivable'].search([
|
||||
('contract_id', '=', receivable.contract_id.id),
|
||||
('management_type_id.name', '=', '违约金'),
|
||||
('source_receivable_id', '=', receivable.id),
|
||||
('is_invalid', '=', False),
|
||||
], limit=1)
|
||||
if existing:
|
||||
skipped += 1
|
||||
continue
|
||||
|
||||
acc_receivable = self.env['property.accounts.receivable'].create({
|
||||
'contract_id': receivable.contract_id.id,
|
||||
'management_type_id': self.env['yuthon.management.type'].search(
|
||||
[('name', '=', '违约金')], limit=1).id,
|
||||
'due_date': first_day,
|
||||
'due_date_end': receivable.payout_date,
|
||||
'original_amount': penalty_amount,
|
||||
'remark': f'{first_day}到{receivable.payout_date}',
|
||||
'source_receivable_id': receivable.id,
|
||||
'charging_range': f'{first_day}到{receivable.payout_date}',
|
||||
'deposit_state': 'unpaid',
|
||||
})
|
||||
|
||||
created += 1
|
||||
acc_receivable.update_property_ids()
|
||||
|
||||
return {
|
||||
'type': 'ir.actions.client',
|
||||
'tag': 'display_notification',
|
||||
'params': {
|
||||
'title': '违约金生成完成',
|
||||
'message': f'已生成 {created} 条违约金,跳过重复 {skipped} 条',
|
||||
'type': 'success',
|
||||
'sticky': True,
|
||||
},
|
||||
}
|
||||
receivable._compute_is_overdue()
|
||||
|
||||
@api.depends('contract_id')
|
||||
def _compute_property_name(self):
|
||||
|
||||
Reference in New Issue
Block a user