好的,所以这是我正在使用的代码。
@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
我正在尝试在处理attendance_action_change()期间触发弹出的select_location()。有没有办法做到这一点,还是我咆哮错误的树?
我在xml中创建了ir.actions.act_window和ir.ui.view记录,并创建并使用了“employment.locations”模型。
感谢任何人的帮助。