İçereği Atla
Menü
Bu soru işaretlendi
3 Cevaplar
2292 Görünümler

I am in need of merging messages in sale order with associated project task and i would like to do this using automated action. Does someone have an idea on how to achieve this? I'm on Odoo 14.


Thanks

Peter


Avatar
Vazgeç
En İyi Yanıt

Hi Peter,

  1. Create new Automated Action.
  2. Model = Message
  3. Trigger = On Creation.
  4. Action To Do = Execute Python Code.
  5. Enter the code: 
if record.model == 'sale.order':
sale_order = env['sale.order'].browse(record.res_id)
for task in env['project.task'].search([('sale_line_id', 'in', sale_order.order_line.ids)]):
task.message_post(body=record.body)

This script checks if the new message is linked to a sale order.

If it is, it gets the sale order and finds the associated project tasks by searching the project.task model for tasks related to the order lines in the sale order.

Then it posts the new message on each of these tasks (there may be many tasks related to one sale order).

_______________________

OR you can restrict domain on the form of Automated action and leave the code without 

if record.model == 'sale.order':

__________________________________

Also note that the system creates a new letter in the project task by simply copying the text from the sale order message. And this means that if the task and the sale order have the same users in the followers, then such followers will receive duplicates of the original letter.

__________________________________
Please add more business context next time)

Avatar
Vazgeç
Üretici

Many Thanks Yaroslav! This is exactly what i was looking for and it works just the way i need it to.

I´m sorry if i was a bit short in my question about the use case. We work with services and each order line on a sales order creates a task in project. Mainly the communication with the customer is made from sales, but the information needs to pass over to task department.
It is not a problem that the complete message history are tracked in each of the corresponding tasks, it still serves its purpose. I understand what you mean with the followers getting duplicates and maybe i´ll have to handle this further on.

What if i want to do the opposite, pass information from task to sales order? Would it be possible to merge tasks messages into one sales order? So that when a sales person communicates with a customer, they also have a complete service history from our technicians.

Many thanks and regards
Peter

Peter, I'm glad the automatic action worked the way you wanted.
But I don't like your second idea, because you want to trigger automatic message creation in the Task, which should trigger automatic message creation in the Sales Order and so on infinitely.
This is not necessarily a blocker in general, for example you can check if the message is created by an actual user and not the system itself ( if record.create_uid.id != 1: ):

if record.model == 'sale.order':
sale_order = env['sale.order'].browse(record.res_id)
if record.create_uid.id != 1:
for task in env['project.task'].search([('sale_line_id', 'in', sale_order.order_line.ids)]):
task.message_post(body=record.body)

but I advise you to contact Odoo partners for more complex solutions.

Üretici

I understand what you are saying.

I have been looking for some apps that could achieve this more advanced solution but without success. I might leave it as a one way communication channel for the moment and bring it up with my Odoo partner later on.

Your solution is beautiful and of great help to me! Many thanks Yaroslav!

//Peter

Üretici En İyi Yanıt

I understand what you are saying. 

I have been looking for some apps that could achieve this more advanced solution but without success. I might leave it as a one way communication channel for the moment and bring it up with my Odoo partner later on. 

Your solution is beautiful and of great help to me! Many thanks Yaroslav!


//Peter

Avatar
Vazgeç
İlgili Gönderiler Cevaplar Görünümler Aktivite
1
Şub 21
4424
3
Haz 20
5096
0
Haz 20
2674
0
Şub 16
3784
0
Ağu 23
3405