Skip to Content
Меню
Вам необхідно зареєструватися, щоб взаємодіяти зі спільнотою.
Це запитання позначене
1 Відповісти
2849 Переглядів

In the odoo event.booth.configurator, which pops up when selecting event booth product in a sale order, you have to select the event and the booth type. However, in my company, I always only have one event at a time, all others are either not created yet or archived. So, when i open the event configurator, I want to check whether there is only one Event within this company that is active (aka not archived) and then automatically select it.

Here is my current attempt:

# -*- coding: utf-8 -*-
from odoo import models, fields, api
# from . import prepare_engine as rectanglemaps_engine


class EventBoothConfigurator(models.TransientModel):
_inherit = 'event.booth.configurator'

# plan = fields.Binary(string='Plan', attachment=True)

@api.model
def create(self, values):

# If the company only has one event active, we set it by default
if not values.get('event_id'):
values['event_id'] = self.env['event.event'].search([('active', '=', True)], limit=1).id


return super(EventBoothConfigurator, self).create(values)

I do not get an error message, however, nothing happens

How can I make this possible? 

Is the create method the right idea?



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

Hi Josef,

You can use the default_get function for this.  Pass your default event_id as below:

@api.model
def default_get
(self, fields):
res = super(EventBoothConfigurator, self).default_get(fields)
events = self.env['event.event'].search([])
if len(events) == 1:
res['event_id'] = events.id
return res

For more details on default_get function refer thisDefault Get Function in Odoo || Set Default Values Using Default Get Function

Hope this will help you

Thank you

Аватар
Відмінити
Автор

well that was an amazing tip! Thanks for letting me know!
I do have one more question: Does this ensure that the selected event belongs to the company that is currently in use? I use multicompany in my odooinstance, so this has to work.
Or do I have to add something like search([('company', '=', active_company)]

?

If you have multi company instance you have to pass the company domain also in the search
Thank you

Автор

@Mehjabin Farsana thank you, can you tell me how?

pass your company domain as this
events = self.env['event.event'].search([('company_id', '=', self.env.company.id)])

Related Posts Відповіді Переглядів Дія
0
квіт. 23
1862
4
квіт. 25
4423
1
лип. 22
6623
1
серп. 25
3591
Auto refresh tree view Вирішено
1
черв. 23
5271