From 3923b6b74d2cdc3d010d7d0b638ca53e157765a5 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: Sat, 27 Sep 2025 18:33:12 +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/contract_accounts_receivable.py | 25 +++++++++-
.../models/inherit_yuthon_property.py | 49 +++++++++++++++++--
.../contract_accounts_receivable_viwes.xml | 5 +-
.../views/inherit_yuthon_property_views.xml | 2 +-
4 files changed, 72 insertions(+), 9 deletions(-)
diff --git a/yuthon_property_approval/models/contract_accounts_receivable.py b/yuthon_property_approval/models/contract_accounts_receivable.py
index 3b57925af..bc8c22b1d 100644
--- a/yuthon_property_approval/models/contract_accounts_receivable.py
+++ b/yuthon_property_approval/models/contract_accounts_receivable.py
@@ -7,8 +7,8 @@ class ContractAccountsReceivable(models.Model):
_description = '应收账单(合同)'
contract_id = fields.Many2one('property.lease.contract', string="合同")
- lessee_id = fields.Many2one('property.tenant.information', string='承租方')
- property_ids = fields.Many2many('yuthon.property', string='物业')
+ lessee_id = fields.Many2one(related="contract_id.lessee_id", string='承租方')
+ property_name = fields.Char(related="contract_id.property_name", string='物业信息')
contract_accounts_ids = fields.One2many('property.accounts.receivable', 'contract_accounts_id', string='关联应收账单')
json_display = fields.Char(
@@ -17,6 +17,27 @@ class ContractAccountsReceivable(models.Model):
store=True
)
+ @api.onchange('contract_id')
+ def onchange_contract_id(self):
+ accounts = self.env['property.accounts.receivable'].search([('contract_id', '=', self.contract_id.id)])
+ receivable_list = []
+ for account in accounts:
+ receivable_list.append([0, 0, {
+ 'contract_accounts_id': account.id,
+ 'management_type_id': account.management_type_id.id,
+ 'last_month_table': account.last_month_table,
+ 'this_month_table': account.this_month_table,
+ 'ratio': account.ratio,
+ 'billable_quantity': account.billable_quantity,
+ 'due_date': account.due_date,
+ 'due_date_end': account.due_date_end,
+ 'original_amount': account.original_amount,
+ 'pre_collection': account.pre_collection,
+ 'remark': account.remark,
+ }])
+ self.contract_accounts_ids = receivable_list
+
+
@api.depends(
'contract_accounts_ids.management_type_id',
'contract_accounts_ids.last_month_table',
diff --git a/yuthon_property_approval/models/inherit_yuthon_property.py b/yuthon_property_approval/models/inherit_yuthon_property.py
index 2a5ea2685..c680f244f 100644
--- a/yuthon_property_approval/models/inherit_yuthon_property.py
+++ b/yuthon_property_approval/models/inherit_yuthon_property.py
@@ -394,14 +394,55 @@ class PropertyAccountsReceivable(models.Model):
billable_quantity = fields.Float(string="计费数量")
pre_collection = fields.Float(string="预收金额")
- actual_coping = fields.Float(string="实际应付")
+ actual_coping = fields.Float(string="实际应付", compute='_compute_actual_coping', store=True)
+
+ @api.depends('original_amount', 'pre_collection')
+ def _compute_actual_coping(self):
+ for record in self:
+ if record.original_amount:
+ record.actual_coping = record.original_amount - record.pre_collection
+ else:
+ record.actual_coping = 0
def update_lessee_id(self):
+ # 1. 获取选中的应收账单记录
accounts_ids = self.env["property.accounts.receivable"].browse(
- self._context.get('active_ids', self._context.get('active_id')))
- for rec in accounts_ids:
- rec.lessee_id = rec.contract_id.lessee_id
+ self._context.get('active_ids', self._context.get('active_id'))
+ )
+ if not accounts_ids:
+ return
+ unique_contracts = {
+ account.contract_id for account in accounts_ids
+ if account.contract_id
+ }
+ for contract in unique_contracts:
+ contract_account = self.env['contract.accounts.receivable'].search([
+ ('contract_id', '=', contract.id)
+ ], limit=1)
+ if not contract_account:
+ contract_account = self.env['contract.accounts.receivable'].create({
+ 'contract_id': contract.id,
+ })
+ contract_account.onchange_contract_id()
+ @api.model_create_multi
+ def create(self, vals_list):
+ contract_account_map = {}
+ for vals in vals_list:
+ if 'contract_id' in vals and vals['contract_id']:
+ contract_id = vals['contract_id']
+ if contract_id not in contract_account_map:
+ contract_account = self.env['contract.accounts.receivable'].search([
+ ('contract_id', '=', contract_id)
+ ], limit=1)
+ if not contract_account:
+ contract_account = self.env['contract.accounts.receivable'].create({
+ 'contract_id': contract_id
+ })
+ else:
+ contract_account.onchange_contract_id()
+
+ contract_account.onchange_contract_id()
@api.depends('management_type_id')
def _compute_is_rent(self):
diff --git a/yuthon_property_approval/views/contract_accounts_receivable_viwes.xml b/yuthon_property_approval/views/contract_accounts_receivable_viwes.xml
index c8f38ed13..801af495e 100644
--- a/yuthon_property_approval/views/contract_accounts_receivable_viwes.xml
+++ b/yuthon_property_approval/views/contract_accounts_receivable_viwes.xml
@@ -7,7 +7,7 @@
-
+
@@ -21,7 +21,7 @@
-
+
@@ -37,6 +37,7 @@
+
diff --git a/yuthon_property_approval/views/inherit_yuthon_property_views.xml b/yuthon_property_approval/views/inherit_yuthon_property_views.xml
index 21c07f4a8..13ca4e6fe 100644
--- a/yuthon_property_approval/views/inherit_yuthon_property_views.xml
+++ b/yuthon_property_approval/views/inherit_yuthon_property_views.xml
@@ -285,7 +285,7 @@