0

ok, So here's the code I'm working with.

@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

I'm trying to get the pop up select_location() to trigger during the processing of attendance_action_change(). Is there a way to do this or am I barking up the wrong tree?

I have the ir.actions.act_window and ir.ui.view records created in xml and the "employment.locations" model created and working.

Thank you anyone for help.

Cristin Meravi
  • 343
  • 2
  • 12

0 Answers0