Skip to Content
Menu
Musisz się zarejestrować, aby móc wchodzić w interakcje z tą społecznością.
To pytanie dostało ostrzeżenie
1 Odpowiedz
3889 Widoki

I am trying to add a computed method to the event.booth model in Odoo 15

These are my attempts:

#1

class EventBooth(models.Model):
_inherit = 'event.booth'

super.name = fields.Char(string='Name', translate=True, compute='_compute_name')


#2

class EventBooth(models.Model):
_inherit = 'event.booth'

name = fields.Char(string='Name', translate=True, compute='_compute_name')

#3

class EventBooth(models.Model):
_inherit = 'event.booth'

super(EventBooth, self).name = fields.Char(string='Name', translate=True, compute='_compute_name')


I have noticed, that event.booth doesnt have a name field directly, rather it inherits its name field from a model called 'event.type.booth'. By default, the name field on event.type.booth is not a computed field.

Thank you for your help.







Awatar
Odrzuć
Autor

This is what the computed method looks like

@api.depends('halle_id.name', 'start_number', 'end_number')
def _compute_name(self):
for record in self:
try:
record.name = "{} | {}-{}".format(record.halle_id.name, str(record.start_number), str(record.end_number))
except:
record.name = "Stand"

The second approach must work. Are there any specific errors you get?

Najlepsza odpowiedź

Hi Josef Schmid,
Please try with this.

class Eventbooth(models.Model):
_inherit = "event.booth"

name = fields.Char(string='Name', translate=True, compute='_compute_name')

@api.depends('halle_id.name', 'start_number', 'end_number')
def _compute_name(self):
for record in self:
try:
record.name = "{} | {}-{}".format(record.halle_id.name, str(record.start_number), str(record.end_number))
except:
record.name = "Stand"


Don't Forgot to add the "event_booth" Module into the depends of  you custom module manifest file:

        'depends': [ 'event_booth']

If it's help you, Please vote the Answer.

Awatar
Odrzuć
Powiązane posty Odpowiedzi Widoki Czynność
1
sty 24
2911
1
lip 25
2086
1
lut 24
1613
2
gru 22
12579
1
maj 24
2340