Skip to Content
Меню
Вам необхідно зареєструватися, щоб взаємодіяти зі спільнотою.
Це запитання позначене
1 Відповісти
1122 Переглядів
Hello, I need to assign a value to a many to one field automatically based on this domain and write the first id that meets that condition. How could I achieve this with a server action?

 domain="[('x_estado', '=', 7),('x_marcanew', '=', x_dispmarca),('x_modelonew.x_mprimario', '=', x_dispmodeloprim)]"

Аватар
Відмінити
Найкраща відповідь

Hi,


Refer to the blog on creating and configuring server actions for detailed guidance: How to Create and Configure Server Actions in Odoo 17.


Here is the code to be used in your server action method:


def custom_server_action(self):

matching_record = self.env['your.custom.model'].search( [

('x_estado', '=', 7),

('x_marcanew', '=', self.x_dispmarca),

('x_modelonew.x_mprimario', '=', self.x_dispmodeloprim)

], limit=1)


# Assign the found record to the Many2one field

if matching_record:

self.x_related_record_id = matching_record.id


Hope it helps

Аватар
Відмінити
Related Posts Відповіді Переглядів Дія
1
черв. 15
4459
2
бер. 15
8619
2
квіт. 17
10266
2
бер. 15
4849
3
черв. 23
10620