Перейти к содержимому
Меню
Чтобы взаимодействовать с сообществом, необходимо зарегистрироваться.
Этот вопрос был отмечен
2 Ответы
6313 Представления

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....

Related Posts Ответы Просмотры Активность
2
мая 25
756
1
нояб. 24
1014
0
июл. 19
7851
2
мар. 24
1856
9
июн. 23
12960