[Python] How to dynamically adjust the selection?

Discussão em 'Python' iniciado por Stack, Maio 26, 2025.

  1. Stack

    Stack Membro Participativo

    I've been trying to do these, but as I've browsed the answers, most of these problem ended up with deprecated one, or simply no solution.

    job_id = fields.Many2one('inw_asset.job_orders', string='Service request', required=True, store=True)
    owner_id = fields.Many2one('res.users', string='Asset Owner', required=True, default=lambda self: self.env.user, readonly=True, store=True)
    person_in_charge = fields.Many2one('res.users', string='Engineer assigned', required=True, store=True)
    report_type = fields.Selection(selection=lambda self: self.get_report_type_list(), required=True, default='i')

    def get_report_type_list(self):
    user = self.env.user
    if self.env.user.has_group('inw_asset.administrator'):
    return [
    ('i', 'Information'),
    ('p', 'Progress'),
    ('r', 'Completion Report'),
    ('d', 'Delayed')
    ]
    elif self.env.user == self.owner_id:
    return [
    ('i', 'Information'),
    ('r', 'Completion Report'),
    ]
    elif self.env.user == self.person_in_charge
    return [
    ('i', 'Information'),
    ('p', 'Progress'),
    ('d', 'Delayed')
    ]
    else:
    return [
    ('i', 'Information')
    ]


    I tried this method, but it ended up as only i option. I have found some solution telling me to use domain, but it was not working, and when I searched why, it was noted that the method was deprecated.

    job_id is linked to the service report requested by the asset holder. Is there a way to restrict the user to pick the options, that is not deprecated? or using a transient record? Or anything?

    Continue reading...

Compartilhe esta Página