Skip to Content
Menu
This question has been flagged
3 Replies
834 Views

Dear all,

why this code to set draft MO not work in odoo 16

python code

def action_draft_mo(self):
self.write({'state':'draft'})
return {}

xml code:



when i click SET TO DRAFT.

nothing happend,

thank for any respons


kind regards,

Giri


Avatar
Discard
Best Answer

The state of an mrp.production is a read only computed value ... writing to it has no effect.

Avatar
Discard
Author Best Answer

Dear cybrosys,

Thank for your valuable answering.

i revise my code like below:

def action_draft_mo(self):
try:
_logger.info("action_draft_mo() method called")
self.write({'state': 'draft'})
_logger.info("line after self.write draft")
except Exception as e:
_logger.error("Error resetting MO to Draft: %s", str(e))
return {}

and the XML :



when i push Set to Draft Button . Got the logger:

 

it's show me the method action draft is executed. but the status of MO not changed to Draft.

i use user with administrator right in manufacturing module.


thank for any respons.

kind regards,

Giri

Avatar
Discard
Best Answer

Hello Giri,
The code you provided should work to set the manufacturing order (MO) to draft state in Odoo 16. However, there might be a few reasons why it's not working as expected:

1. Check Permissions: Ensure that the user clicking the "SET TO DRAFT" button has the necessary permissions to write to the MO model.
2. Check Button Declaration: Make sure that the button is correctly declared in the XML file and is associated with the correct method.
3. Check for Errors: Check the logs for any error messages that might provide clues as to why the button click is not working.

Here's an example of how the XML button declaration should look:
<button string="Set to Draft" class="oe_highlight" type="object" name="action_draft_mo"/>

If you're still experiencing issues, consider adding logging or debugging statements to your Python method to see if it's being called and if any errors are occurring.



Hope it helps.



Avatar
Discard