diff --git a/yuthon_property_approval/models/property_lease_renewal.py b/yuthon_property_approval/models/property_lease_renewal.py
index 976a342c4..cc7dbc98f 100644
--- a/yuthon_property_approval/models/property_lease_renewal.py
+++ b/yuthon_property_approval/models/property_lease_renewal.py
@@ -63,11 +63,9 @@ class PropertyLeaseRenewal(models.Model):
deposit = fields.Float(string="原押金")
is_full_refund = fields.Boolean(string="是否全额退押", default=True)
refund_amount = fields.Float(string="退款金额")
- refund_remake = fields.Char(string="备注")
+ deposit_treatment = fields.Selection([('refund', '全额退押'), ('part_refund', '部分退租'), ('no_refund', '全额没收')], string="押金处理方式", default='refund')
total_receivables = fields.Float(string="应收金额", compute="_compute_total_receivables")
- total_remake = fields.Char(string="备注")
- balance = fields.Float(string="金额")
- balance_remake = fields.Char(string="备注")
+ forfeit = fields.Float(string="没收金额")
receivables_ids = fields.One2many('early.receivables.line', 'renewal_id', string='应收明细')
@@ -95,8 +93,10 @@ class PropertyLeaseRenewal(models.Model):
# 需求调整:不做自动填充,保留用户手动输入的联系人
return
-
-
+ @api.onchange('refund_amount')
+ def _onchange_forfeit(self):
+ for rec in self:
+ rec.forfeit = rec.deposit - rec.refund_amount
@api.onchange('contact')
def _onchange_contact_fill_info(self):
@@ -214,73 +214,79 @@ class PropertyLeaseRenewal(models.Model):
elif lessor_id.referred in ['天河粮储']:
company_id = self.env['res.company'].search([('name', '=', '天河粮储')], limit=1)
- if not rec.is_full_refund:
- penalty_amount = rec.deposit - rec.refund_amount - rec.total_receivables
- if penalty_amount > 0:
- management_type_id = self.env['yuthon.management.type'].search([
- ('name', '=', '违约金')
- ], limit=1)
- exist_receivable = self.env['property.accounts.receivable'].search([
- ('contract_id', '=', rec.contract_id.id),
- ('management_type_id', '=', management_type_id.id),
- ('due_date', '=', rec.early_quitting_date),
- ('original_amount', '=', penalty_amount),
- ], limit=1)
- if not exist_receivable:
- self.env['property.accounts.receivable'].create({
- 'contract_id': rec.contract_id.id,
- 'management_type_id': management_type_id.id,
- 'due_date': rec.early_quitting_date,
- 'original_amount': penalty_amount,
- 'remark': rec.total_remake,
- })
- deposit_id = self.env['property.accounts.receivable'].search([
- ('contract_id', '=', rec.contract_id.id),
- ('management_type_id.name', '=', '押金'),
- ], limit=1)
- if deposit_id:
- deposit_id.write({
- 'workflow_record_id': workflow_record_id.id
- })
+ # 取本审批最后一条流程日志的操作时间,作为账单 due_date
+ operation_log = self.env['soong.workflow.log'].search([
+ ('model', '=', self._name),
+ ('res_id', '=', rec.id),
+ ], order='lase_click_date DESC, id DESC', limit=1)
+ operation_date = operation_log.lase_click_date.date() if operation_log.lase_click_date else fields.Date.today()
+ # 非押金退款明细(除押金外的退款,原逻辑保留)
if rec.receivables_ids:
refund_lines = rec.receivables_ids.filtered(lambda l: l.refund_amount > 0 and l.management_type_id.name != '押金')
bills_line_list = []
- # 除押金的明细
if refund_lines:
for refund_line in refund_lines:
bills_line_list.append({
'lessor_id': rec.contract_id.lessor_id.id,
- 'due_date': fields.Date.today(),
+ 'due_date': operation_date,
'management_type_id': refund_line.management_type_id.id,
'amount': refund_line.refund_amount,
'contract_id': rec.contract_id.id,
'receivables_id': refund_line.id,
'remake': rec.refund_remake
})
- # 押金
- deposit_management_type = self.env['yuthon.management.type'].search(
- [('name', '=', '押金')],
- limit=1
- )
- deposit_amount = rec.deposit if rec.is_full_refund else rec.refund_amount
- if deposit_amount > 0:
- bills_line_list.append({
- 'lessor_id': rec.contract_id.lessor_id.id,
- 'due_date': fields.Date.today(),
- 'management_type_id': deposit_management_type.id,
- 'amount': deposit_amount,
- 'contract_id': rec.contract_id.id,
- 'remake': '押转租/没收押金',
- 'workflow_record_id': workflow_record_id.id,
- })
+ if bills_line_list:
+ self.env['property.bills.list'].create(bills_line_list)
- if not rec.is_full_refund:
- balance = rec.deposit - rec.refund_amount
+ # 押金处理(根据押金处理方式分三种,先判断去重再创建)
+ deposit_management_type = self.env['yuthon.management.type'].search(
+ [('name', '=', '押金')], limit=1)
+
+ if rec.deposit_treatment == 'refund':
+ # 全额退押金:仅创建 bills.list,金额 = 原押金 deposit
+ if rec.deposit > 0:
+ exist_bill = self.env['property.bills.list'].search([
+ ('contract_id', '=', rec.contract_id.id),
+ ('management_type_id', '=', deposit_management_type.id),
+ ('amount', '=', rec.deposit),
+ ('workflow_record_id', '=', workflow_record_id.id),
+ ], limit=1)
+ if not exist_bill:
+ self.env['property.bills.list'].create({
+ 'lessor_id': rec.contract_id.lessor_id.id,
+ 'due_date': operation_date,
+ 'management_type_id': deposit_management_type.id,
+ 'amount': rec.deposit,
+ 'contract_id': rec.contract_id.id,
+ 'remake': '押转租/没收押金',
+ 'workflow_record_id': workflow_record_id.id,
+ })
+
+ elif rec.deposit_treatment == 'part_refund':
+ # 部分退租:bills.list 金额 = refund_amount;bank.statements 和 receivable 金额 = forfeit
+ if rec.refund_amount > 0:
+ exist_bill = self.env['property.bills.list'].search([
+ ('contract_id', '=', rec.contract_id.id),
+ ('management_type_id', '=', deposit_management_type.id),
+ ('amount', '=', rec.refund_amount),
+ ('workflow_record_id', '=', workflow_record_id.id),
+ ], limit=1)
+ if not exist_bill:
+ self.env['property.bills.list'].create({
+ 'lessor_id': rec.contract_id.lessor_id.id,
+ 'due_date': operation_date,
+ 'management_type_id': deposit_management_type.id,
+ 'amount': rec.refund_amount,
+ 'contract_id': rec.contract_id.id,
+ 'remake': '押转租/没收押金',
+ 'workflow_record_id': workflow_record_id.id,
+ })
+ if rec.forfeit > 0:
start_time = datetime.combine(rec.early_quitting_date, datetime.min.time().replace(hour=8, minute=00))
existing_bank_statement = self.env['property.bank.statements'].sudo().search([
('start_time', '=', start_time),
- ('original_amount', '=', balance),
+ ('original_amount', '=', rec.forfeit),
('name_account', '=', rec.lessee_id.name),
('remake', '=', '押转租/没收押金'),
('workflow_record_id', '=', workflow_record_id.id),
@@ -296,7 +302,7 @@ class PropertyLeaseRenewal(models.Model):
bank_id = self.env['property.bank.statements'].sudo().create({
'start_time': start_time,
'name': bank_accounts,
- 'original_amount': balance,
+ 'original_amount': rec.forfeit,
'name_account': rec.lessee_id.name,
'remake': '押转租/没收押金',
'lending_direction': 'loan',
@@ -307,20 +313,110 @@ class PropertyLeaseRenewal(models.Model):
})
bank_id._compute_property_employee_id()
- # 创建应付账单
- if bills_line_list:
- self.env['property.bills.list'].create(bills_line_list)
+ management_type_id = self.env['yuthon.management.type'].search([
+ ('name', '=', '违约金')
+ ], limit=1)
+ exist_receivable = self.env['property.accounts.receivable'].search([
+ ('contract_id', '=', rec.contract_id.id),
+ ('management_type_id', '=', management_type_id.id),
+ ('due_date', '=', rec.early_quitting_date),
+ ('original_amount', '=', rec.forfeit),
+ ], limit=1)
+ if not exist_receivable:
+ self.env['property.accounts.receivable'].create({
+ 'contract_id': rec.contract_id.id,
+ 'management_type_id': management_type_id.id,
+ 'due_date': rec.early_quitting_date,
+ 'original_amount': rec.forfeit,
+ 'remark': rec.early_explain,
+ })
+ deposit_id = self.env['property.accounts.receivable'].search([
+ ('contract_id', '=', rec.contract_id.id),
+ ('management_type_id.name', '=', '押金'),
+ ], limit=1)
+ if deposit_id:
+ deposit_id.write({
+ 'workflow_record_id': workflow_record_id.id
+ })
+
+ elif rec.deposit_treatment == 'no_refund':
+ # 全额没收:bills.list、bank.statements、receivable 金额均为 deposit
+ if rec.deposit > 0:
+ exist_bill = self.env['property.bills.list'].search([
+ ('contract_id', '=', rec.contract_id.id),
+ ('management_type_id', '=', deposit_management_type.id),
+ ('amount', '=', rec.deposit),
+ ('workflow_record_id', '=', workflow_record_id.id),
+ ], limit=1)
+ if not exist_bill:
+ self.env['property.bills.list'].create({
+ 'lessor_id': rec.contract_id.lessor_id.id,
+ 'due_date': operation_date,
+ 'management_type_id': deposit_management_type.id,
+ 'amount': rec.deposit,
+ 'contract_id': rec.contract_id.id,
+ 'remake': '押转租/没收押金',
+ 'workflow_record_id': workflow_record_id.id,
+ })
+
+ start_time = datetime.combine(rec.early_quitting_date, datetime.min.time().replace(hour=8, minute=00))
+ existing_bank_statement = self.env['property.bank.statements'].sudo().search([
+ ('start_time', '=', start_time),
+ ('original_amount', '=', rec.deposit),
+ ('name_account', '=', rec.lessee_id.name),
+ ('remake', '=', '押转租/没收押金'),
+ ('workflow_record_id', '=', workflow_record_id.id),
+ ], limit=1)
+ if not existing_bank_statement:
+ bank_accounts = self.env['property.bank.line'].search([
+ ('tenant_id', '=', rec.lessee_id.id)
+ ]).mapped('bank')
+ bank_accounts = [acc for acc in bank_accounts if acc][0]
+ rec.contract_id.write({
+ 'actual_end_time': rec.early_quitting_date
+ })
+ bank_id = self.env['property.bank.statements'].sudo().create({
+ 'start_time': start_time,
+ 'name': bank_accounts,
+ 'original_amount': rec.deposit,
+ 'name_account': rec.lessee_id.name,
+ 'remake': '押转租/没收押金',
+ 'lending_direction': 'loan',
+ 'workflow_record_id': workflow_record_id.id,
+ 'company_id': company_id.id,
+ 'your_own_unit': lessor_id.referred,
+ 'your_own_account': lessor_id.rent_account,
+ })
+ bank_id._compute_property_employee_id()
+
+ management_type_id = self.env['yuthon.management.type'].search([
+ ('name', '=', '违约金')
+ ], limit=1)
+ exist_receivable = self.env['property.accounts.receivable'].search([
+ ('contract_id', '=', rec.contract_id.id),
+ ('management_type_id', '=', management_type_id.id),
+ ('due_date', '=', rec.early_quitting_date),
+ ('original_amount', '=', rec.deposit),
+ ], limit=1)
+ if not exist_receivable:
+ self.env['property.accounts.receivable'].create({
+ 'contract_id': rec.contract_id.id,
+ 'management_type_id': management_type_id.id,
+ 'due_date': rec.early_quitting_date,
+ 'original_amount': rec.deposit,
+ 'remark': rec.early_explain,
+ })
# 原有作废/减免逻辑保留
for receivable_id in rec.receivables_ids:
if receivable_id.void:
receivable_id.receivable_id.write({
'is_invalid': True,
- 'void_date': fields.Date.today()
+ 'void_date': operation_date
})
if receivable_id.reduction_amount:
receivable_id.receivable_id.discount_amount = receivable_id.reduction_amount
- receivable_id.receivable_id.discount_date = fields.Date.today()
+ receivable_id.receivable_id.discount_date = operation_date
@api.onchange('early_quitting_date', 'contract_id')
def _onchange_early_quitting_date(self):
diff --git a/yuthon_property_approval/views/property_lease_renewal.xml b/yuthon_property_approval/views/property_lease_renewal.xml
index 15f8c280e..fed95b26d 100644
--- a/yuthon_property_approval/views/property_lease_renewal.xml
+++ b/yuthon_property_approval/views/property_lease_renewal.xml
@@ -91,26 +91,28 @@
-
+
-
-
-
+
-
+
+
+
+
+
-
+
@@ -118,7 +120,6 @@
-