Run Odoo with shell command and execute below script
python3 /opt/odoo14/odoo/odoo-bin shell -c /opt/odoo14/conf/odoo14-server.conf -d production_migrated
self.env['ir.module.module'].update_list()
self._cr.commit()
module_list = ['advance_purchase_ordering_ept', 'agro-odoo-shopify', 'hr_attendance_print', 'intercompany_transaction_ept', 'inventory_coverage_report_ept', 'l10n_mx_edi_bank', 'l10n_mx_edi_landing_marvelsa', 'l10n_mx_edi_reports', 'l10n_mx_edi_transfer', 'mandrake-master', 'merge_purchase_order',]
self.env['ir.module.module'].search([('state','=','installed'),('name','in',module_list )]).button_immediate_uninstall();
0
To upgrade
self.env['ir.module.module'].search([('name','=','setu_access_rights')]).button_immediate_upgrade();