Search code examples
pythonodoo

How to open list form from other form(odoo 12)


Add button to the form "product.product_template_form_view"

<?xml version="1.0" encoding="utf-8"?>
<odoo>
  <data>

    <act_window
      id="attach_pdf_action"
      name="Attach PDF"
      res_model="attach.pdf" />

    <menuitem
      id="attach_pdf_menu"
      name="Attach PDF"
      action="attach_pdf_action"
      parent=""
      sequence="5" />

    <record id="attach_pdf_view_form" model="ir.ui.view">
      <field name="name">Attach PDF Form</field>
      <field name="model">attach.pdf</field>
      <field name="arch" type="xml">
        <form>
          <group>
            <field name="product_id"/>
            <field name="product_attribute_value_id"/>
          </group>
          <group>
            <field name="file" widget="binary" filename="file_name" string="Binary"/>
          </group>
        </form>
      </field>
    </record>

    <record id="library_book_view_tree" model="ir.ui.view">
      <field name="name">Attach PDF List</field>
      <field name="model">attach.pdf</field>
      <field name="arch" type="xml">
        <tree>
          <field name="product_id"/>
          <field name="product_attribute_value_id"/>
          <field name="file_name" readonly="1"/>
        </tree>
      </field>
    </record>

    <record id="attach_pdf_view_search" model="ir.ui.view">
      <field name="name">Attach PDF Search</field>
      <field name="model">attach.pdf</field>
      <field name="arch" type="xml">
        <search>
          <field name="product_id"/>
          <field name="product_attribute_value_id"/>
        </search>
      </field>
    </record>

    <record id="view_form_product_attr_pdf" model="ir.ui.view">
      <field name="name">attach_pdf_attribute_product_product_template_only_form_view</field>
      <field name="model">product.template</field>
      <field name="inherit_id" ref="product.product_template_form_view"/>
      <field name="arch" type="xml">
        <xpath expr="//header/button[@name='121']" position="after">
          <button name="%(attach_pdf_attribute.attach_file_wizard)d" string="Attach PDF" type="action" class="oe_highlight"/>
        </xpath>
      </field>
    </record>

    <record id="attach_file_wizard" model="ir.actions.act_window">
      <field name="name">Attach PDF</field>
      <field name="type">ir.actions.act_window</field>
      <field name="res_model">attach.pdf</field>
      <field name="view_mode">tree, form</field>
      <field name="view_id" ref="library_book_view_tree"/>
    </record>

  </data>
</odoo>

When I click on the button, the list form of my custom module should open ("library_book_view_tree"). But I get error: "External ID not found in the system: attach_pdf_attribute.attach_file_wizard" while parsing file:/c:/program%20files%20(x86)/odoo%2012.0/server/odoo/custom_addons/attach_pdf_attribute/views/views.xml:59, near Why?


Solution

  • Try with change sequence of your code. Other then that your code looks good.

    For example:

    <record id="attach_file_wizard" model="ir.actions.act_window">
      <field name="name">Attach PDF</field>
      <field name="type">ir.actions.act_window</field>
      <field name="res_model">attach.pdf</field>
      <field name="view_mode">tree, form</field>
      <field name="view_id" ref="library_book_view_tree"/>
    </record>
    
    <record id="view_form_product_attr_pdf" model="ir.ui.view">
      <field name="name">attach_pdf_attribute_product_product_template_only_form_view</field>
      <field name="model">product.template</field>
      <field name="inherit_id" ref="product.product_template_form_view"/>
      <field name="arch" type="xml">
        <xpath expr="//header/button[@name='121']" position="after">
          <button name="%(attach_pdf_attribute.attach_file_wizard)d" string="Attach PDF" type="action" class="oe_highlight"/>
        </xpath>
      </field>
    </record>
    

    Keep in mind that we always should introduce new XML ID first and then use reference.