Skip to Content
Menu
This question has been flagged
2 Replies
5505 Views

Hello everyone, I have 2 classes like in the picture.
In the overtime_detail class, I have created a list of records, all of which are defaulted in the "draft" state.


'' class overtime_detail (models.Model):
    _name = 'overtime_detail'
    _description = "More details"
    _rec_name = 'employee'

    employee = fields.Many2one (comodel_name = 'hr.employee', string = "Employee name", required = True)
    department = fields.Many2one (comodel_name = 'hr.department', string = 'Department', required = True)
    date = fields.Date (string = 'Overtime day', default = datetime.today (), required = True)
    ot_rate = fields.Float (string = 'Overtime rate')
    ot_time = fields.Integer (string = "Overtime", min = '0.5', max = '16 ', required = True)
    reason = fields.Char (string = "Reason for overtime", size = 100, required = True)
    status = fields.Selection (string = 'Status', selection = [('draft', 'Draft'),
                                                             ('wait', 'Wait for approval'),
                                                             ('done', 'Approved'),
                                                             ('reject', 'Rejected')], default = 'draft')

    management = fields.Many2one (comodel_name = 'overtime_management', string = 'Description') ''


In class overtime_management


class overtime_management (models.Model):
    _name = "overtime_management"
    _description = "Overtime ticket"
    _rec_name = 'department'

    subject = fields.Char (string = 'Description', required = True)
    department = fields.Many2one (comodel_name = 'hr.department', string = 'Department', required = True)
    date = fields.Date (string = 'Overtime day', required = True)
    ot_rate = fields.Float ("Overtime rate", required = True)
    ot_sum = fields.Float ("Total overtime", compute = '_ sum_ot')
    reason = fields.Char (string = 'Reason for overtime', size = 100, required = True)
    detail = fields.One2many (comodel_name = 'overtime_detail', inverse_name = 'management', string = "More details")
    status = fields.Selection (string = "Status", selection =
[('draft', 'Draft'),
                                                             ('done', 'Approved'),
                                                             ('reject', 'Rejected')], default = 'draft')

This class has a many2one relationship with overtime_detail. I want to create an "approved" button that converts the state of detail records in overtime_detail to "approved". Please help me. Thank you

Avatar
Discard

Look into odoo workflow: https://goo.gl/gYe8RL

Best Answer

Hi,

You can define a button for this and on clicking the button , you can call a python function, you can write the function like this,

def action_approve(self):
for rec in self:
for line in rec.detail:
line.status = 'done'

1. Control States and Statusbar Using Buttons

2.Button Types

Thanks

Avatar
Discard
Related Posts Replies Views Activity
2
Mar 23
7964
2
Mar 23
917
1
Nov 22
14654
3
Aug 22
10764
2
Aug 22
3054