This question has been flagged
4 Replies
2005 Views

Hello, Im new to Odoo Studio and Im trying to figure out how to add the Customer name from a Sales order to a Manufacturing Order.  Does anyone have an online example or an explanation they can share to point me in the right direction?

Avatar
Discard

How are you creating the manufacturing order?

Author

The manufacturing orders are created at confirmation of the Sales Order.

Are they generated by reordering rules or the Replenish on Order (MTO) route?

Author

Hi Lucas. They are generated with Replenish On Order (MTO).

I have a solution for you, I will post the answer here

Author

Awesome. Thank you for your help.

Best Answer

When you confirm a sales order that contains a product with the MTO Route, then the 'Source' field on the 'Miscellaneous' tab on the manufacturing order will contain the Sales Order number as a text field.

We can use this to create a firm link between the Sales Order and Manufacturing Order.

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

Now, when a Sales Order is confirmed the Manufacturing Order that is generated will be formally linked to the Sales Order and the related field will pull through the customer name from that Sales Order. You can also add more related fields to pull any other fields from the SO, e.g. customer phone number etc.

Please let me know if this works for you

Avatar
Discard
Author

Thank you so much. I will give it a try and let you know.

Author

So on the 1st field I see it is pulling in the Sales Order number. However, on the Related Field it is not bringing in the customer name. I made sure to delete all my manufacturing orders, cancel the sales order, then confirm it again to create new records. Any ideas?

You can manually select the Sales Order number in the Many2One field to test if the related field is pulling the correct data through. It is easier to test the link manually rather than creating a new sales/manufacturing order.

Open Studio, select the related field and check the 'Related Field' box in the left hand pane and make sure it says something like:
x_studio_many2one_field_9yWzD.partner_id.display_name

It must say partner_id.display_name , please check that

Author

The Related Field value is: x_studio_sales_order.partner_id.display_name

Which Odoo version are you on?

Author

Im doing a trial of Odoo so it should be latest. Im preparing for a test run and we will then subscribe.

Author

I noticed when I was adding the Related Field there were multiple Sales Order values listed. I took the first one. Im not sure why so many are listed. I was thinking about creating another test database to try your steps again. It seems like it should work.

If there were multiple Sales Order values listed then it means that you have added multiple Many2One fields referencing the Sales Order model

Author

Yea, I just created a new database and did it again and it worked! I did create many fields trying to figure this out. Thank you so much for your help. I have a better understanding of how Studio works now too.

You are welcome, I had the same requirement and spent waaaaay too long trying to figure it out.

The automated action will only update one Many2One field with the SO number. If you have multiple Many2One fields (from testing etc) you have to make sure the related field is referencing the correct one.

Good luck!

Best Answer

hi, this is realy good starting position help. try it.
https://odootricks.tips/about/odoo-studio/

Avatar
Discard
Best Answer

How about not have "related field" in Odoo 16 and 17 What can i ues?

Avatar
Discard
Best Answer

Hi,

Lucas's example is good, but it still requires manual selection of the sales order in the Manufacturing Order in order to display the customer name. With the following solution you will immediately enter the customer name when creating the production order:

1. Go to a Manufacturing order and open Odoo Studio

2. Add a 'Many2One' field that is linked to the 'Sales Order' model.

3. Add a Related Field on the Manufacturing Order using Studio. Use the path Sales Order > Customer > Display Name. Give it a technical name x_studio_production_customer
4. C
reate an automated action with the following settings:

- Model: Production Order

- Trigger: On Creation

- Action to do : Python Expression

- The Python code

order = record.env['sale.order'].search([('name','=',record.origin)])
if order:
​record.write({'x_studio_production_customer': order.partner_id.name})

Good luck!

Avatar
Discard