diff --git a/yuthon_property_approval/models/inherit_yuthon_property.py b/yuthon_property_approval/models/inherit_yuthon_property.py index 90505cbce..8715d6092 100644 --- a/yuthon_property_approval/models/inherit_yuthon_property.py +++ b/yuthon_property_approval/models/inherit_yuthon_property.py @@ -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): diff --git a/yuthon_property_approval/wizard/binding_information_wizard.py b/yuthon_property_approval/wizard/binding_information_wizard.py index 2ff9d4ef1..54c6f6dab 100644 --- a/yuthon_property_approval/wizard/binding_information_wizard.py +++ b/yuthon_property_approval/wizard/binding_information_wizard.py @@ -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 \ No newline at end of file + 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] + }) diff --git a/yuthon_property_approval/wizard/binding_information_wizard_views.xml b/yuthon_property_approval/wizard/binding_information_wizard_views.xml index 5320c10a5..4b4461a27 100644 --- a/yuthon_property_approval/wizard/binding_information_wizard_views.xml +++ b/yuthon_property_approval/wizard/binding_information_wizard_views.xml @@ -7,8 +7,11 @@
- - + + + + +