Skip to Content
Menu
This question has been flagged
2 Replies
6462 Views

Our internal product ID's could be generated automatically based on the variant attributes.

For example we could have a product called "Shirt" which has different colors and sizes.

The specific variants Internal Reference could be set like this based on the variants attributes:

<Product name><Color><Size> = SHIRTREDXS

As I'm new to Odoo, I would like to know what is the proper way to accomplish something like this? Should I use javascript/modules/something else? I'm not after the full solution for this specific problem, but a nudge to the right direction so I can learn to do stuff like this with Odoo.

Avatar
Discard
Best Answer

Just make the default code a computed field. E.g.:


class product_product(models.Model):

    _inherit = 'product.product'

    @api.multi

    @api.depends('attribute_value_ids.name')

    def _compute_default_code(self):

        for product in self:

            default_code = product.product_tmpl_id.name

            for attr_value in product.attribute_value_ids: # the order is according to sequence. You may re-order it using 'sort' or 'search'

                default_code += attr_value.name

                product.default_code = default_code

      default_code = fields.Char(compute=_compute_default_code, store=True)

Avatar
Discard
Best Answer

You can use/adapt https://www.odoo.com/apps/modules/8.0/product_variant_default_code/

Avatar
Discard