Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OpenERP :Simple use of fields.function

Tags:

python

openerp

I try to make some calculation of fields of my object and store them to a new field. I'm beginning with a simple example of using fileds.function, but when I try to login to openerp, the system raise an error that the user or password is incorrect.

in my class I add the field:

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

definition of the function:

       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 ,can anyone help me ? thanks

like image 294
Spirit angel Avatar asked May 09 '12 22:05

Spirit angel


2 Answers

To fix that issue, I check for some intendation and also the definition of my function should be before declaration of fields .

like image 42
Spirit angel Avatar answered Oct 09 '22 14:10

Spirit angel


There is no Connection of Function Filed with OpenERP Login.

So It may be possible that you are providing wrong user id or password.

The Main Use of Function Field is:

Auto Calculate Value of the field based on other Fields.

i.e Total = field1 + field2 + field3

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

How to define Function:

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
like image 200
Avadhesh Avatar answered Oct 09 '22 14:10

Avadhesh