I try to implement numbering positions in invoices. I got a field "position" in the one2many field and it looks like this
<field name="invoice_line" widget="one2many_list" context="{'type': type,'order_id':active_id}">
<field name="position"/>
(..)
My class
class account_invoice_line(osv.osv):
_inherit = 'account.invoice.line'
_columns = {
'position': fields.char('Position'),
}
def position_number(self, cr, uid, context=None):
return ACTUAL ROW NUMBER
_defaults = {
'position': lambda obj, cr, uid, context: obj.position_number(cr, uid, context),
}
account_invoice_line()
I have no Idea how to get the actual row number or how to count the rows. I found this, but it's not working :-/
def _default_sequence(self, cr, uid, context=None):
if context is None:
context = {}
max_sequence = 0
if context.get('order_id'):
sale_order_line_ids = self.search(cr, uid, [('order_id', '=', context['order_id'])])
if sale_order_line_ids:
max_sequence = max([line['position'] for line in self.read(cr, uid, sale_order_line_ids, ['position'])])
return max_sequence + 1
_defaults = {
'sequence': lambda obj, cr, uid, context: obj._default_sequence(cr, uid, context),
}
Can anybody help me?