Skip to Content
เมนู
คุณต้องลงทะเบียนเพื่อโต้ตอบกับคอมมูนิตี้
คำถามนี้ถูกตั้งค่าสถานะ
1 ตอบกลับ
4369 มุมมอง

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

ผู้เขียน

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

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

ผู้เขียน

with my code I get this:

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

ValueError: need more than 3 values to unpack

คำตอบที่ดีที่สุด

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'

ผู้เขียน

I tried youre code, I get this error:

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

Related Posts ตอบกลับ มุมมอง กิจกรรม
Employee to an other model แก้ไขแล้ว
1
ก.ย. 16
4108
1
ส.ค. 25
997
1
ก.ค. 25
1064
0
พ.ค. 25
979
Individual Payment Reconcile แก้ไขแล้ว
1
เม.ย. 25
2137