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

In sale.order we can sort the list view by sale order name. Likewise i need to make a field sortable in odoo16.
i tried this code,


from odoo import models, fields, api


class PricelistItem(models.Model):
_inherit = "product.pricelist.item"
_order = 'custom_name, id desc'

custom_name = fields.Char('Custom name', compute="_compute_custom_name")

@api.depends('name')
def _compute_custom_name(self):
for rec in self:
if rec:
rec.custom_name = rec.name

i need to sort name field in model product.pricelist.item,
thanks in advance.

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

Sorting is currently only supported on stored fields.

Computed fields are not stored by default, they are computed and returned when requested. 

Setting store=True will store them in the database and automatically enable sorting.

See also https://www.odoo.com/documentation/17.0/developer/reference/backend/orm.html#computed-fields


Ảnh đại diện
Huỷ bỏ
Bài viết liên quan Trả lời Lượt xem Hoạt động
1
thg 5 25
2455
1
thg 4 25
3474
1
thg 4 25
4303
1
thg 4 25
1780
4
thg 3 25
6890