This question has been flagged
1 Reply
3233 Views

I created a sequence field as a function field to show the number of records in browse starting from '1', regardless the 'id' value of the record.

I used the following code

    def _get_sequence(self, cr, uid, ids, fields, args, context=None):
        res={}
        line_o = self.pool.get('budget.transaction.line')
        for o in self.browse(cr,uid,ids):
            res[o.id] = 1+line_o.search_count(cr,uid,[('id','<',o.id)])
        return res
    _columns = {
...
ondelete='cascade', select=True, required=True), 'sequence': fields.function(_get_sequence,string='Sequence',type='integer', help="Gives the sequence order when displaying a list of lines."),

The issue with me now is that I need this numbering to be recalculated if I changed the filter of applied on the browse from the advanced search option. How to achieve this. Any help is appreciated.


Avatar
Discard
Best Answer

You need to declare a field preferably a dummy that no have a calculation method or you just simply forget about it, then you need to override the methods, read and read_group to assign the value to each record that you will display, a little more tricky is the read_group that will apply when you "group by" the data. The override methods need to assign the value of the field by an increment of the sequence value

Avatar
Discard

Also you need to take pagination into account