Skip to Content
Menu
This question has been flagged
1 Reply
1844 Views

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?



Avatar
Discard
Best Answer

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

Avatar
Discard
Author

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

Author

@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 Replies Views Activity
0
Apr 23
1023
1
Sep 22
1265
1
Jul 22
4408
1
Jun 23
3765
1
May 24
1985