This question has been flagged
2 Replies
3431 Views

I have added one column named as "line_no" in POLine. Im trying to get the below structure. Please anyone help me

 PO0001      PO0002    PO0003  
   Line      Line      Line
    1          1        1
    2          2        2
    3                   3

My code:

def default_get(self, cr, uid, ids, context=None):
    res = {}
    next_no = 0;
    next_line_no  =1
    value=self.browse(cr,uid,ids,context=context)
    obj = value[0]
    next_no = next_no + value.next_line_no
    total =+ next_no                
    res={
       'next_line_no':next_no,
       'line': total
        }
    return res

  _columns={
   'next_line_no':fields.integer(' Next Line No'),
   'line_no':fields.function(_get_line_no,string='Line No',type='integer'),
   }

Im getting error:

    TypeError: %d format: a number is required, not unicode

Another Question

I will get order and order Id in another class by using below format

    record_id = context.get('active_id')
    orderid= self.pool.get('purchase.order.line').browse(cr, uid, record_id)
    order = self.pool.get('purchase.order').browse(cr, uid, move_obj.order_id.id)

In Order Line Class How do get Order and Order Line ID.

Avatar
Discard
Best Answer

Hello

1."TypeError: %d format: a number is required, not unicode"

ur column datatype is integer , and u passing character value in it. u have to type cast before u pass the value in integer field by int(val)

1.1 "In Order Line Class How do get Order and Order Line ID"

 class orderline():

def get_orderline(self,cr,uid,ids,context):

   // here ids will be ur current orderline id

    po_order=self.browse(cr,uid,ids)[0] .order_id

   po_name=self.pool.get('purchase.order').browse(cr,uid,po_order)[0].name

  // po_name will give order name  i.e PO00001
Avatar
Discard
Author Best Answer

I got this by using below code:

def _get_line_no(self, cr, uid, ids, line_no, arg, context=None):
res = {}
for record in self.browse(cr, uid, ids, context=context):                     
    nextno =0
    no = record.next_line_no        
    next_no = nextno + no
    total += next_no
    res[record.id]={
              'next_line_no':next_no,
              'line_no': total
    } 
return res

_columns = {
'line_no':fields.function(_get_line_no,string='Line No',type='integer', multi="lineno"),
'next_line_no':fields. function(_get_line_no,string='Next Line No',type='integer', multi="lineno", store=True),
}
_defaults = {
  'next_line_no':1  
 }
Avatar
Discard