Ir al contenido
Menú
Se marcó esta pregunta
1 Responder
1699 Vistas
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 

Avatar
Descartar

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.

Mejor respuesta

Create a many2one field on the Manufacturing Order (production.order) linked to Contacts (res.partner).  I called it x_studio_customer.

Create an Automated Action with Execute Python code as the Action and this should get you the customer:



if record.origin:
  order =  env['sale.order'].search([('name','=',record.origin)])
  record['x_studio_customer'] = order.partner_id


Substitute x_studio_customer with your field name


This can also be created as a server action.  I have added more checking to make it extra robust, but can't guarantee it will work in every case:


for record in records:
  order = False
  if record.origin:
      if record.sale_order_count:
          order = record.env['sale.order'].search([('name','=',record.origin)])
          if order:
            record['x_studio_customer'] = order.partner_id

This checks that 

  1. There is a source and
  2. There is a sales order in the source and 
  3. The sales order can be retrieved.  

This Python code can be used in the Automated Action (and if you create an Automated Action it can also be used as a Server Action).

Creating a contextual action lets you update the customer on existing manufacturing orders.


Check it with your configuration / version of Odoo

Avatar
Descartar
Autor

Can you give me more guide on how to do it? I might do sometings wrong
the Customer name it's not showing.

Thank you sir

I added a screenshot and some extra information

Publicaciones relacionadas Respuestas Vistas Actividad
1
jun 23
2417
0
abr 23
1318
0
ene 23
2095
1
sept 24
3106
1
jun 22
2679