Overslaan naar inhoud
Menu
Je moet geregistreerd zijn om te kunnen communiceren met de community.
Deze vraag is gerapporteerd
1 Beantwoorden
3012 Weergaven

Hello,

I have to models.

class HrClockImport (models.Model):   
     _name = "hr.clock.import"
    _description = "Clock Imported from Machine"
    _rec_name = 'employee_id'
    # to display as caption in a form

    hr_attendance_id = fields.Many2one ('hr.attendance', string = "Attendance")
    employee_id = fields.Many2one ('hr.employee', string = 'Employee')
    clockdatetime = fields.Datetime (string = "Clock")
    
class HrAttendance (models.Model):
    _inherit = "hr.attendance"
    hr_clock_import_ids = fields.One2many ('hr.clock.import', 'hr_attendance_id', string = "Import Clock Line")


Here are my code:

clockinout_dict = {'employee_id': emp3, 'check_in': clock3, 'check_out': clock4}
last_id = hr_attendance.create (clockinout_dict)



​​#update hr.clock.import:hr_attendance_id with the newly created attendance id
clock_obj = self.env['hr.clock.import'].search([('employee_id', '=', emp3),'|', ('clockdatetime', '=',clock3), ('clockdatetime', '=',clock4)])
if clock_obj:
     for clock in clock_obj:
          clock.hr_attendance_id = last_id.id   <----this does not work!


Thank you for your time to read. 

Any help will be greatly appreciated.






Avatar
Annuleer
Beste antwoord

Hi, Gain


Kindly try below code in order to achieve your requirement.

  • First search for the records from model "hr.clock.import" which you want to link in the model "hr.attendance"

clock_objs = self.env['hr.clock.import'].search([('employee_id', '=', emp3),'|', ('clockdatetime', '=',clock3), ('clockdatetime', '=',clock4)])
clock_ids = clock_objs.ids
  • Then create record in the table "hr.attendance",,

clockinout_dict = {
                   'employee_id': emp3,
                   'check_in': clock3,
                   'check_out': clock4,
                    'hr_clock_import_ids': [(6, 0, clock_ids)]    
            }
last_id = self.env['hr.attendance'].create(clockinout_dict)
Above steps are enough link your record.


Thanks,
Ashish Singh (Team Lead)
Webkul Software Private Limited


Avatar
Annuleer