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.

1

Why do one2many fields return empty list?

By
Alcaline
on 10/9/14, 1:39 AM 714 views

Any one can help? In class "hr.employee" there is a one2many fields for "hr.payslip" w/c in turn has one2many fields for "hr.payslip.line". My problem is whenever i output employee's payslips it return nothing but my database is populated.

Here ismy code:

def load_employee(self,cr,uid,ids,context=None):
result = {}
total = 0.00
emp_ids = self.pool.get('hr.employee').search(cr,uid,[])
for emp in self.pool.get('hr.employee').browse(cr,uid,emp_ids,context=context):
pay_ids = self.pool.get('hr.payslip').search(cr,uid,[('employee_id','=',emp.id)],context=context)
netsvc.Logger().notifyChannel("OUT PUT ", netsvc.LOG_INFO, 'EMPL LIST ....' + str(emp_ids))
netsvc.Logger().notifyChannel("OUT PUT ", netsvc.LOG_INFO, 'ID ID ID ID :::::' + str(emp.id))
netsvc.Logger().notifyChannel("OUT PUT ", netsvc.LOG_INFO, 'PAY :::::' + str(pay_ids))
result={"value":{
'employee_id' : payslip_list
}}

return result


*** pay_ids shows nothing but an empty list ***
anyone can help? Please

1

Temur

--Temur--
2896
| 6 5 7
Tbilisi, Georgia
--Temur--
Programmer
Temur
On 10/9/14, 4:06 AM

Hi,

 

Once you've browsed for objects, like: for emp in self.pool.get('hr.employee').browse(cr,uid,emp_ids,context=context): -in your code, then you do NOT need another search like you have: pay_ids = self.pool.get('hr.payslip').search(cr,uid,[('employee_id','=',emp.id)],context=context), instead you should iterate over objects directly.

def load_employee(self,cr,uid,ids,context=None):
    result = {}
    total = 0.00
    emp_ids = self.pool.get('hr.employee').search(cr,uid,[])
    netsvc.Logger().notifyChannel("OUT PUT ", netsvc.LOG_INFO, 'EMPL LIST ....' + str(emp_ids))

    for emp in self.pool.get('hr.employee').browse(cr,uid,emp_ids,context=context):
        # -  pay_ids = self.pool.get('hr.payslip').search(cr,uid,[('employee_id','=',emp.id)],context=context)
        # Let's say one2many fields for "hr.payslip" in the class  "hr.employee" is named as: 'payslip_ids',  then:
        # (Please adapt it to your case)

        for pay in emp.payslip_ids:
            for pay_line in pay.line_ids:
                # + ...

        netsvc.Logger().notifyChannel("OUT PUT ", netsvc.LOG_INFO, 'ID ID ID ID :::::' + str(emp.id))
        # - netsvc.Logger().notifyChannel("OUT PUT ", netsvc.LOG_INFO, 'PAY :::::' + str(pay_ids))
        result={"value":{
            'employee_id' : payslip_list
        }}

return result

Try  approach like this.

 

regards,

thanks sir i will try this one..

Alcaline
on 10/9/14, 4:17 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: 10/9/14, 1:39 AM
Seen: 714 times
Last updated: 3/16/15, 8:10 AM