By follow this
Firstly, open Studio on the Manufacturing Order and add a 'Many2One' field that is linked to the 'Sales Order' model.
Secondly, create an automated action with the following settings:
- Model: Production Order
- Action To Do: Update the Record
- Trigger: On Creation
- Field: (Select the custom Many2One field that is linked to the sales order model)
- Evaluation Type: Python Expression
- Value: record.env['sale.order'].search([('name','=',record.origin)])
Thirdly, Add a Related Field on the Manufacturing Order using Studio. Use the path Sales Order > Customer > Display Name
I can't find "A Related Field" is the Thirdly Part
How to Add customer name in manufacturing order?
Is there another way to Add customer name in manufacturing order? (uesing odoo online 16 - 17)
Thank you
Hello Chris.
We enter the sales order manually into the manuifacturong order, and collect som additional information. I will try your automatic action to be more efficient.
But we have another challenge: Multi level manufaturing and we want the sales order information also on the child order. We can have two or three levels below the top order. Do you have any tips to include that in automation?
Hello Lars,
The same logic can be used anywhere if there is a link. For a child MO, the source is the parent MO. I think the fields Count of Source SO and Number of source MO will tell you whether the parent is an SO or MO.
Hello Chris.
The field 'mrp_production_source_count' is not available to set criteria in the domain in the action. Confused there. But I will get help on the coding anyway, so we will solve it.
Hello Lars,
It should be possible to add it to the Python code, something like this
if record.origin record and mrp_production_source_count:
Thanks Chris
Your comment was very helpful. I will explain some details, if anybody else should be interested:
It was in the user interface where you can define the domain that the field 'Number of source' was not available to look up. But I could modify in that window where the code is generated. Just write the right field name on the right place. So domain for the action looks like this, so we do not run this action on child orders, and we do not need it on backorders:
["&", ("backorder_sequence", "=", 0), ("mrp_production_source_count", "=", 0)]
This is to select the top order. And the code to find the sales order number:
if record.origin:
order = env['sale.order'].search([('name','=',record.origin)])
record['x_studio_many2one_field_416E4'] = order.id
The top order is created first. We have MTO also on the semifinished products. So child order is generated after the top order. For those I wanted to copy the sales order number that exist in the top order. Or more correct - from the source order.
Domain filter is a little different, so we only run this action if the order is a child order and is not a backorder:
["&", ("backorder_sequence", "=", 0), ("mrp_production_source_count", "=", 1)]
Code to get the sales order number:
if record.origin:
order = env['mrp.production'].search([('name','=',record.origin)])
record['x_studio_many2one_field_416E4'] = order.x_studio_many2one_field_416E4
So today I could make our sales person happy as manual work is reduced.
I suppose that you can't select mrp_production_source_count from the UI because it is a computed field. If you can enter it manually that is a good solution.