Odoo - Adding domain filters to tree views in tabs

Viewed 45

I am new to Odoo, but I have been tasked to create a tree view in the partners form. The tree view has to display a list of an individual's "active" contracts. Unfortunately, setting the domain logic on the tree view does not seem to work. What is the pattern for doing this in Odoo?

<record model="ir.ui.view" id="view_partner_form_inherit">
  <field name="name">res.partner.form.inherit</field>
  <field name="model">res.partner</field>
  <field name="inherit_id" ref="base.view_partner_form" />
  <field name="arch" type="xml">
    <notebook position="inside">
      <page string="Contracts">
        <field name="contract_ids">
          <tree domain="[('state', '=', 'active')]">
            <field name="state" invisible="1" />
            <field name="name" />
            <field name="arrears" />
            <field name="total_amount_paid" />
          </tree>
        </field>
      </page>
    </notebook>
  </field>
</record>
1 Answers

Atleast for One2many fields it should be possible by defining a field twice with different names and ofcourse one of them with the domain, for example:

contract_ids = fields.One2many(
    comodel_name="contract.model", inverse_name="inverse_id",
    string="All Contracts")
active_contract_ids = fields.One2many(
    comodel_name="contract.model", inverse_name="inverse_id",
    string="Active Contracts", domain="[('state', '=', 'active')]")

Related