Перейти к содержимому
Меню
Чтобы взаимодействовать с сообществом, необходимо зарегистрироваться.
Этот вопрос был отмечен
1 Ответить
3350 Представления

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

Аватар
Отменить
Лучший ответ

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

Аватар
Отменить

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

Related Posts Ответы Просмотры Активность
1
янв. 23
1474
1
дек. 16
4368
2
авг. 25
558
0
июл. 25
475
1
июл. 25
907