How to pass id of the containing model in a from view to an action of another model in a notebook tree view in odoo 15

30 Views Asked by At

I have two models, say A and B. In the form view of a record of A, I have a notebook containing a tree view of records of model B. Each item in the tree view has a button action and I would like to pass A's id in the context when the action is called and use it in the backend to link A to B (i.e. set b_id FK on A)

Question is how to get the id of A, active_id in the context of the tree view refers to the current model B record. Also, tried to access any other field of A e.g. name_of_a in the tree view but the view raises an error that the field is not present.

How can I get this to work?

<field name="arch" type="xml">
      <form string="A">
        <header>
          <field name="state" widget="statusbar"/>
        </header>

        <sheet>
          <group name="main">
            <group>
              <field name="name_of_a"/>
            </group>
          </group>
          <notebook>
            <page string="B" name="b">
              <field name="customer_case_ids">
                <tree>
                  <field name="name_of_b"/>
                  <!-- active_id here is the id of the current record of model B, I want to pass id of A's record -->
                  <button name="action_create_link" type="object" string="Link" class="btn btn-link" icon="fa-link"
                          context="{'a': active_id}"/>
                </tree>
              </field>
            </page>
          </notebook>
        </sheet>
      </form>
    </field>
0

There are 0 best solutions below