İçereği Atla
Menü
Bu soru işaretlendi
1 Cevapla
3370 Görünümler

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
Vazgeç
En İyi Yanıt

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
Vazgeç

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

İlgili Gönderiler Cevaplar Görünümler Aktivite
1
Oca 23
1493
1
Ara 16
4398
0
Ağu 25
11
0
Ağu 25
14
2
Ağu 25
609