I am trying to call an action server from a menu, but it is not working for me, it is in Odoo 15
model="ir.actions.server" id="df_action_remove_draf_orders">
name="name">Remove Draf Orders
name="model_id" ref="model_df_maintenance_work_order"/>
name="type">ir.actions.server
name="state">code
name="code">
if records:
action = model.action_remove_draf_orders()
#--Function PY
def action_remove_draf_orders(self):
for record in self:
if record.state == 'draf':
record.unlink()
id="menu_maintenance_remove_order" name="Remove orders in draft state"
parent="maintenance.menu_maintenance_configuration" action="df_action_remove_draf_orders"
groups="maintenance.group_equipment_manager" sequence="6"/>
I think your code would work in a list view button. It check if there are records then for each reacord if state='draft' it would remove it. To use it, put a button on the header of the list view, select the records to work on and click the button.
Since you want to call it from a menu which I believe will not have a set of records. I think you should change your code:
ir.action code: action=model.action_remove_draft_orders()
action_remove_draft_order:
records=self.env['df.maintanance_work_order'].search([('state','==','draft')])
for record in records:
record.unlink()