İçereği Atla
Menü
Bu soru işaretlendi

here is a code i am using in the scheduled action this code run perfectly if i run this manually but it didnot work every min.

i am accessing the  mrp.production this module in the selection

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',

​ })


image of my settings​

https://drive.google.com/file/d/1Lh1XkGNDKr7WHBNM4ttE6NnqNk6bKx37/view?usp=sharing

Avatar
Vazgeç
En İyi Yanıt

Hi krakalien,

why are you using Scheduled Action? Why not Automated Action, if it's going to have impact on all confirmed or to_close manufactured orders?

check this out:


BG,

Hamid - bitigloo GmbH

Avatar
Vazgeç
Üretici

i used this method but it did not give any output nor error.

it's weird, because I tested it in different scenarios before posting it, and again now, it's working for me. To be on the safe side, make sure your scheduled action is not active, when you are doing this.

Üretici

thanks its working for me as well i didn't see before you removed the first line of code.

En İyi Yanıt

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


Avatar
Vazgeç
Üretici

thank you but i cant access the backend code so cant write the xml code or .py code in the backend i am just using frontend to do this task.

En İyi Yanıt

I did this in V14. I wanted an automated action, but was not able to make it work.   SO I ended up witj a scheduled action running every 1 minute.

When you process 'Mark as Done', Odoo perform several actions in the background (as posting stock movements) as well as check that all is OK in the manufacturing order.  

The little pyhton code I have that calls the method is:

model.search([('state', '=', 'to_close')]).button_mark_done()

And it runs on Model production order (of course). 

Avatar
Vazgeç

Hi Lars, the action of the button will not work when you need to force the consumption of the components, because in the standard way, in this case, Odoo will show a wizard to the user. I don' remember if we had the wizard in Odoo14 or not, but in the later versions, you can also check.

As far as I can read from your code, you fill the consumed and produced qty = to planned. If you keep that part of the code and then runnteh action "button_mark_done" you should be able to process without raising the warning. But still keep tha checks Odoo have in this action.

İlgili Gönderiler Cevaplar Görünümler Aktivite
3
Eki 23
2732
1
Oca 23
2290
1
Ağu 23
2607
1
Ağu 23
3356
1
Mar 23
2328