Skip to Content
मेन्यू
This question has been flagged
1 Reply
415 Views

Hello,

Currently working on the res.partner model, i need to add a computed field wich will display an url like this :  'https://reallycoolurl.com/AppID/access' Where the "App ID" is a field saved in the res.partner model as 'x_studio_app_id'

In Studio I created the field "App URL"

and i know in the properties you can compute the field. But i don't know what the code should look like.



Can someone provide me with the code for a solution or a link to a documentation with clear instruction? I loked up at multiple one and didn't manage to maje things work.
It would really help me for other fields later.

Sincerely,

Edouard MORET.


Avatar
Discard
Best Answer

Hi,

Try this

from odoo import models, fields


class ResPartner(models.Model):

    _inherit = 'res.partner'


    app_url = fields.Char(compute='_compute_app_url', string='App URL', store=True)


    def _compute_app_url(self):

        base_url = 'https://reallycoolurl.com/'

        for partner in self:

            if partner.x_studio_app_id:

                partner.app_url = f"{base_url}{partner.x_studio_app_id}/access"

            else:

                partner.app_url = False


Hope it helps

Avatar
Discard