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 to put employee in other model.

By
wizardz
on 9/1/16, 3:03 AM 264 views

Hi, I tried to put the employee_id from hr.payslip model in the account_analytic_line in a new field called employee_test.

This is my code


# -*- coding: utf-8 -*-

from openerp import models, fields, api, osv

from openerp.http import request

from openerp import SUPERUSER_ID

class account_analytic_line(models.Model):

_inherit = ['account.analytic.line']

employee_id = fields.Char('test')

employee_test = fields.Integer(compute="employee")

@api.multi

def employee(self, ref):

cr, uid, context, pool = request.cr, request.uid, request.context,

objpayslip = self.pool.get('hr.payslip')

result = objpayslip.search_read(cr, SUPERUSER_ID, [('number', '=', ref)], [])

print result

return result.id


But I get error.

How can I fix this?

I tried this with the self.pool method too.


I have in 'account.analytic.line' a ref field, in 'hr.payslip' I have the number field.

The inside of these two fields is the same. I need to filter that and give the employee_id from 'hr.payslip' to the model 'account.analytic.line' model.

How can I make that work?


Sorry, Pls use the api as per the function.

eg:

@api.one

Premananth
on 9/2/16, 6:39 AM

with your function you have write down I get this error:

TypeError: search() takes at least 4 arguments (2 given)

wizardz
on 9/2/16, 8:16 AM

with my code I get this:

cr, uid, context, pool = request.cr, request.uid, request.context,

ValueError: need more than 3 values to unpack

wizardz
on 9/2/16, 9:19 AM
0
Premananth
On 9/1/16, 4:24 AM

Hi wizardz

can you show me the error message.


Hi wizardz:

can you try this .

def employee(self):

     objpayslip = self.pool.get('hr.payslip')

     if self.ref:

         result = objpayslip.search([('number', '=', self.ref)]) # i hope it should return one record   

       for record in objpayslip.browse(result):         

            return record.id

only 1 argument given. is the error.

I need to get the ref from 'account.analytic.line' and then look at 'hr.payslip' - number to get the employee_id there. Then I need to put the employee_id in a new field in 'account.analytic.line'

wizardz
on 9/1/16, 4:30 AM

I tried youre code, I get this error:

TypeError: search() takes at least 4 arguments (2 given)

wizardz
on 9/2/16, 3:08 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: 9/1/16, 3:03 AM
Seen: 264 times
Last updated: 9/1/16, 4:50 AM