Mark as lost
list
code
if not 'opportunity' in records.mapped('type'):
records.action_set_lost()
elif records:
action_values = env.ref('crm.crm_lead_lost_action').sudo().read()[0]
action_values.update({'context': env.context})
action = action_values
Crm: My Pipeline
code
action = model.action_your_pipeline()
Crm: Forecast
code
action = model.action_opportunity_forecast()