跳至內容
選單
此問題已被標幟
1 回覆
3883 瀏覽次數
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
頭像
捨棄
作者 最佳答案
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>

頭像
捨棄
相關帖文 回覆 瀏覽次數 活動
0
3月 22
110
3
3月 15
8802
1
3月 15
5264
1
7月 25
2671
0
2月 24
1502