function field

Asked by ange bouabre

Hi everybody, i'm new on openerp and i'm stopped in my work. i would like to do a field function which calculate the multiplication of others fields: this is my code:

 lass vigne_class(osv.osv):
    _name = 'vigne.class'

    def _devis_taillage_hectare(self,cr,uid,ids,field_names,context=None):
  res={}
  champs=self.browse(cr,uid,ids,context)
  for i in champs:
   res[i.id]=i.nbr_plantsfacture*i.prix1

  return res

    _columns = {
        'vigne_ids': fields.many2one('client.class',"Propriétaire", readonly=True, select=True, ondelete='cascade'),
        'nom': fields.char("Nom de vigne",size=64),
        'guyot':fields.selection([('s','Simple'), ('d','Double')],'Guyot'),
        'nbr_plantsfacture': fields.integer("Nombre de Plants facturé"),
        'prix1': fields.float("Prix",digits=(3,3),help="Prix du taillage"),

 I get an error when i update my module:
File "/usr/lib/pymodules/python2.6/openerp/sql_db.py", line 212, in execute
 res = self._obj.execute(query, params)
ProgrammingError: can't adapt

I need your help please!!!! :(

Question information

Language:
English Edit question
Status:
Answered
For:
Odoo Addons (MOVED TO GITHUB) Edit question
Assignee:
No assignee Edit question
Last query:
Last reply:
Revision history for this message
Damián Soriano (damiansoriano) said :
#1

Please correct me if I am wrong, but if you pass to "self.browse" a simple id instad of a list with a simple id, the function regutns one instance of a class and not a list of instances. Try doing this to see if it works:

....
champs = self.browse(cr,uid,ids,context)
if not isinstance(champs, list):
    champs = [champs]
....

Can you help with this problem?

Provide an answer of your own, or ask ange bouabre for more information if necessary.

To post a message you must log in.