Skip to Content
Menú
This question has been flagged
1 Respondre
3898 Vistes
Hello,

I would like to modify the partner form in order to separate the display of contacts and addresses on 2 distinct tabs. My problem is when displaying the "child_ids" field. How to display only part of the records by filtering them?

Code to display only contact on first tab:
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<record model="ir.ui.view" id="society_res_partner_form">
<field name="name">society Partner Form Inherit</field>
<field name="model">res.partner</field>
<field name="inherit_id" ref="base.view_partner_form"/>
<field name="priority">100</field>
<field name="arch" type="xml">
<xpath expr="//field[@name='company_type']" position="attributes">
<attribute name="readonly">True</attribute>
</xpath>
<xpath expr="//page[1]" position="attributes">
<attribute name="string">Contacts</attribute>
<attribute name="attrs">{'invisible': [('is_company','!=',True)]}</attribute>
</xpath>
<xpath expr="//field[@name='child_ids']" position="attributes">
<attribute name="mode">tree</attribute>
<attribute name="domain">[('type', '=', 'contact')]</attribute>
<attribute name="context">{'default_type': 'contact'}</attribute>
</xpath>
<xpath expr="//field[@name='child_ids']/kanban" position="replace">
<tree>
<field name="name"/>
<field name="type"/>
<field name="company_type"/>
<field name="city"/>
<field name="email"/>
<field name="phone"/>
</tree>
</xpath>
</field>
</record>
</odoo>

The "<attribute name="domain">[('type', '=', 'contact')]</attribute>" as no effect,
all records are loaded, not just contacts.

Thank you
Avatar
Descartar
Autor Best Answer
Hello, 
As a simple modification of view is not enough, I added two fields. One for storing contact IDs, the other for addresses IDs. Then you have to modify the view to replace the standard tab with the two loaded with the new fields.

------------------resPartner model
from odoo import models, api, fields, _

Class ResPartner(models.Model):
_inherit = 'res.partner'

contact_ids = fields.One2many('res.partner', 'parent_id', string='Contacts',
domain=[('active', '=', True), ('type', '=', 'contact')])
adress_ids = fields.One2many('res.partner', 'parent_id', string='Adresses',
domain=[('active', '=', True), ('type', '!=', 'contact')])

-------------------resPartner view
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<record model="ir.ui.view" id="society_res_partner_form">
<field name="name">society Partner Form Inherit</field>
<field name="model">res.partner</field>
<field name="inherit_id" ref="base.view_partner_form"/>
<field name="priority">100</field>
<field name="arch" type="xml">
<xpath expr="//page[1]" position="replace">
<page name="contacts" string="Contacts" attrs="{'invisible': [('is_company','!=',True)]}">
<field name="contact_ids" mode="tree" context="{'default_parent_id': active_id, 'default_street': street, 'default_street2': street2, 'default_city': city, 'default_state_id': state_id, 'default_zip': zip, 'default_country_id': country_id, 'default_lang': lang, 'default_user_id': user_id, 'default_type': 'contact', 'default_company_type': 'person'}">
[...]
</field>
</page>
<page name="adresses" string="Adresses" attrs="{'invisible': [('is_company','!=',True)]}">
<field name="adress_ids" mode="tree" context="{'default_parent_id': active_id, 'default_street': street, 'default_street2': street2, 'default_city': city, 'default_state_id': state_id, 'default_zip': zip, 'default_country_id': country_id, 'default_lang': lang, 'default_user_id': user_id, 'default_type': 'delivery', 'default_company_type': 'person'}">
[...]
</field>>
</page>
</field>
</record>
</odoo>

Avatar
Descartar
Related Posts Respostes Vistes Activitat
0
de març 22
110
3
de març 15
8811
1
de març 15
5271
1
de jul. 25
2689
0
de febr. 24
1516