콘텐츠로 건너뛰기
메뉴
커뮤니티에 참여하려면 회원 가입을 하시기 바랍니다.
신고된 질문입니다
2 답글
6404 화면

Dear All,

We are in development of store request module, that a department user request items to store and they will deliver based on the request. So in department module we created dept_location_id = fields.Many2one('stock.location', 'Department Location'). Its working fine. My problem is I need this value in my custom module store request. So i create a compute function in store request module. Raise error is showing correct location id, But the function is not returning any value. Any help is highly appreciated. Thanks.

 #---------------------------To find Department warehouse Location----------------------

    @api.one
    @api.depends('partner_id')
    def _compute_department_location(self):
   
        loc_id = 1
        if (self.partner_id.id == False):
            #self.department_id = None
            loc_id = None
            return
       
        employee = self.env['hr.employee'].search([('work_email', '=', self.partner_id.email)])
        if (len(employee) > 0):
            self.department_id = employee[0].department_id.id
            dept_id = self.env['hr.department'].search([('id', '=', self.department_id.id)])
            if (len(dept_id) > 0):
                loc_id = dept_id[0].dept_location_id.id
#              raise UserError(_('Test - %s') % loc_id)
            else:
                loc_id = None
        else:
 
            loc_id = None
#        raise UserError(_('Test - %s') % loc_id)
        return loc_id

    dept_location_id = fields.Many2one('stock.location', 'Department Location',
        compute='_compute_department_location',ondelete="cascade",store=True)



아바타
취소
베스트 답변

As a single compute function can be used to compute multiple fields, it doesn't return a value. Instead, the value should be assigned in the function. 

If you change return loc_id to self.dept_location_id = loc_id, it should write the value.
Note: Compute functions in v11 should be able to handle recordsets. You should wrap the body of the function with for rec in self and do the same logic using rec instead of self.

아바타
취소
작성자

Thanks Jake, Its working....

관련 게시물 답글 화면 활동
2
5월 25
881
1
11월 24
1126
0
7월 19
7975
2
3월 24
2011
9
6월 23
13077