Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

1

How can i merge couple of fields into one (py)?

By
Dr Obx
on 3/31/15, 4:35 AM 488 views

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 ?


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)

Dr Obx
on 4/1/15, 6:08 AM
4

Openies Services

--Openies Services--
925
| 2 2 4
Vadodara, India
--Openies Services--

We provide Odoo Services.

Contact us on : contact@openies.com

Openies Services
On 3/31/15, 5:16 AM

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

 

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

Atchuthan - Technical Consultant, Sodexis Inc
on 4/1/15, 6:34 AM

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

Asked: 3/31/15, 4:35 AM
Seen: 488 times
Last updated: 4/5/15, 8:33 PM