Reputation: 1254
In Odoo Treeview, I can add a sequencing column like this:
<field name="sequence" widget="handle"/>
The widget handle support auto arrange sequences by drag and drop.
But if I shift the first item to another position, the new first item's sequence isn't 1 but another number. My question is:
1. How can I make the first item's sequence is always 1?
2. Is there any other way to add a sequencing order column in Odoo Treeview? I just want a column to show row num of items.
Upvotes: 1
Views: 4632
Reputation: 79
This works for me.
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
If you show the field "index" in the tree, it won't change, you have to reload the view :(.
Upvotes: 2