diff --git a/yuthon_property/models/yuthon_property.py b/yuthon_property/models/yuthon_property.py index e1e4f9448..7745d597f 100644 --- a/yuthon_property/models/yuthon_property.py +++ b/yuthon_property/models/yuthon_property.py @@ -59,7 +59,7 @@ class YuthonProperty(models.Model): suite_area = fields.Float(string="套内面积", digits=(16, 4)) purpose_id = fields.Many2one('yuthon.resource.purpose', string="管理类型", compute="compute_information_fields", store=True) admin_id = fields.Many2one('res.users', string="片区管理员", compute="compute_information_fields", store=True) - lessee_id = fields.Many2one('property.tenant.information', string='承租方') + lessee_id = fields.Many2one('property.tenant.information', string='承租方', compute="_compute_lessee_id") title_address = fields.Many2one('yuthon.property.message', string="产权地址", compute="_compute_title_information_fields", store=True) company_id = fields.Many2one('yuthon.property.company', string="公司", compute="compute_information_fields", store=True) rental_address = fields.Text(string="出租地址") diff --git a/yuthon_property_approval/models/inherit_yuthon_property.py b/yuthon_property_approval/models/inherit_yuthon_property.py index 46415a997..0031e9cdd 100644 --- a/yuthon_property_approval/models/inherit_yuthon_property.py +++ b/yuthon_property_approval/models/inherit_yuthon_property.py @@ -106,6 +106,18 @@ class YuthonProperty(models.Model): property_contract_ids = fields.One2many('property.contract.line', 'yuthon_property_id', string="关联物业合同明细行") + @api.depends('property_contract_ids') + def _compute_lessee_id(self): + today = date.today() + for record in self: + contract_lines = record.property_contract_ids + valid_lines = contract_lines.filtered( + lambda line: + line.start_time <= today and + (not line.end_date or line.end_date >= today) + ) + record.lessee_id = valid_lines[0].lessee_id if valid_lines else False + def get_yuthon_property_time(self): unique_property_ids = set() for record in self.search([('property_state', '=', 'to'), ('property_contract_ids', '=', False)]):