添加功能
This commit is contained in:
@@ -39,6 +39,9 @@ class PropertyBankStatements(models.Model):
|
||||
'view_mode': 'form',
|
||||
'res_model': 'binding.information.wizard',
|
||||
'target': 'new',
|
||||
'context': {
|
||||
'default_bank_id': self.id,
|
||||
}
|
||||
}
|
||||
|
||||
def button_bank_state(self):
|
||||
|
||||
@@ -5,8 +5,59 @@ class BindingInformationWizard(models.Model):
|
||||
_name = 'binding.information.wizard'
|
||||
_description = '绑定信息弹窗'
|
||||
|
||||
bank_id = fields.Many2one('property.bank.statements',string="银行")
|
||||
property_ids = fields.Many2many('yuthon.property', string='物业')
|
||||
contract_ids = fields.Many2many('property.lease.contract', string="租赁合同审批")
|
||||
contract_ids = fields.Many2many('property.lease.contract',string="租赁合同审批")
|
||||
# 可用物业ID字段(显式指定关联表)
|
||||
available_property_ids = fields.Many2many(
|
||||
'yuthon.property',
|
||||
'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', # 唯一表名
|
||||
'wizard_id',
|
||||
'contract_id',
|
||||
compute='_compute_available_records',
|
||||
string='可用合同ID',
|
||||
store = True
|
||||
)
|
||||
|
||||
@api.onchange('bank_id')
|
||||
def _onchange_bank_id(self):
|
||||
"""计算可用的物业和合同ID"""
|
||||
for record in self:
|
||||
# 搜索未对账的应收记录
|
||||
unreconciled_records = self.env['property.accounts.receivable'].search([
|
||||
('is_reconciliation', '=', False)
|
||||
])
|
||||
# 提取物业和合同ID列表(去重)
|
||||
property_ids = list(set(record.property_id.id for record in unreconciled_records if record.property_id))
|
||||
contract_ids = list(set(record.contract_id.id for record in unreconciled_records if record.contract_id))
|
||||
|
||||
# 设置计算字段值
|
||||
record.available_property_ids = [(6, 0, property_ids)] if property_ids else [(5,)]
|
||||
record.available_contract_ids = [(6, 0, contract_ids)] if contract_ids else [(5,)]
|
||||
|
||||
def confirm(self):
|
||||
pass
|
||||
bank_ids = self.env['property.bank.statements'].search([('name', '=', self.bank_id.name)])
|
||||
for bank_id in bank_ids:
|
||||
if self.property_ids:
|
||||
new_properties = self.property_ids - bank_id.property_ids
|
||||
if new_properties:
|
||||
bank_id.write({
|
||||
'property_ids': [(4, prop.id) for prop in new_properties]
|
||||
})
|
||||
if self.contract_ids:
|
||||
new_contracts = self.contract_ids - bank_id.contract_ids
|
||||
if new_contracts:
|
||||
bank_id.write({
|
||||
'contract_ids': [(4, cont.id) for cont in new_contracts]
|
||||
})
|
||||
|
||||
@@ -7,8 +7,11 @@
|
||||
<form string="绑定信息">
|
||||
<sheet>
|
||||
<group>
|
||||
<field name="property_ids" widget="many2many_tags"/>
|
||||
<field name="contract_ids" widget="many2many_tags"/>
|
||||
<field name="bank_id" invisible="1"/>
|
||||
<field name="available_property_ids" widget="many2many_tags" invisible="1"/>
|
||||
<field name="available_contract_ids" widget="many2many_tags" invisible="1"/>
|
||||
<field name="property_ids" widget="many2many_tags" domain="[('id', 'in', available_property_ids)]"/>
|
||||
<field name="contract_ids" widget="many2many_tags" domain="[('id', 'in', available_contract_ids)]"/>
|
||||
</group>
|
||||
</sheet>
|
||||
<footer>
|
||||
|
||||
Reference in New Issue
Block a user