Ir al contenido
Menú
Se marcó esta pregunta
1 Responder
5146 Vistas

For example, i would like to combine into one values from form to create a one string (don't ask why i just need it. My knowledge won't let me :)

I know how to do it in other languages but not Python. Maybe framework allow to do it but i don't know how so please can anyone help me with ?


Avatar
Descartar
Autor

Perfect example, i hope i can use this solution in my project. It seems like a new API a'm I right ? (i'm a newbie so i want be sure what to do)

Mejor respuesta

To merge the fields in one you can use compute on field. for example.

class res_partner(models.Model):
_inherit = 'res.partner' # extending partner model

    def merge_string(self):

        if self.name

        return self.title or '' + self.name or '' # will return Partner Title + Partner Name(Mr. Openies)


    merged_string = fields.Char(compute='merge_string') # adding one field which merges string


Note: Compute field will get computed when the record is getting saved.

you can also refer the odoo new api doc: http://odoo-new-api-guide-line.readthedocs.org/en/latest/fields.html#computed-fields

 

Avatar
Descartar

with the help of api.depends, you could trigger the computation method before the SAVE event. for e.g. add @api.depends('title','name')

Publicaciones relacionadas Respuestas Vistas Actividad
0
may 20
6267
1
jun 16
11324
1
dic 16
3436
1
sept 15
4602
11
abr 15
11236