Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

0

ODOO: FIELDS TYPE FUNCTION

By
Drees Far
on 7/28/16, 4:51 AM 278 views

Hello Guys!!!

I have a field defined with function type.

Here is the code:

    def _get_prime_code(self, cr, uid, ids, field_name, arg, context=None):

        res = {}

        obj_contract = self.pool.get('hr.contract')

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

            contract_ids = obj_contract.search(cr, uid, [('id', '=', emp.employee_id.contract_id.id)], context=context)

            if contract_ids:

            vals = obj_contract.read(cr,uid,contract_ids,['id','adjustment_prime'],context=context)

            if vals[0]['adjustment_prime']:

                res[emp.id] = vals[0]['adjustment_prime'][0]

            else:

                res[emp.id] = False

            print res

        return res


and the field:

         'adjustment_prime_code':fields.function(_get_prime_code, string="Code de prime de compensation", type='integer', relation="hr.contract", help="Code de prime de compensation"),

the problem is that nothing appears in the field in the view.

DId i a mistake.

Can anyone help please.

Why are you using type='integer'? This is a many2one field

Francesco OpenCode
on 7/28/16, 5:51 AM

i have changed it to many2one but it still not working

Drees Far
on 7/28/16, 6:42 AM

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

Asked: 7/28/16, 4:51 AM
Seen: 278 times
Last updated: 7/28/16, 5:50 AM