Skip to Content
मेन्यू
This question has been flagged
2 Replies
351 Views

Hi all!

I have multiple operators that utilize the shop floor app only, and sometimes they have to add in work/tasks that would be outside of normal planning.


I would like to add a dummy work order that they can access and record time/notes for when those occurrences do happen. I already have that set up.


Upon marking it complete, I would like to have an automated action repopulate another identical work order in it's place, but with a new number that would be next in sequence.


Assuming the "execute python code" function is necessary here. Is there someone that can help me out with the code to complete this?

TIA!

Avatar
Discard
Author Best Answer

I am getting a forbidden opcode error when saving after copying your code in. Are there any other ways to do this, or a way to override the error? Also, I forgot to mention, I am on Odoo 18 if that makes a difference

Avatar
Discard

Hi, there are a few things you can try:

1- Security Constraints: Check if there are any specific security rules applied to the model that might prevent the copy() method from being executed. You may need to tweak access control or create a custom group to allow this operation.

2- Permission Issues: Make sure that the user or group running the automated action has the proper permissions to access and modify work orders. Sometimes these errors are related to insufficient access rights.

3- Alternative Solution with Scheduled Action:
If the execute python code method is not working, you could consider using a scheduled action to periodically check for completed dummy work orders and duplicate them with a new number.

Here’s an example of how you might implement this:
- Create a scheduled action that runs periodically (like every minute or hour).
- Check for work orders that are in the "done" state.
- For each completed work order, copy it, reset the fields, and assign a new sequence number.

Python code for the scheduled action:

workorders = self.env['mrp.workorder'].search([('state', '=', 'done'), ('production_id', '!=', False)])
for wo in workorders:
new_wo = wo.copy({
'state': 'ready',
'time_ids': [(5, 0, 0)],
'qty_produced': 0,
})
new_wo.name = self.env['ir.sequence'].next_by_code('mrp.workorder') or new_wo.name

This way, the scheduled action runs automatically without needing the "execute Python code" method within the automated action.

4- Override the Forbidden Opcode Error (if applicable):
If you believe the code should run as intended, you could try overriding the security rules for the specific field or action causing the issue. However, this could have security implications, so it's better to first test with less risky solutions like the scheduled action approach.

Let me know if any of these suggestions help.

Author

I do not believe it is a security or permission issue, but I have been working on an alternative solution. I am trying to create a new record by attaching the proper id to each mandatory field, however, I am not sure how to implement the next_by_code sequence as the production_id.
workorder_data = {
'name': 'Rework Cover',
'production_id':
'operation_id': 24,
'workcenter_id': 19,
'product_id': 18,
'product_uom_id': 1,
'qty_producing': 1.0,
'state':'ready'
}
new_workorder = env['mrp.workorder'].create(workorder_data)

This method does create a new workorder but there are other issues with it because it has the same work order number assigned as the previous. What can I do to add the sequence as production_id? or is that based on an existing work order?

Best Answer

Hi,

You can solve this by creating an Automated Action on the Work Order (mrp.workorder) model with trigger On Update, and using the following Python code in the action:


if record.state == 'done' and record.production_id:

    new_wo = record.copy({

        'state': 'ready',

        'time_ids': [(5, 0, 0)],

        'qty_produced': 0,

    })

    new_wo.name = self.env['ir.sequence'].next_by_code('mrp.workorder') or new_wo.name


This will duplicate your dummy work order when marked done, reset it to ready, clear logs, and give it the next sequence number.


Hope it helps

Avatar
Discard
Related Posts Replies Views Activity
2
अग॰ 25
629
2
अग॰ 25
1651
0
फ़र॰ 25
1713
1
अग॰ 25
2391
2
दिस॰ 24
1969