跳至内容
菜单
此问题已终结
2 回复
266 查看

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!

形象
丢弃
编写者 最佳答案

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

形象
丢弃

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.

最佳答案

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

形象
丢弃
相关帖文 回复 查看 活动
2
8月 25
549
2
8月 25
1578
0
2月 25
1656
1
8月 25
2301
2
12月 24
1907