Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
4 Trả lời
3870 Lượt xem

Hi Odooers,

I want to prevent the product.template object from clearing the internal reference when it's variant's internal reference changed.I tried the below code, the text is printing but product.template's internal reference value is still erased

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

@api.depends('product_variant_ids', 'product_variant_ids.default_code')
def _compute_default_code(self):
print("overridden")

kindly suggest any solutions.

Thanks in advance

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

Hello

Or you can set the default_code field as non-compute field:

default_code = fields.Char('Internal Reference', compute=False)
Ảnh đại diện
Huỷ bỏ
Tác giả

let me try

Tác giả

Thanks it worked

You're welcome

Câu trả lời hay nhất

It seems like you have a typo. The class name should be ProductTemplate if you are trying to override product.template.

Ảnh đại diện
Huỷ bỏ
Tác giả

The class name doesn't matter right? only the _inherit field is what matters I think.

Câu trả lời hay nhất

我在ODOO【18.0】中也有一样的需求,根据此贴将default_coder compute设置成False后解决,十分感谢。

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất



Hey all to override a computed method we need to define the field again in the inherited class

class ProductTemplate(models.Model):
_inherit = 'product.template'
default_code = field.Char(compute='_compute_default_code')
@api.one
@api.depends('product_variant_ids', 'product_variant_ids.default_code')
def _compute_default_code(self):
print("overridden")






Ảnh đại diện
Huỷ bỏ
Bài viết liên quan Trả lời Lượt xem Hoạt động
2
thg 7 24
14094
1
thg 7 21
8281
0
thg 4 20
4771
1
thg 5 18
3089
0
thg 4 18
3570