i'm using odoo 11. i have create a custom module for attendance modification request which be approuved by the manager of attendance . My goal is to limit the acces to the modification of attendance and when the manager press approuve "hr.attendance" will be modified automatically whith the new values of check_in and check_out (if it's the same employee and same date between "hr.attendance" and my request modification). The problem is when i press approuve there is no error but in the same time there is no modification. Here is my code. Any idea for help please ?
modification_request.xml
<record model="ir.ui.view" id="view_attendance_modification_request_form"> <field name="name">attendance.modification.request.form</field> <field name="model">attendance.modification.request</field> <field name="arch" type="xml"> <form string="Attendance modification Request"> <header> <field name="state" statusbar_visible="draft,waiting,approved,cancel" widget="statusbar" /> <button name="submit_modification" string="Submit for manager" type="object" class="btn-primary" attrs="{'invisible': [('state','not in','draft')]}"/> <button name="modification_approval" type="object" string="Approve" class="oe_highlight" groups="hr_attendance.group_hr_attendance_manager" attrs="{'invisible': [('state','not in','waiting')]}"/> <button name="modification_rejection" type="object" string="Cancel" class="oe_highlight" groups="hr_attendance.group_hr_attendance_manager" attrs="{'invisible': [('state','not in','waiting')]}"/> </header> <sheet> <h2> <group> <field name="employee_id"/> </group> </h2> <group col="4" colspan="4"> <field name="time_check_in_1"/> <field name="time_check_out_1"/> </group> <label for="note"/> <field name="note"/> </sheet> <field name="message_follower_ids" widget="mail_followers" groups="base.group_user"/> <field name="activity_ids" widget="mail_activity"/> <field name="message_ids" widget="mail_thread"/> </form> </field> </record>
modification_request.py
class AttendanceModificationRequest(models.Model): _name = 'attendance.modification.request' _description = 'Attendance modification Request' _inherit = ['mail.thread', 'mail.activity.mixin'] def _get_employee_id(self): employee_rec = self.env['hr.employee'].search([('user_id', '=', self.env.uid)], limit=1) return employee_rec.id employee_id = fields.Many2one('hr.employee',"Employee", readonly=True,default=_get_employee_id, required=True) user_id = fields.Many2one('res.users', string='User', track_visibility='onchange', readonly=True, states={'draft': [('readonly', False)]}, default=lambda self: self.env.user) state = fields.Selection([ ('draft', 'Pending'), ('waiting', 'Waiting for approval'), ('approved', 'Approved'), ('cancel', 'Cancelled')], readonly=True, help="Gives the state of the attendance request modification .", default='draft') modification_date = fields.Date("Date") time_check_in_1 = fields.Datetime("Check in") time_check_out_1 = fields.Datetime("Check out") note = fields.Text("Note") attendance_id = fields.Many2one('hr.attendance', string='Attendance') @api.multi def modification_approval(self): attend_signin_ids = self.env['hr.attendance'] check_in_date = datetime.strptime(self.time_check_in_1, "%Y-%m-%d %H:%M:%S").date() check_out_date = datetime.strptime(self.time_check_out_1, "%Y-%m-%d %H:%M:%S").date() for obj in attend_signin_ids : attendance_check_in_date = datetime.strptime(obj.check_in, "%Y-%m-%d %H:%M:%S").date() attendance_check_out_date = datetime.strptime(obj.check_out, "%Y-%m-%d %H:%M:%S").date() if (obj.employee_id == self.employee_id) and (check_in_date == attendance_check_in_date): obj.check_in = self.time_check_in_1 obj.check_out = self.time_check_out_1 return self.write({ 'state': 'approved' })