Skip to Content
Menu
This question has been flagged
1 Reply
3921 Views

hi in hr expense i add a new field in hr.expense.line named caissier_id i wanna that on adding a new element on expense.line , caissier_id get the value  of , employee_id,


so in the hr_expense_line classe i tried some functions like that 

function 1 :

def _employe_get(self, cr, uid, context=None):

        res = {}

        for record in self.browse(cr, uid, context=context):

            payslip_obj = self.pool.get('hr.expense.expense')

            payslip = payslip_obj.search([('id', '=', record.expense_id)], limit=1)

            if payslip:

                res[record.caissier_id] = payslip.employee_id.id

        return res

this : retun nothing.

function 2 :

def _get_cur(self, cr, uid, context=None):

        user = self.pool.get('hr.expense.expense').browse(cr, uid,[uid], context=context)[0]

        return user.employee_id.id


this return a value  that not the same as employe_id

function 3 :

def _employe1_get(self, cr, uid, id, context=None):

        res = []

        holiday_obj = self.pool['hr.expense.expense']

        holiday_ids = holiday_obj.search(cr, uid, [], context=context)

        holiday_datas = holiday_obj.browse(cr, uid, id, context=context).employee_id

        for holiday in holiday_datas:

            res.append({'caissier_id': holiday.employee_id})

        return res


i get this error :

ValueError

Expected singleton: hr.expense.expense(u'lang', u'currency_id', u'tz', u'uid', u'default_analytic_account', u'caissier_id')


so can anyone help me or guid me , thnak you in advance

Avatar
Discard
Best Answer

In function 1 : please check if it is getting inside the if condition

here is an example for adding a new value to a dict

res['mynewkey'] = 'mynewvalue'

In function 2 : uid is used for current user id .You are using it to browse hr.expense.expene module with id that of current user. I think you should use search method if you are trying to get expense with current user

In function 3 : I dont understand what you are trying to achieve. what you are doing is that passing all values in employee_id to res and returning it.

Avatar
Discard