OpenERP: Simple use of fields. Function

I am trying to do some calculation of the fields of my object and save them in a new field. I start with a simple example of using the fileds.function, but when I try to login to openerp, the system raises an error that is incorrect for the user or password.

in my class I add a field:

      'a' : fields.integer('A'),
      'b' : fields.integer('B'),
      'total' : fields.function(fnct, method=True, string='Tot',type='integer'),

function definition:

       def fnct(self, cr, uid, ids, fields, arg, context):

          x = {}

          for record in self.browse(cr, uid, ids):

              x[record.id] = record.a + record.b

          return x

Please help me? thank

+5
source share
3 answers

There is no connection to a function registered with the OpenERP login.

So it’s possible that you are providing the wrong user ID or password.

The main field for using the function:

Automatically calculates field values ​​based on other fields.

ie Total = field1 + field2 + field3

:    'total': fields.function(get_total, method = True, string = 'Total', type = 'integer'),

:

def get_total(self, cr, uid, ids, fields, arg, context):

    x={}

    for record in self.browse(cr, uid, ids):

        x[record.id]= record.field1 + record.field2 + record.field3

    return x
+4

, , .

+2
def fnct(self, cr, uid, ids, fields, arg, context):

    x = {}

    for record in self.browse(cr, uid, ids):

    x[record.id] = record.a - record.b

if x[record.id]<0:

    raise osv.except_osv(("Warning"),("You Cant Subtract %s ")%(record.a - record.b))

else:


return x

    "a":fields.integer('A'),
    "b":fields.integer('B'),


 "total":fields.function(fnct, method=True, string='Total',type='integer'),
0
source

All Articles