Hi,
To run the scheduled action for every minute you can create an XML file
to define the scheduled action. In this XML file, you'll specify the
model, method, and cron expression for the scheduled action. For
example,
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<data>
<!-- Scheduled Action Definition -->
<record id="ir_cron_send_email" model="ir.cron">
<field name="name">Send Email Every Minute</field>
<field name="model_id" ref="model_mrp_production"/>
<field name="state">code</field>
<field name="code">model.automate_mrp_order()</field>
<field name="interval_number">1</field>
<field name="interval_type">minutes</field>
<field name="numbercall">-1</field>
<field name="doall" eval="False"/>
<field name="active" eval="True"/>
</record>
</data>
</odoo>
In this XML file, we define an ir.cron record with the necessary details for the scheduled action. It specifies the model (model_mrp_production), the Python method (model.automate_mrp_order()), and that it should run every minute (interval_number and interval_type).
And inside the python method you can define your code
def automate_mrp_order(self):
orders = env['mrp.production'].search([('state', 'in', ['confirmed', 'to_close'])])
for order in orders:
order.write({
'qty_producing': order.product_qty,
})
move_lines = order.move_raw_ids
for move in move_lines:
move.write({
'quantity_done': move.product_uom_qty,
})
order.write({
'state': 'done',
})
Refer this below blog to know more details about how to create a scheduled action
Scheduled Action
Hope it helps