Hello,
Someone out there that know if it is possible to change the state of the MO generated by Odoo in the MPS?
By default they are generated confirmed, can they be generated in draft?
Thnxs
Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:
Hello,
Someone out there that know if it is possible to change the state of the MO generated by Odoo in the MPS?
By default they are generated confirmed, can they be generated in draft?
Thnxs
You can do this via the Automation Framework using a custom field, an automated action, a custom view and a server action.
Consider this a proof of concept that you may need to modify based on your needs. It has been quickly tested based on manually created, MTO created and scheduler/order point created MO's but may still need further improvements to support all workflows. Contact your Odoo Consultant or an Odoo Partner if you need more help.
1. From the Fields Menu, create a custom boolean field Released which will prevent confirmation of a manufacturing order if false (the default value) and allow it if true:
2. From the Views Menu, create a custom View to add this field to the Form View of Manufacturing Orders:
<field name="product_id" position="before">
<field name="x_released"/>
</field>
Note: you can also use Odoo Studio to both create and add the field to the UI at the same time, see the References section at the end for more information.
3. From the Automated Actions Menu, create a custom action that prevents Manufacturing Orders from being confirmed if the value of x_released is false:
for record in records:
if not record.x_released:
record['state'] = 'draft'
4. From the Server Actions Menu, create a custom action that allows Users to release Manufacturing Orders:
Note: when you create this action, look in the URL to find the ID of it as you will need it in the next step.
5. Finally, edit the custom View made in the second step to add a button that runs the Server Action and hide the Confirm button until the MO is released:
<button name="action_confirm" position="before">
<button name="458" attrs="{'invisible': ['|',('x_released', '=', True),('state','=','cancel')]}" string="Release" type="action" class="oe_highlight"/>
</button>
<button name="action_confirm" position="attributes">
<attribute name="attrs">{'invisible': ['|',('state', '!=', 'draft'),('x_released', '!=', True)]}</attribute>
</button>
Note: the ID of the Server Action was 458 - yours will be different, so change this number to the number you found during the fourth step.
What you end up with is Manufacturing Orders that are initially created in Draft mode:
When you open each MO, you will see that the CONFIRM button is hidden until you click the new RELEASE button:
Click both buttons to confirm the Manufacturing Order.
References:
Ray Carnes,
Thank you this is a beautiful solution. I have one question however, if let's say a component on the bom has the routes of purchase and replenish on order, the request for quotation is still created.
Is there the possibility to block that as well, until the manufacturing order is confirmed?
Best regards,
Yes, please contact your Odoo Consultant or Odoo Partner for help with this.
I was able to make this work with a slight modification for v14. The lines from step 5, I added to the <header> section of the form. It does not create a "Release" button but does keep the Manufacturing Order in Draft mode and once the order is to your liking, you press "Confirm" to lock it.
Hello Ray,
this sounds good for a technical guy, but for a functional one as myself it is quite weird
Why is the MO not created in Draft state by the MPS (as the PO for example)
At least it should be configurable so that the use can decide whicg behaviour best fits
Regards
Maurice
I tested this for Odoo 14 and it works like a charm. This procedure can be followed with the same steps in Odoo 13 and the steps do not look any different to Odoo 14. However, in Odoo 13 it is not leading to a 'draft' state of the MO.
Any idea's on why the automated action does act differently in Odoo 13?
I just tested in v13 and it works the same way - please start over and check your work - you likely have missed a step or made a small mistake somewhere.
Tried it again on v13 and seems to work indeed. Thanks for the solution in general and for checking it in v13 too!
I was hoping to use this modification to allow selecting the BOM. I was able to perform this modification successfully and the MO generated via automation remains in a draft state. However when I change to a different BOM and attempt to save I get an errror:
"You can only delete draft moves."
Can this method be modified/enhanced to allow selecting a different BOM prior to confirmation?
Hey,
Though the initial idea is good, I found problems when using this approach:
- You will have problems if your MO needs to launch new MOs. Let's say that you have Prod1 = Part1+Part2, all of them manufacturable. If you launch MO/1 for Prod1 when confirmed, it will launch MO/2 and MO/3 for Part1 and Part2, initially blocked. If you don't release MO/2 and 3, and in the meanwhile, you launch a new MO for Prod1, (MO/4), it won't generate new MO for Parts 1 and 2, nor add units on the existing (blocked) ones. However, it will generate new MO if MO/2 and 3 are released.
-Additionally, it does something to the existing MO/2 and MO/3, as it modifies its last updated time. However, it does not change their due quantity.
I did not test what happens with Purchase Orders, but I can anticipate a similar behaviour.
Using Odoo 14 Online.
Hey Ray! Thanks for sharing it with us!
I did step by step, and indead the MO are created in draft state
But if i try do edit quantity or change the bom is giving the error: "You can only delete draft moves."
The version of odoo is V16
Any help will help us (seems that others faced the same)
Many Users have found that create an empty Bill of Materials is far easier. If this is the first in the sequence of BoM's for a product (drag it to the top of the list) then the MO will always be created in draft. You can read a forum post about this approach at https://www.odoo.com/forum/help-1/how-to-generate-a-manufacturing-order-in-draft-status-from-a-sales-order-using-mto-215627
Hello there,
An easy work around would be to add an empty BoM as the first bom to your product that is set up with MTO. That way, the MO triggered will be in Draft. Then you can select the correct bom and confirm the MO as you please.
Posting here to bump Tim Drinkwater's comment. Has anyone been able to figure out this part?
My understanding is that the MTO rule creates stock moves in confirmed state. I am trying to create an automated action to force them into draft state, similar to Ray's solution for the production order. Here's what I have come up with for python code in an automated action targeting the stock.move model. It needs work (I think my syntax is bad) but it could help as a good starting point:
for record in self:
if self.env['mrp.production'].search('name', '=like', 'record.reference') == 'draft':
record['state'] = 'draft'
Hey Hayden!
Did u succes to find a solution?
Ray's solution, is indead creating my MO in draft mode, but i cannot update/edit the bom , as is giving me the error "You can only delete draft moves." , why is this error, as anyway the MO is in draft mode?! Why i should not be able to delete it?
@Nicu Constantin The only way I have been able to do this is by first setting the associated 'Stock Moves' to draft state before changing the BOM. To do this is a bit convoluted but I will explain how:
1. Enable developer mode
2. Create a server action on the Stock.Move object called something like "Move: Force Draft". Set it to execute the following python code: 'for record in records:
record['state'] = 'draft''
3. Create a contextual action for the server action.
Now everything is set up, each time you want to change a BOM, you have to do the following (Note, you must be in developer mode to do this):
1. Go to 'Inventory > Reporting > Stock Moves'. Look for the moves with 'reference' value that matches the MO you want to change.
2. Open the stock moves and hit the action button - run the "Move: Force Draft" action. Do this for each move associated with the MO.
3. Once all moves are draft, you should be able to change the BOM on the MO.
You can try to create an automation to force stock.move to be created in draft, similar to what Ray did in point #3 of his answer, but for whatever reason I did not have any luck with this. Hope this helps!
Cree una cuenta para poder utilizar funciones exclusivas e interactuar con la comunidad.
InscribirsePublicaciones relacionadas | Respuestas | Vistas | Actividad | |
---|---|---|---|---|
|
2
ago 22
|
4580 | ||
|
1
mar 22
|
2440 | ||
|
1
feb 22
|
2248 | ||
|
1
feb 22
|
2767 | ||
|
0
jun 21
|
2062 |
How did you solve this?