Odoo is the world's easiest all-in-one management software. It includes hundreds of business apps:
CRM | e-Commerce | Accounting | Inventory | PoS | Project management | MRP | etc.
I have found in official addons that even though a record has a reference to other records (like one2many), and they already have a browse record with the required information, the programmer still uses the search function to get the list of ids from the database.
hr_employee has a field
contract_ids, that is a one2many relationship to
If I already have
employee_data = employee_obj.browse( blah, blah, blah...)
and I want to access the list of contracts for that employee, what is the right way to get it:
a) Use the list I already have on employee_data.contract_ids and get the information from there,
b) Execute a search on contract object looking for contracts related to the employee, like:
contract_ids = obj_contract.search(cr, uid, [('employee_id','=',emp.id),], context=context)
I would think option a), but I have found that in most cases option b) is used in official addons, so I guess there is a reason for that...
What are cons and pros of each aproach ?
if you already have that, and no realy need, replace it by a read
employee_data = employee_obj.browse( cr, uid, ids, context=context)
for employee in employee_obj.read( cr, uid, ids, ['contract_ids'], context=context): #So in employee['contract_ids'], you have a list of all contract id for this employee
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 platform 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.Register
Odoo Training Center
Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.Test it now
|Asked: 4/10/13, 4:00 AM|
|Seen: 9871 times|
|Last updated: 11/28/16, 8:41 AM|