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

How can I display the value of a computed field in a form?

By
E.M.
on 2/7/16, 10:04 AM 363 views

When loading a register with a computed field (example, a new sale margin field computed out of price and cost), I see that it is not populated with the value. Why? and how can I make the value being displayed?

It is properly stored in database.


you can use the onchange to trigger the computation for client side (form view)

Jérémy Kersten (jke)
on 2/7/16, 12:56 PM
0
Vishal Gediya
On 2/8/16, 1:40 AM

Hello E.M.


To write a on_change method in .py file like this,

def on_change_emp_dept(self, cr, uid, ids, employee_id, context=None):
dept_id = False
if employee_id:
emp_pool = self.pool.get("hr.employee")
emp_obj = emp_pool.browse(cr, uid, employee_id, context=context)
dept_id = emp_obj and emp_obj[0].department_id.id or False
return {'value':{'department_id':dept_id}}

Invoke method in .xml file write like this,
<field name="employee_id" on_change="on_change_emp_dept(employee_id)" />

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: 2/7/16, 10:04 AM
Seen: 363 times
Last updated: 2/8/16, 1:40 AM