1

在此处输入图像描述我是 Odoo 的新手,可以自定义当前卡在 Many2one 字段上。按照我正在处理的代码片段:

这是我的 Python 代码:

我的 One2many 领域:

field_contacts_customer_info = fields.One2many(
        'contacts.customer.information', 'another_id', string='Contacts for customer information')

我的课:

class ContactsCustomerInformation(models.Model):
    _name = 'contacts.customer.information'
    _rec_name = 'name_contacts'

    name_contacts = fields.Many2one(
        'res.partner', string="Person", domain="[('is_company' , '=' , False)]")

    mail_contacts = fields.Char(
        related = 'name_contacts.email' ,string="Email")

    another_id = fields.Many2one('res.partner', string="AnotherID")

    @api.onchange('name_contacts')
    def onchange_name_contacts(self):
        if self.name_contacts:
            if self.name_contacts.email:
                self.mail_contacts = self.name_contacts.email

还有我的 XML:

    <page name="contacts_customer_information" string="Contacts for customer information" attrs="{'invisible': [('is_company','=', False)]}">
                    <field name="field_contacts_customer_info">
                        <tree editable="bottom">
                            <field name="name_contacts"/>
                            <field name="mail_contacts" domain="[('is_company' , '=' , False)]"/>
                            <field name="another_id" invisible="1"/>
                            <field name="versuch" invisible="1"/>
                        </tree>
                            <form>
                                <group>
                                    <group>
                                        <field name="name_contacts" domain="[('is_company' , '=' , False)]"/>
                                    </group>
                                    <group>
                                        <field name="mail_contacts" domain="[('is_company' , '=' , False)]"/>
                                    </group>
                                </group>
                            </form>
                    </field>
                </page>

目前我只有一个条件,那就是在 Many2one 字段中没有显示公司,只有个人。我还想仅显示属于您当前所在视图的公司的个人。我知道我必须将其与 AND 条件联系起来。

什么情况下只显示当前显示公司的个人?

谢谢。

在此处输入图像描述

4

1 回答 1

0

我想你有与 res.partner 相关的公司字段。然后如果你想显示属于这家公司的个人,试试这个

class ContactsCustomerInformation(models.Model):
    _name = 'contacts.customer.information'
    _rec_name = 'name_contacts'


        
    name_contacts = fields.Many2one(
        'res.partner', string="Person", domain=[('parent_id','=',another_id)])

    mail_contacts = fields.Char(
        related = 'name_contacts.email' ,string="Email")

    another_id = fields.Many2one('res.partner', string="AnotherID")

    @api.onchange('name_contacts')
    def onchange_name_contacts(self):
        if self.name_contacts:
            if self.name_contacts.email:
                self.mail_contacts = self.name_contacts.email

于 2021-11-23T03:21:08.270 回答