Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
2 Trả lời
1776 Lượt xem

Hello everyone

I am still a beginner I have just started odoo 1 month ago I do an automated action which has the role of sending a notification to the Management Department if there has been a modification of the contact name for the moment it works but I have when even wanted to improve it so that it gives me details in the notification as follows:

"Contact name {old_name} has been changed to {new name}"

Thank you all


Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

Hi,

To include both the old and new name values in the notification message, you can use the context values that Odoo gives to server activities.

For example, use the following code:

old_name = record.name

new_name = record.env.context.get('new_name')

if old_name and new_name:

    body = f"Contact name {old_name} has been changed to {new_name}"    mail_values = {

        'subject': 'Contact Name Changed',

        'body_html': body,

        'email_to': 'recipient@gmail.com',  # Replace with the desired email address

        'email_from': record.env.user.email,

    }

    record.env['mail.mail'].create(mail_values).send()


Hope it helps.

Ảnh đại diện
Huỷ bỏ

Does this really work ? i think we should use mail.tracking.value to get old and new name

Câu trả lời hay nhất

Hello Youssouf , in order to retrive old name, we need to get to use model mail.tracking.value

in order to get it, i guess the code to take old value like this

tracking_value = contract.message_ids.tracking_value_ids.filtered(lambda t: t.new_value_char == contract.name)[:1]

if tracking_value:

​old_contract_name = tracking_value.old_value_char

NOTE THIS: the contract name need to have tracking=True, i'm not sure it has it or not, i haven't test this code but this the best idea you can get

Ảnh đại diện
Huỷ bỏ

contract here meen record or you can use for record in records

Bài viết liên quan Trả lời Lượt xem Hoạt động
2
thg 11 24
1547
1
thg 10 24
1352
4
thg 7 25
1796
1
thg 7 25
1016
2
thg 5 25
961