From 90f8b5ee18596876f4d7e4630291db5e637842db 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, 27 Nov 2025 18:32:35 +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 --- .../models/inherit_yuthon_property.py | 5 +- .../models/property_lease_contract.py | 1 + .../models/property_lease_renewal.py | 118 +++++++++++------- ...contract_accounts_receivable_templates.xml | 24 ++-- .../views/property_lease_renewal.xml | 6 +- .../models/yuthon_business_approval.py | 1 + .../views/yuthon_business_approval_viwes.xml | 1 + 7 files changed, 100 insertions(+), 56 deletions(-) diff --git a/yuthon_property_approval/models/inherit_yuthon_property.py b/yuthon_property_approval/models/inherit_yuthon_property.py index 2ef2ce00f..f40d62cea 100644 --- a/yuthon_property_approval/models/inherit_yuthon_property.py +++ b/yuthon_property_approval/models/inherit_yuthon_property.py @@ -1230,7 +1230,10 @@ class PropertyManagementList(models.Model): theoretical_end = date(due_date_obj.year, due_date_obj.month, last_day) if contract_actual_end: - due_date_end = fields.Date.to_string(min(theoretical_end, contract_actual_end)) + if theoretical_end: + due_date_end = fields.Date.to_string(min(theoretical_end, contract_actual_end)) + else: + due_date_end = fields.Date.to_string(contract_actual_end) else: due_date_end = fields.Date.to_string(theoretical_end) diff --git a/yuthon_property_approval/models/property_lease_contract.py b/yuthon_property_approval/models/property_lease_contract.py index 635e31d44..4878a6f78 100644 --- a/yuthon_property_approval/models/property_lease_contract.py +++ b/yuthon_property_approval/models/property_lease_contract.py @@ -109,6 +109,7 @@ class PropertyLeaseContract(models.Model): ) title_address = fields.Char(string="产权地址") receivable_ids = fields.One2many('property.accounts.receivable', 'contract_id', string="应收账单") + receivable_report_ids = fields.Many2many('property.accounts.receivable', string="应收账单(报表)") payment_ids = fields.One2many('property.payment.notice', 'contract_id', string="合同打印") handling_opinions = fields.Text(string="经办意见") lessor_id = fields.Many2one('yuthon.property.company', string="出租方公司") diff --git a/yuthon_property_approval/models/property_lease_renewal.py b/yuthon_property_approval/models/property_lease_renewal.py index bd4ed099d..53736898a 100644 --- a/yuthon_property_approval/models/property_lease_renewal.py +++ b/yuthon_property_approval/models/property_lease_renewal.py @@ -56,21 +56,19 @@ class PropertyLeaseRenewal(models.Model): active = fields.Boolean('Active', default=True, tracking=True) work_end = fields.Boolean(string="结束") - full_refund = fields.Boolean(string="全额退还", compute="_compute_full_refund") + deposit = fields.Float(string="押金") + is_full_refund = fields.Boolean(string="是否全额退押", default=True) + refund_amount = fields.Float(string="退款金额") + balance = fields.Float(string="余额") + remake = fields.Text(string="备注") receivables_ids = fields.One2many('early.receivables.line', 'renewal_id', string='应收明细') bills_record_id = fields.Many2one('property.bills.payable', string='应付账单流程') - @api.depends('receivables_ids.original_amount') - def _compute_full_refund(self): - for record in self: - deposit_line = record.receivables_ids.filtered( - lambda l: l.management_type_id.name == '押金' - )[:1] - if deposit_line: - record.full_refund = deposit_line.original_amount - else: - record.full_refund = False + @api.onchange('refund_amount') + def _onchange_refund_amount(self): + for rec in self: + rec.balance = rec.deposit - rec.refund_amount def end_approval(self): for rec in self: @@ -181,49 +179,72 @@ class PropertyLeaseRenewal(models.Model): 'actual_end_time': rec.early_quitting_date }) rec.contract_id.get_property_contract_time() - rec.hide = True if rec.receivables_ids: refund_lines = rec.receivables_ids.filtered(lambda l: l.refund_amount > 0) + bills_line_list = [] + soong_workflow_line_list = [] if refund_lines: - bills_line_list = [] - soong_workflow_line_list = [] for refund_line in refund_lines: bills_line_list.append((0, 0, { 'due_date': fields.Date.today(), 'management_type_id': refund_line.management_type_id.id, 'original_amount': refund_line.refund_amount, })) - bills_payable = self.env['property.bills.payable'].create({ - 'lease_contract_id': rec.contract_id.id, - 'name': f'{rec.contract_id.contract_code}应付单', - 'create_uid': self.env.uid, - 'bills_line_ids': bills_line_list + + if rec.is_full_refund: + 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((0, 0, { + 'due_date': fields.Date.today(), + 'management_type_id': deposit_management_type.id, + 'original_amount': deposit_amount, + })) + + bills_payable = self.env['property.bills.payable'].create({ + 'lease_contract_id': rec.contract_id.id, + 'name': f'{rec.contract_id.contract_code}应付单', + 'create_uid': self.env.uid, + 'bills_line_ids': bills_line_list + }) + + if not rec.is_full_refund: + start_time = datetime.combine(rec.early_quitting_date, datetime.min.time().replace(hour=8, minute=00)) + self.env['property.bank.statements'].create({ + 'start_time': start_time, + 'original_amount': rec.balance, + 'name_account': rec.new_lessee_id.name, + 'remake': f'合同为{rec.contract_id.contract_code}提前退押金', }) - workflow_record_id = self.env['soong.workflow.record'].search([ - ('code', '=', self.code), - ]) - soong_workflow_line_list.append((0, 0, { - 'model': 'property.bills.payable', - 'res_id': bills_payable.id, - 'workflow_record_id': workflow_record_id.id - })) - self.bills_record_id = bills_payable.id - bills_payable.soong_record_ids = soong_workflow_line_list - soong_record = self.env["soong.workflow.record"].search([("code", "=", bills_payable.code)]) - if soong_record: - self.workflow_record_id = soong_record.id + workflow_record_id = self.env['soong.workflow.record'].search([ + ('code', '=', self.code), + ]) + soong_workflow_line_list.append((0, 0, { + 'model': 'property.bills.payable', + 'res_id': bills_payable.id, + 'workflow_record_id': workflow_record_id.id + })) + self.bills_record_id = bills_payable.id + bills_payable.soong_record_ids = soong_workflow_line_list - # 原有作废/减免逻辑保留 - for receivable_id in rec.receivables_ids: - if receivable_id.void: - receivable_id.receivable_id.write({ - 'is_void': True, - 'void_date': fields.Date.today() - }) - if receivable_id.reduction_amount: - receivable_id.receivable_id.reduction_amount = receivable_id.reduction_amount - receivable_id.receivable_id.discount_date = fields.Date.today() + soong_record = self.env["soong.workflow.record"].search([("code", "=", bills_payable.code)]) + if soong_record: + self.workflow_record_id = soong_record.id + + # 原有作废/减免逻辑保留 + for receivable_id in rec.receivables_ids: + if receivable_id.void: + receivable_id.receivable_id.write({ + 'is_void': True, + 'void_date': fields.Date.today() + }) + if receivable_id.reduction_amount: + receivable_id.receivable_id.reduction_amount = receivable_id.reduction_amount + receivable_id.receivable_id.discount_date = fields.Date.today() @api.onchange('early_quitting_date', 'contract_id') def _onchange_early_quitting_date(self): @@ -235,8 +256,19 @@ class PropertyLeaseRenewal(models.Model): ('due_date', '<=', self.early_quitting_date), ('contract_id', '=', self.contract_id.id), ]) - receivable_list = [] + deposit_receivables = self.env['property.accounts.receivable'] + normal_receivables = self.env['property.accounts.receivable'] for rec in receivable_ids: + if rec.management_type_id and rec.management_type_id.name == '押金': + deposit_receivables |= rec + else: + normal_receivables |= rec + + if deposit_receivables: + self.deposit = sum(rec.original_amount for rec in deposit_receivables) + + receivable_list = [] + for rec in normal_receivables: receivable_list.append([0, 0, { 'receivable_id': rec.id, }]) diff --git a/yuthon_property_approval/report/contract_accounts_receivable_templates.xml b/yuthon_property_approval/report/contract_accounts_receivable_templates.xml index 0af14cd86..41c5e1e06 100644 --- a/yuthon_property_approval/report/contract_accounts_receivable_templates.xml +++ b/yuthon_property_approval/report/contract_accounts_receivable_templates.xml @@ -45,6 +45,7 @@