fix: Correct active template handling in create method to ensure proper activation logic

This commit is contained in:
Altahir Hassan 2026-01-06 10:26:41 +04:00
parent bc4a5b32dd
commit 8828bc7308
1 changed files with 4 additions and 5 deletions

View File

@ -111,14 +111,13 @@ class ExpertLoginTemplate(models.Model):
def create(self, vals):
"""Ensure only one template is active at a time"""
# If no active value is set, default to False (don't auto-activate new templates)
if 'active' not in vals[0]:
vals[0]['active'] = False
if 'active' not in vals:
vals['active'] = False
# Only deactivate others if this one is being set to active
print(vals[0])
if vals[0].get('active'):
if vals.get('active'):
# Deactivate all other templates (excluding the one being created)
self.search([('active', '=', True)]).write({'active': False})
return super(ExpertLoginTemplate, self).create(vals[0])
return super(ExpertLoginTemplate, self).create(vals)
def write(self, vals):
"""Ensure only one template is active at a time"""