Odoo Help


Merging fields into one

Dr Obx
on 4/4/15, 5:21 PM 1,532 views

Trying to combine 3/4 fields into one in product.

For example i would like to create product name using fields I created. brand, model, size etc

So name = brand+model+size+... and paste it into <field name="name"/> then save.

How can i do it ?

Hi Empiro, still trying but all the time a'm getting some errors, once it is wrong indentation, once i fought it it gives me an error "Brand is not defined" however it is defined but in other module. so what should i do ? remove from my module and create new in this module ?

Dr Obx
on 4/5/15, 9:48 AM

@robert If you have defined "model, brand and size" then directly use those fields. Use same name as what you declared. That will work.

Emipro Technologies Pvt. Ltd.
on 4/5/15, 2:12 PM

Add the field prod_name in your view as invisible (update browser view after module update), I also modify my code to write in field name of class product template and not product product, please avoid to display email you get from odoo, thanks, let me know the result, bye

Cyril Gaspard (GEM)
on 4/5/15, 3:37 PM
Cyril Gaspard (GEM)
On 4/5/15, 2:10 PM

from openerp import models, api, fields

from openerp.tools import ustr

class ProductProduct(models.Model):

    _inherit = "product.product"

    brand = fields.Char('brand')

    model = fields.Char('model')

    size = fields.Char('size')

    prod_name = fields.Char(compute="_get_prod_name", string="Product Name")


    @api.depends("brand", "model", "size")

    def _get_prod_name(self):

        brand = self.brand or ''

        model = self.model or ''

        size = self.model or ''

        name = ustr(brand) + " " + ustr(model) + " " + ustr(size)

        self.product_tmpl_id.name = name

        self.prod_name = name

Hey Cyril, is it possible to add some conditions to it and for example change set of fields if required ? example: if itype = "type1": prod_name = brand + ' ' + model + ' ' + size if itype = "type2": prod_name = brand + ' ' + model + ' ' + condition if itype = "type3": prod_name = brand + ' ' + size + ' ' + connection

Dr Obx
on 4/7/15, 7:54 AM

I don't think is possible just like that. Field itype is declared by other module so do I have to create a new itype in this module ?

Dr Obx
on 4/7/15, 8:27 AM
Dr Obx
On 4/5/15, 10:28 AM

Guys, I can't make it work, I already have brand, model and size declared. Why whilst am trying install new module it tells me brand not declared, etc.  After that i've had a message regarding indentation, now i have: " can only concatenate tuple (not "str") to tuple"

So in this case all fields I have are char type.

Dr Obx
on 4/5/15, 11:58 AM

Great thnx Cyril, finally i got it work. Based on this example i can build something more ;) Thanx a lot.

Dr Obx
on 4/5/15, 4:22 PM
michel Guénard
On 4/5/15, 9:14 AM

@Emipro,@Cyril How would you do the equivalent solution for a Saas user who only have the developper mode.

For instance I can't create a new field with a type function, because this type is not proposed under the Saas environment.

Although I really need this capacity to combine fields to name the product with the name of its composer and opus title (music domain)!

Hi, please open a new post for that, your case is not similar than this of Robert, contributors will try answer to your problem for your case (explain what configuration menus are available for saas mode => menu modules, company ... or display a picture with all menus extend, a lot of people like me don't use saas version) , bye

Cyril Gaspard (GEM)
on 4/5/15, 10:35 AM


For this, you can create a new field as of type "Function" i.e fields.function()

from openerp import models,api,fields

class product(models.Model):

    _inherit = "product.product"



    def get_prod_name(self):

        for product in self:

            brand = product.brand_id.name or ''

            model = product.model_id.name or ''

            size = str(product.size)

            product.prod_name= brand + "_"+model+"_"+size

   prod_name = fields.Char(compute="get_prod_name", string="Product Name",store=True)

Here you declared a new field "prod_name" which is a compute field. One more thing, product.product model has a field "name_template" which generally stores the same value as the field "name" from product.template. So you need to decide here whether to take the new field "prod_name" or not. Here I treat brand_id, model_id as many2one fields.

Hope this helps !!.

About This Community

This platform 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.


Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

2 follower(s)


Asked: 4/4/15, 5:21 PM
Seen: 1532 times
Last updated: 4/5/15, 8:33 PM