Merge pull request !3594 from 李鹏宇/dev
This commit is contained in:
李鹏宇
2025-06-30 09:50:28 +00:00
committed by Gitee
5 changed files with 90 additions and 7 deletions
@@ -44,6 +44,28 @@ class PropertyBankStatements(models.Model):
}
}
def unbind(self):
statements_ids = self.env["property.bank.statements"].browse(
self._context.get('active_ids', self._context.get('active_id'))
)
for statement in statements_ids:
bank_account = self.env['property.bank.line'].search([
('bank', '=', statement.name) # 假设statement.name存储银行账号
])
if bank_account.tenant_id:
# 获取需要删除的合同明细行
lines_to_delete = self.env['property.tenant.line'].search([
('tenant_id', '=', bank_account.tenant_id.id),
('lease_contract_id', 'in', statement.contract_ids.ids)
])
# 删除合同明细行
if lines_to_delete:
lines_to_delete.unlink()
statement.contract_ids = [(5,)]
statement.property_ids = [(5,)]
def button_bank_state(self):
receivable_ids = self.env["property.bank.statements"].browse(
self._context.get('active_ids', self._context.get('active_id')))
@@ -29,10 +29,21 @@ class PropertyTenantLine(models.Model):
tenant_id = fields.Many2one('property.tenant.information', string="关联租户信息")
property_ids = fields.Many2many('yuthon.property', string="物业信息")
lease_contract_id = fields.Many2one('property.lease.contract', string="合同编号")
rent = fields.Float(string="租金")
rent = fields.Float(related='lease_contract_id.rent', string="租金")
start_time = fields.Date(related='lease_contract_id.actual_start_time', string="生效日期")
end_date = fields.Date(related='lease_contract_id.actual_end_time',string="失效日期")
@api.model
def create(self, vals):
"""在创建记录时自动关联合同对应的物业"""
if vals.get('lease_contract_id'):
# 获取合同关联的物业明细行并直接提取物业ID列表
contract = self.env['property.lease.contract'].browse(vals['lease_contract_id'])
property_ids = contract.lease_ids.mapped('address_id.id')
if property_ids:
vals['property_ids'] = [(6, 0, property_ids)]
return super(PropertyTenantLine, self).create(vals)
class PropertyLeaseContract(models.Model):
_name = 'property.lease.contract'
_description = '租赁合同审批'
@@ -7,7 +7,7 @@
<field name="arch" type="xml">
<xpath expr="//page[@name='bank_ids']" position="after">
<page string="合同">
<field name="property_contract_ids">
<field name="property_contract_ids" create="false" edit="false" delete="false">
<tree editable="bottom">
<field name="tenant_id" column_invisible="1"/>
<field name="lease_contract_id"/>
@@ -589,6 +589,11 @@
<field name="model">property.bank.statements</field>
<field name="inherit_id" ref="yuthon_property.view_property_bank_statements_tree"/>
<field name="arch" type="xml">
<xpath expr="//tree" position="inside">
<header>
<button name="unbind" type="object" class="btn btn-primary" string="取消绑定"/>
</header>
</xpath>
<xpath expr="//field[@name='property_ids']" position="before">
<field name="contract_ids" string="合同编号" widget="many2many_tags" readonly="1"/>
</xpath>
@@ -8,21 +8,18 @@ class BindingInformationWizard(models.Model):
bank_id = fields.Many2one('property.bank.statements',string="银行")
property_ids = fields.Many2many('yuthon.property', string='物业')
contract_ids = fields.Many2many('property.lease.contract',string="租赁合同审批")
# 可用物业ID字段(显式指定关联表)
available_property_ids = fields.Many2many(
'yuthon.property',
'binding_information_wizard_available_property_rel', # 唯一表名
'binding_information_wizard_available_property_rel',
'wizard_id',
'property_id',
compute='_compute_available_records',
string='可用物业ID',
store=True
)
# 可用合同ID字段(显式指定关联表)
available_contract_ids = fields.Many2many(
'property.lease.contract',
'binding_information_wizard_available_contract_rel', # 唯一表名
'binding_information_wizard_available_contract_rel',
'wizard_id',
'contract_id',
compute='_compute_available_records',
@@ -30,6 +27,39 @@ class BindingInformationWizard(models.Model):
store = True
)
@api.onchange('property_ids')
def onchange_property_ids(self):
if not self.property_ids:
return
new_contract_ids = []
for property_id in self.property_ids:
# 获取物业关联的合同明细行
for line in property_id.property_contract_ids:
if line.lease_contract_id:
new_contract_ids.append(line.lease_contract_id.id)
# 过滤掉已选择的合同,避免重复
new_contract_ids = list(set(new_contract_ids) - set(self.contract_ids.ids))
if new_contract_ids:
self.contract_ids = [(4, contract_id) for contract_id in new_contract_ids]
@api.onchange('contract_ids')
def onchange_contract_ids(self):
if not self.contract_ids:
return
new_property_ids = []
for contract_id in self.contract_ids:
# 获取合同关联的物业明细行
for line in contract_id.lease_ids:
if line.address_id:
new_property_ids.append(line.address_id.id)
# 过滤掉已选择的物业,避免重复
new_property_ids = list(set(new_property_ids) - set(self.property_ids.ids))
# 追加新物业(使用操作码4)
if new_property_ids:
self.property_ids = [(4, property_id) for property_id in new_property_ids]
@api.onchange('bank_id')
def _onchange_bank_id(self):
"""计算可用的物业和合同ID"""
@@ -61,3 +91,18 @@ class BindingInformationWizard(models.Model):
bank_id.write({
'contract_ids': [(4, cont.id) for cont in new_contracts]
})
# 根据银行账号查找承租方信息
bank_account = self.env['property.bank.line'].search([
('bank', '=', self.bank_id.name)
])
if bank_account.tenant_id:
# 获取已存在的合同明细行的合同ID
existing_contract_ids = bank_account.tenant_id.property_contract_ids.mapped('lease_contract_id.id')
# 过滤出需要新增的合同(排除已存在的)
new_contracts = self.contract_ids.filtered(lambda c: c.id not in existing_contract_ids)
for contract in new_contracts:
self.env['property.tenant.line'].sudo().create({
'tenant_id': bank_account.tenant_id.id,
'lease_contract_id': contract.id,
})