This question has been flagged
2 Replies
2224 Views

i want to declare a function


_columns = {

        'preno_emp_ar': fields.Char(

            'الاسم'),

        'nom_emp_ar': fields.Char(

            'النسب'),

        'complete_name_ar': fields.function(

            _get_full_name_ar, string='الاسم الكامل', type='char', store={

                'hr.employee': (_update_fill_name_ar, [

                    'complete_name_ar', 'preno_emp_ar', 'nom_emp_ar'],

                    50),

            }, method=True, help='Full arabic name of employee'),

    }



and i get this error module 'odoo.fields' has no attribute 'function'
is there any methode to declare the function ? 



Avatar
Discard
Author Best Answer

i defined the function name like this 


class Hr_Employee(osv.Model):

    _inherit = "hr.employee"


    def _get_full_name_ar(self, cr, uid, ids, fields_name, args, context=None):

        if context is None:

            context = {}

        res = {}

        for emp in self.browse(cr, uid, ids, context=context):

            res[emp.id] = (emp.preno_ar or '') + ' ' + (

                emp.nom_ar or '')

        return res


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

        return ids


    _columns = {

        'preno_ar': fields.Char(

            'الاسم'),

        'nom_ar': fields.Char(

            'النسب'),

        'complete_name_ar': fields.function(

            _get_full_name_ar, string='الاسم الكامل', type='char', store={

                'hr.employee': (_update_fill_name_ar, [

                    'complete_name_ar', 'preno_ar', 'nom_ar'],

                    50),

            }, method=True),

    }


so how is the right way to declare the function inside _columns attribute ? 

Avatar
Discard

this is the coding structure used in old versions i think, if you have time have a look at the video to see how to define a compute field and its function

Author

based on the video i change my code to the following

class Hr_Employee(osv.Model):

_inherit = "hr.employee"

@api.depends('preno_ar', 'nom_ar')

def _get_full_name_ar(self):

self._get_full_name_ar = (self.preno_ar or '') + ' ' + (self.nom_ar or '')

_columns = {

'preno_ar': fields.Char(

'الاسم'),

'nom_ar': fields.Char(

'النسب'),

'complete_name_ar': fields.Char(

'الاسم الكامل', compute= '_get_full_name_ar', store="True")

}

but i get 'preno_ar' fields dosen't exsist

can you define a field like this without using columns, i think you have defined fields correctly in your previous questions,

preno_ar = fields.Char(string='PreNo Ar', compute='_get_full_name_ar')

Author

i tried this but unfortunatly the module won't be installed and the system stops 'conexion lost'

class hr_corp(models.Model):

_inherit = "hr.employee"

@api.depends('preno_emp_ar', 'nom_emp_ar')

def get_full_name_ar(self):

self._get_full_name_ar = (self.preno_emp_ar or '')+' '+(self.nom_emp_ar or '')

preno_emp_ar = fields.Char(string="الاسم")

nom_emp_ar = fields.Char(string="النسب")

complete_name_ar = fields.Char(string="الاسم الكامل", compute= 'get_full_name_ar', store="True")

Best Answer

Hi,

This has got removed in latest versions,

``fields.related`` and ``fields.function`` are replaced by using a normal
field type with either a ``related=`` or a ``compute=`` parameter

Try to define the compute field, for more details on how to add a compute field, see this: How to Write Compute Field and its Function


Thanks

Avatar
Discard