跳至内容
菜单
此问题已终结
1 回复
3353 查看

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

相关帖文 回复 查看 活动
1
1月 23
1480
1
12月 16
4378
2
8月 25
568
0
7月 25
478
1
7月 25
909