在 Odoo Treeview 中,我可以像这样添加一个排序列:
<field name="sequence" widget="handle"/>
小部件句柄支持通过拖放自动排列序列。但是,如果我将第一项移动到另一个位置,则新的第一项的序列不是 1,而是另一个数字。我的问题是:
1.如何使第一项的序列始终为 1?
2. 有没有其他方法可以在Odoo Treeview中添加排序列?我只想要一列显示项目的行数。
这对我有用。
class TestModel(models.Model):
_name = 'test.model'
_description = 'test.model'
sequence = fields.Integer()
index = fields.Integer(compute='_compute_index')
@api.one
def _compute_index(self):
cr, uid, ctx = self.env.args
self.index = self._model.search_count(cr, uid, [
('sequence', '<', self.sequence)
], context=ctx) + 1
如果您在树中显示字段“索引”,它不会改变,您必须重新加载视图:(。