[UPDATE]UPDATE floor base on count

This commit is contained in:
zainab8585 2024-10-07 12:49:42 +02:00
parent 57ab6d8849
commit b63e092c56
1 changed files with 23 additions and 1 deletions

View File

@ -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([