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

Hi everybody,

I'm trying to have the internal reference automatically set when creating new products.

Using automated actions, I used a python script that works just fine:


if not record.default_code:
seq = env['ir.sequence'].next_by_code('product.sequence')
record.write({'default_code' : seq})

The problem is that when creating variants for the product, that number is not passed to the variants. And as creating variants erases the reference of the main product, there isn't any reference anymore at all, nor for the main product, nor for the variants.

For now, I'd just like to have the reference number of the product copied to the variants when creating them.

How can it be?

Thanks

Avatar
Descartar
Mejor respuesta

Hello Virtual Crew,


As, "product.product" Inherits "product.template", so over-ride the create method of "product.product" to achieve this.


Add below code of snippet in you module's 'product_product.py' file.


//Code in Comment//


Hope this helps.

   

If you need any help in customization feel free to contact us.


Thanks & Regards,

Email:  odoo@aktivsoftware.com           

Skype: kalpeshmaheshwari

Avatar
Descartar

Code :

from odoo import models, api

class ProductProduct(models.Model):
_inherit = 'product.product'

@api.model_create_multi
def create(self, vals_list):
# Call the original create method
products = super(ProductProduct, self).create(vals_list)

for product in products:
# Check if the product template has a default code and the variant doesn't
if product.product_tmpl_id.default_code and not product.default_code:
# Set the variant's default_code to the product template's default_code
product.default_code = product.product_tmpl_id.default_code

return products

Publicaciones relacionadas Respuestas Vistas Actividad
1
ene 23
1490
1
dic 16
4394
2
ago 25
596
0
jul 25
486
1
jul 25
918