
print("--- RESOLVING HOMEPAGE ---")
try:
    website = env['website'].get_current_website()
    print(f"Current Website: {website.name} (ID: {website.id})")
    
    # Resolve the view as Odoo does during rendering
    resolved_view = website.viewref('website.homepage')
    print(f"Resolved Homepage View: {resolved_view.name} (ID: {resolved_view.id}, Key: {resolved_view.key})")
    print(f" - Website ID of View: {resolved_view.website_id.id}")
    
    generic_view = env.ref('website.homepage')
    print(f"Generic View ID: {generic_view.id}")
    
    if resolved_view.id != generic_view.id:
        print("!!! ALERT: Output resolves to a DIFFERENT view than the generic one. !!!")
        print("This is a COW view masking your theme.")
        print("Archiving this masking view now...")
        resolved_view.write({'active': False, 'key': resolved_view.key + '.archived'})
        print(" -> Archived masking view.")
    else:
        print("Resolved view IS the generic view.")
        
    env.cr.commit()
    print("--- CHECK COMPLETE ---")
except Exception as e:
    print(f"Error: {e}")
