[Python] How to compute on load?

Discussão em 'Python' iniciado por Stack, Junho 1, 2025.

  1. Stack

    Stack Membro Participativo

    I have a model like this:

    # Calculated Fields
    request = fields.Many2one('job.request', string='Request', required=True)
    e_name = fields.Char('Nama Asset', store=False, compute="_compute_initial")

    @api.depends('request')
    def _compute_initial(self):
    for record in self:
    r = record.request
    record.e_name = r.equipment_id.name


    And I need to assign a value to e_name, taken from its parent, for display purposes only, as equipment from "job.request". The problem is that _compute_initial doesn't get executed, even though I've put the e_name field on the form, the value is empty.

    So, how to execute _compute_initial to fill in the e_name field?

    Continue reading...

Compartilhe esta Página