Files
2025-09-11 18:27:37 +08:00

48 lines
2.1 KiB
Python

from odoo import models, fields, api, _, SUPERUSER_ID
from odoo.exceptions import UserError, ValidationError
class BuildPopWizard(models.TransientModel):
_name = 'build.pop.wizard'
_description = '添加物业弹窗'
property_ids = fields.Many2many('yuthon.property', string='物业')
construction_id = fields.Many2one('property.construction.approval', string="关联建设工程造价咨询合同审批")
project_id = fields.Many2one('property.project.approval', string="关联工程立项")
design_id = fields.Many2one('property.design.approval', string="关联建设工程设计合同审批")
accounting_id = fields.Many2one('property.accounting.approval', string="关联建设工程委托监理合同审批")
supervising_id = fields.Many2one('property.supervising.approval', string="关联建设工程施工合同审批")
def confirm(self):
# 收集所有选中物业的地址
property_addresses = [
prop.name
for prop in self.property_ids
if prop.name
]
concatenated_address = ', '.join(property_addresses)
related_fields = [
('construction_id', 'construction_id'),
('project_id', 'project_id'),
('design_id', 'design_id'),
('accounting_id', 'accounting_id'),
('supervising_id', 'supervising_id')
]
for field, line_field in related_fields:
record = getattr(self, field)
if record:
if hasattr(record, 'property_address'):
record.write({'property_address': concatenated_address})
existing_lines = self.env['property.lease.contract.line'].search([
(line_field, '=', record.id)
])
if existing_lines:
existing_lines.unlink()
for prop in self.property_ids:
self.env['property.lease.contract.line'].create({
line_field: record.id,
'address_id': prop.id,
})