This question has been flagged
5 Replies
17914 Views

class si(osv.osv):
        _name='si'
        _columns ={

'street':fields.char('Street',size=100,required=True),

}

  def btnSet(self,cr,uid,ids,values,context=None):

 

self.pool.get('res.partner').write(cr,uid,ids,{'street2':street},context=context)

return True

 

si()

 

why i got this error? 

self.pool.get('res.partner').write(cr,uid,ids,{'street2':street},context=context) NameError: global name 'street' is not defined

 

I just want to transfer the value from my 'street' field to the res_partner's street2 field. 

 

 

Avatar
Discard
Best Answer

Try this

def btnSet(self,cr,uid,ids,values,context=None):
     current_obj = self.browse(cr, uid, ids, context)
     street = current_obj.street
# we have to get the street value from the current record
     self.pool.get('res.partner').write(cr,uid,ids,{'street2':street},context=context)
return True

Avatar
Discard
Author

it works atchuthan thanks! can i ask question, whats the purpose of context parameter why is it not context=None or context=context..

Author

it works atchuthan thanks! can i ask question, whats the purpose of context parameter why is it not context=None or context=context..

Author

oh isee i now get it thanks atchuthan!

Best Answer

hi atchutan i try this 

def _get_tot(self,cr,ids,values,context):

current_obj = self.browse(cr, uid, ids, context)

idstate = current_obj.id

cr.execute("SELECT sum(amount) FROM account_bank_statement_line WHERE statement_id ="+str(idstate)+"")

return cr.fetchall()


i get this error : _get_tot() takes exactly 5 arguments (4 given) 

can u help 

Avatar
Discard

Hi Najlae, please check your method you missed uid at method definition.

it should be like : def _get_tot(self,cr,uid,ids,values,context):

Eventhough, the method you mentioned above does not looks fine,what is your actual requirement, better to use odoo ORM method instead of using postgres queries.

hi Raaj actually i work on odoo 8 .. in acount.bank.satement.line i add new column name's(Montant crédit 'like amount field') i wanna to get the sum without using <field name="x" sum="x"/> , because i will use the sum to calculate the diffrence .. u can check this link : http://stackoverflow.com/questions/41368634/get-sum-of-the-column-in-odoo8/41373263?noredirect=1#comment70096973_41373263