Odoo Help


How to change the generation of 'default_code' in 'product_variant_multi'? [Closed]

Anabela Damas
on 12/18/13, 12:37 PM 2,664 views

The Question has been closed

Anabela Damas
on 12/19/2013 06:45:50


I've developed a module that set the 'default_code' from product as unique and required. Like this:

class product_product(osv.osv):
    _inherit = "product.product"
    _columns = {
        #'default_code' : fields.char('Reference', size=30, required=True),
        'default_code' : fields.char('Internal Reference', size=30, select=True, required = True),
    _sql_constraints = [('code_unique','unique(default_code)', _("Product code must be unique!")),

Now I try to install 'product_variant_multi' in a BD with my new module, and I'm facing some problems with the condition that I've give to 'default_code'. I've the problem with the required setting that Igive to the field, I fixed this by inherit the function 'button_generate_variants ' and change this:

            for variant in list_of_variants_to_create:
                vi_code = product_temp.name +'_'+str(count)
                print vi_code
                count += 1
                vals = {
                    'name': product_temp.name,
                    'track_production': product_temp.variant_track_production,
                    'track_incoming': product_temp.variant_track_incoming,
                    'track_outgoing': product_temp.variant_track_outgoing,
                    'product_tmpl_id': product_temp.id,
                    'dimension_value_ids': [(6, 0, variant)],
                    'default_code': vi_code,

So I need to change the code generator in the form of product templates (the red area in the picture):

image description

So I want to change this: [_'-'.join([x.option_id.name for x in o.dimension_value_ids] or ['CONF'])_], but I don't understand this syntax. I want to in the code have the name of template and the color, like this :

Internal Reference : Bicycle Color - Black Internal Reference : Bicycle Color - Blue

If I could change the Code Generator to do this above, I would have the unique Internal Reference....

Someone understand this syntax? How can I join the name of template with the name of the color ?


On 12/18/13, 1:04 PM


For what you want to do, you have to change the Code Generator to :

[_o.name +'/'_][_'-'.join([(x.option_id.name) for x in o.dimension_value_ids] or ['CONF'])_]

I 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

0 follower(s)


Asked: 12/18/13, 12:37 PM
Seen: 2664 times
Last updated: 3/16/15, 8:10 AM