Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
1 Trả lời
7591 Lượt xem

Hello,

I'm trying to make a module to manage travel leaves for employees.

What I need t do is adding extra float field in hr.employee module of 'available_tickets' . To be allocated from other module named "travel_request". How t do this?


Here's my code:

class hr_employee(osv.osv):
_inherit="hr.employee"
_columns = {
        'available_tickets': fields.float("Available Tickets"),
}


class travel_request(osv.osv):

_name = 'travel.request'

def _get_tickets(self, cr, uid, ids, context=None):

emp_ticket = self.pool.get('hr.employee').browse(cr, uid, ids)

return emp_ticket.available_tickets

_columns = {

'no_tickets': fields.function(_get_tickets, string='Number of Tickets', type='float'),

     }


But it didn't work.. any idea how to fix it?

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

Hi Youta,

Just try to search 'hr.employee' based on any condition. And browse the records.

For ex:-

def _get_tickets(self, cr, uid, ids, context=None):

        hr_employee_obj = self.pool.get('hr.employee')

        res = {}

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

     emp_ticket_ids = hr_employee_obj.search(cr, uid, [], ids, context=None)

            emp_ticket = hr_employee_obj.browse(cr, uid, emp_ticket_ids[0], context=None)

            res['no_tickets'] = emp_ticket.available_tickets

        return res

Ảnh đại diện
Huỷ bỏ
Bài viết liên quan Trả lời Lượt xem Hoạt động
1
thg 4 25
3718
3
thg 12 22
11639
5
thg 4 24
42200
6
thg 4 24
39043
3
thg 3 24
10638