From b63e092c565d1e5bb837337f08c194ba7428f360 Mon Sep 17 00:00:00 2001 From: zainab8585 Date: Mon, 7 Oct 2024 12:49:42 +0200 Subject: [PATCH] [UPDATE]UPDATE floor base on count --- .../real_estate/models/internal_property.py | 24 ++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/odex25_realstate/real_estate/models/internal_property.py b/odex25_realstate/real_estate/models/internal_property.py index 1dd5d8d72..d95281299 100644 --- a/odex25_realstate/real_estate/models/internal_property.py +++ b/odex25_realstate/real_estate/models/internal_property.py @@ -67,7 +67,29 @@ class Property(models.Model): # res['arch'] = etree.tostring(doc, encoding='unicode') # return res - + @api.onchange('floors_count') + def _onchange_no_of_floor(self): + if self.floors_count>0: + # Clear existing lines + self.floor_ids = [(5, 0, 0)] + # Create floor records based on the number of floors + floors = [] + for i in range(1, self.floors_count + 1): + + floor_name = _('Floor') + ' ' + str(i) # Construct the floor name + + # Search for the role with the given floor name + role_record = self.env['property.role'].search([('name', '=', floor_name)], limit=1) + + if not role_record: + # If not found, create a new role with the corresponding name + role_record = self.env['property.role'].create({ + 'name': floor_name, + }) + # Append the record to One2many field + floors.append((0, 0, {'role_id': role_record.id})) + self.floor_ids = floors + def _compute_maintenance_count(self): for record in self: record.maintenance_count = self.env['property.management.maintenance'].search_count([