首页 > 解决方案 > 通过方法调用Odoo 10 python弹出窗口不会触发

问题描述

好的,这是我正在使用的代码。

@api.model
def _get_company(self):
    return self.env.user.company_id

company_id = fields.Many2one('res.company', string='Company', required=True, default=_get_company,
    help='The company this user is currently working for.', context={'user_preference': True})
company_ids = fields.Many2many('res.company', 'res_company_employees_rel', 'employee_id', 'cid',
    string='Companies', default='_get_company')

@api.multi
def select_location(self):
    return{
        'name': 'Select Location',
        'view_type': 'kanban',
        'view_mode': 'kanban',
        'target': 'new',
        'res_model': 'employment.locations',
        'type': 'ir.actions.act_window',
        'context':{
            'search_default_filter_company_id': self.company_ids,
        }
    }

@api.multi
def attendance_action_change(self):
    """ Check In/Check Out action
        Check In: create a new attendance record
        Check Out: modify check_out field of appropriate attendance record
    """
    if len(self) > 1:
        raise exceptions.UserError(_('Cannot perform check in or check out on multiple employees.'))
    action_date = fields.Datetime.now()

    if self.attendance_state != 'checked_in':
        location_id = select_location()
        vals = {
            'employee_id': self.id,
            'check_in': action_date,
            'location_id': location_id,
        }
        return self.env['hr.attendance'].create(vals)
    else:
        attendance = self.env['hr.attendance'].search([('employee_id', '=', self.id), ('check_out', '=', False)], limit=1)
        if attendance:
            attendance.check_out = action_date
        else:
            raise exceptions.UserError(_('Cannot perform check out on %(empl_name)s, could not find corresponding check in. '
                'Your attendances have probably been modified manually by human resources.') % {'empl_name': self.name, })
        return attendance

我试图让弹出 select_location() 在处理出席_action_change() 期间触发。有没有办法做到这一点,还是我在叫错树?

我在 xml 中创建了 ir.actions.act_window 和 ir.ui.view 记录,并创建了“employment.locations”模型并正常工作。

谢谢任何人的帮助。

标签: pythonpopupodoo-10

解决方案


推荐阅读