You need to enable JavaScript to run this app.
最新活动
大模型
产品
解决方案
定价
生态与合作
支持与服务
开发者
了解我们

如何在Odoo的member_id字段上显示自定义表单视图而非res.partner视图?

How to Open a Custom Form View for member_id in Helpdesk Tickets

Got it, let's tackle this! You’ve added a member_id field to helpdesk.ticket pointing to res.partner (filtered to individual persons), but clicking it still pulls up the default res.partner form view. Here are two reliable methods to force it to use your custom member-specific view:

Method 1: Directly Specify Views in the Form Field

This is the quickest fix—you can override the member_id field’s XML definition to explicitly tell Odoo which view to load.

Step 1: Build Your Custom res.partner Form View

First, create the custom form view tailored to your members (only include fields relevant to individuals from your Building module):

<record model="ir.ui.view" id="res_partner_member_custom_form">
    <field name="name">Member Custom Form</field>
    <field name="model">res.partner</field>
    <field name="arch" type="xml">
        <form string="Member Details">
            <sheet>
                <group col="4">
                    <field name="name" required="1"/>
                    <field name="email"/>
                    <field name="phone"/>
                    <!-- Add any member-specific fields from your Building module here, e.g., membership IDs, office info -->
                    <field name="company_type" invisible="1"/>
                </group>
                <!-- Add more sections as needed for member data -->
            </sheet>
        </form>
    </field>
</record>

Step 2: Update the member_id Field in Your Helpdesk View

Modify your existing helpdesk ticket form view to add the views attribute to the member_id field. This tells Odoo to prioritize your custom form view:

<record model="ir.ui.view" id="create_ticket_inherit_view">
    <field name="name">Create Ticket</field>
    <field name="model">helpdesk.ticket</field>
    <field name="inherit_id" ref="helpdesk_basic.view_helpdesk_form"/>
    <field name="arch" type="xml">
        <!-- Your existing button box modification stays here -->
        <xpath expr="//div[@name='button_box']/button[@name='action_get_attachments']" position="after">
            <button class="oe_stat_button" name="on_assigned" type="object" icon="fa-tasks">
                <field name="assigned" widget="statinfo"/>
            </button>
        </xpath>
        
        <xpath expr="//field[@name='priority']" position="after">
            <!-- Add the views attribute to link your custom form -->
            <field name="member_id" 
                   views="[(res_partner_member_custom_form, 'form'), (False, 'tree')]"/>
            <field name="office_no"/>
            <field name="floor"/>
            <field name="raised_by"/>
        </xpath>
    </field>
</record>
  • The views attribute uses a tuple list: (view_id, view_type). Here we set your custom form as the default, with the standard tree view as a fallback.
  • Double-check that the view ID res_partner_member_custom_form matches the one you created in Step 1.

Method 2: Use a Custom Action (For More Control)

If you need extra flexibility—like applying default filters, setting specific context values, or reusing the view elsewhere—create a dedicated action and link it to the field.

Step 1: Create the Custom Action

Define an ir.actions.act_window that points to your custom form view:

<record model="ir.actions.act_window" id="action_open_member_form">
    <field name="name">View Member Details</field>
    <field name="res_model">res.partner</field>
    <field name="view_mode">form</field>
    <field name="view_id" ref="res_partner_member_custom_form"/>
    <!-- Optional: Re-enforce the person filter here as a safety -->
    <field name="domain">[('company_type', '=', 'person')]</field>
</record>

You can do this either in Python code or the XML view:

Option A: In Python

Update your member_id field definition to reference the action:

class CreateTicket(models.Model):
    _inherit = 'helpdesk.ticket'
    member_id = fields.Many2one(
        'res.partner', 
        string="Member", 
        domain=[('company_type', '=', 'person')],
        # Link the custom action here
        action='action_open_member_form'
    )
    # Your other fields remain the same...
    office_no = fields.Char(string="Office No")
    floor = fields.Char(string="Floor")
    raised_by = fields.Char(string="Raised By")
    assigned = fields.Char('Assigned')

    @api.onchange('member_id')
    def onchange_member_id(self):
        obj=self.env['res.contract'].search([('membership_id','=',self.member_id.id)])
        self.floor = obj.sector_id.name
        self.office_no = obj.inventory_id.id

Option B: In XML View

Alternatively, set the context to load your custom view directly:

<field name="member_id" context="{'form_view_ref': 'your_module_name.res_partner_member_custom_form'}"/>
  • Replace your_module_name with the actual name of the module where you saved the custom view.

Quick Checks Before Testing

  • Make sure both your custom view and action are listed in your module’s __manifest__.py under the data key (so Odoo loads them).
  • Upgrade your module after making these changes to apply the updates.
  • If your Building module adds unique fields for members, include them in the custom form view to make it fully functional for your team.

Once you’ve done this, clicking member_id in a helpdesk ticket should pull up your custom member form view instead of the default res.partner one!

内容的提问来源于stack exchange,提问作者Syed Hamza Bukhari

火山引擎 最新活动