[Python] How to get models id CRM in inherit

Discussão em 'Python' iniciado por Stack, Março 3, 2025.

  1. Stack

    Stack Membro Participativo

    I have a problem in odoo 18, I want to move Activity into page tab, but when I try to create or update, I got error like this image

    [​IMG]

    I have tried some solutions, but it's still not work, This is one of my solution, any can help me to fix this?

    My model:


    class Lead(models.Model):
    _inherit = "crm.lead"

    models_id = fields.Integer(lambda self: self._get_model_id())

    def _get_model_id(self):
    ir_model = self.env['ir.model'].search([('model', '=', 'crm.lead')], limit=1)
    if not ir_model:
    raise ValueError("Could not find the 'crm.lead' model in ir.model.")
    return ir_model.id



    and this is my XML code

    <xpath expr="//page[@name='lead']" position="after">
    <page name="activity" string="Activity">
    <field name="activity_ids" widget="one2many_list" context="{'default_res_model_id': models_id }">
    <list>
    <field name="activity_type_id" string="Type"/>
    <field name="summary" string="Deskription"/>
    <field name="date_deadline" string="Planned Start Date"/>
    <field name="state" string="Status"/>
    </list>
    </field>
    </page>
    </xpath>

    Continue reading...

Compartilhe esta Página