Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

0

How do I remove fields from a view in a custom module?

By
Seth Boyd
on 7/31/14, 12:54 PM 6,843 views

I'm trying to modify a view from the CRM module from a custom module with no luck.  Currently, from the debugging interface, I can see that my inherited views are being created alongside the views they are meant to modify and end up being straight copies of the inherited view with no modifications.

Here is the view's code:

<!-- Phonecalls Form View -->
    <record model="ir.ui.view" id="crm_case_phone_form_view">
        <field name="name">CRM - Phone Call Form</field>
        <field name="model">crm.phonecall</field>
        <field name="type">form</field>
        <field name="inherited_id" ref="crm.crm_case_phone_form_view"/>
        <field name="arch" type="xml">
            <field name="partner_phone" position="replace"/>
            <field name="user_id" position="replace"/>
            <field name="duration" position="replace"/>
            <field name="partner_mobile" position="replace"/>
            <field name="priority" position="replace"/>
        </field>
    </record>

As you can see, I'm just tryting to remove a few fields, but after restarting openerp and updating my module nothing changes at all on the view.

 

EDIT:

Here are the four files that I have in my module.

__openerp__.py

{
    "name" : "Hotel CRM Customizations",
    "version" : "0.01",
    "category" : "Generic Modules/Hotel Management",
    "description": """
    Module to to customize the CRM module to be more useful for the hotel industry
    """,
    "depends" : ["crm"],
    "data": [
        "crm_phonecall_menu.xml",
        "crm_phonecall_view.xml",
    ],
    "auto_install": False,
    "installable": True
}

__init__.py is blank

crm_phonecall_menu.xml (this modification actually works)

<?xml version="1.0"?>
<openerp>
    <data>
        <!-- PHONE CALLS (menu)  -->
        <menuitem name="Call Log" id="crm.menu_crm_case_phone"
            groups="base.group_sale_salesman"
            parent="base.menu_base_partner" sequence="4" />
    </data>
</openerp>

crm_phonecall_view.xml

<?xml version="1.0"?>
<openerp>
    <data>

    <!-- Phonecalls Form View -->
    <record model="ir.ui.view" id="crm_case_phone_form_view_inherit">
        <field name="name">CRM - Phone Call Form</field>
        <field name="model">crm.phonecall</field>
        <field name="sequence">14</field>
        <field name="inherited_id" ref="crm.crm_case_phone_form_view"/>
        <field name="arch" type="xml">
            <field name="partner_phone" position="attributes">
                <attribute name="invisible">True</attribute>
            </field>
            <field name="user_id" position="attributes">
                <attribute name="invisible">True</attribute>
            </field>
            <field name="duration" position="replace"/>
            <field name="partner_mobile" position="replace"/>
            <field name="priority" position="replace"/>
        </field>
    </record>
    </data>
</openerp>

Seems like some of the comment has been trimmed, so usage is .

Currenda Sp. z o.o., Mariusz Mizgier
on 8/1/14, 10:47 AM

Ah, very well spotted on the inherit! On the position tag, it is a common way to do that. This is the equivalent of . You could also use Xpath, but the OpenERP built-in is much easier!

Ludo - Neobis
on 8/1/14, 10:49 AM

"inherited_id" was the problem. After changing it to "inherit_id" everything is working properly. Thank you so much for noticing that!

Seth Boyd
on 8/1/14, 11:18 AM

First, when you inherit a view, use field name="inherit_id" instead of inherited_id. Second, remove sequence from the xml view - you do not need that for inherited view, which deals with attributes. Third, i do not understand your position="replace" usage of fields like duration partner_mobile or priority - if you use replace, the schema is like

Seth Boyd
on 8/1/14, 11:20 AM

I tried to convert your, Mariusz's, comment to an answer, but it created it under my name for some reason. I've accepted your answer instead.

Seth Boyd
on 8/1/14, 11:22 AM
1
Mariusz Mizgier
On 8/1/14, 4:00 AM

Easiest way to do that is to use attributes for that. For example, if you want to hide partner_phone just type:

<field name="partner_phone" position="attributes">

<attribute name="invisible">True</attribute>

</field>

That way the field you want to dissapear will be hidden in the form view.

I updated my original post to include all of my file contents including your suggested change. Unfortunately, it's still not working yet, though.

Seth Boyd
on 8/1/14, 10:19 AM
1

Ludo - Neobis

--Ludo - Neobis--
2387
| 2 2 5
Hoogvliet, Netherlands
--Ludo - Neobis--

Developer

Ludo - Neobis
On 8/1/14, 3:26 AM

And you are 100% sure the view gets loaded? (as in: its in an installed module AND in the __openerp__.py "data" or "update_xml" list?)

If so, try to add the priority (or sequence?) field to your view. The syntax is something like <field name="sequence">15</field>. Give it a low number so it gets picked up last.

Also try to make the id of the xml record unique. I do not know if that matters, but I always tend to make it unique. Just add something like _inherit to the end of it.

[EDIT]

Try to enclose the view adjustments with the <data> tag, like so:

        <field name="arch" type="xml">

           <data>
                <field name="partner_phone" position="replace"/>
                <field name="user_id" position="replace"/>
                <field name="duration" position="replace"/>
                <field name="partner_mobile" position="replace"/>
                <field name="priority" position="replace"/>

            </data>
        </field>

Other than that I would not see why this would not work. I'm unfortunately not in the position to test it currently.

I've edited my original post to include the contents of all four files in the module. Also, I tried your suggested changes, but nothing has worked so far. The module is installed, and the view id changed in the debugging interface when I made it unique, so it is getting some of the file updates.

Seth Boyd
on 8/1/14, 10:16 AM

I've edited my original answer. If that fails then I don't know what would be wrong. Assuming you did not make any typo's in the XML names. Can you check the database to verify the view itself is actually loaded?

Ludo - Neobis
on 8/1/14, 10:22 AM
The view is actually loaded, but it doesn't have an inherited_id for some reason.  It's weird when I preview my view from the debugging interface my changes aren't showing up there either.  Perhaps it is using my view changes, but my view changes aren't formatted properly so their not having their intended effect.


Here is the row for the created view:
"933";"crm.phonecall";
"data";
"<?xml version="1.0"?>
<data>
                <field name="partner_phone" position="attributes">
                    <attribute name="invisible">True</attribute>
                </field>
                <field name="user_id" position="attributes">
                    <attribute name="invisible">True</attribute>
                </field>
                <field name="duration" position="replace"/>
                <field name="partner_mobile" position="replace"/>
                <field name="priority" position="replace"/>
            </data>
        ";
"";
16;1;
"2014-08-01 13:43:59.672517";
"2014-08-01 14:28:33.136775";
1;
; <-- This should be the inherited_id
"CRM - Phone Call Form"

Here is the row for the view I'm trying to inherit from:
"928";
"crm.phonecall";
"form";
"<?xml version="1.0"?>
<form string="Phone Call" version="7.0">
                <header>
                    <button name="case_close" string="Call Done" type="object" class="oe_highlight" states="open,pending"/>
                    <button name="case_reset" string="Reset to Todo" type="object" states="cancel"/>
                    <button name="case_cancel" string="Cancel Call" type="object" states="draft,open,pending"/>
                    <field name="state" widget="statusbar" nolabel="1" statusbar_visible="open,done"/>
                </header>
                <sheet string="Phone Call">
                    <div class="oe_right">
                        <button string="Convert to Opportunity" type="object" name="action_button_convert2opportunity" attrs="{'invisible':[ '|', ('opportunity_id','!=',False), ('state', 'not in', ('open', 'done'))]}"/>
                        <button string="Schedule Other Call" name="505" type="action"/>
                        <button string="Schedule a Meeting" name="action_make_meeting" type="object"/>
                    </div>
                    <div class="oe_title">
                        <div class="oe_edit_only">
                            <label for="name"/>
                        </div>
                        <h1><field name="name" required="1"/></h1>
                        <div class="oe_edit_only">
                            <label for="partner_phone" string="Phone"/>
                        </div>
                        <h2><field name="partner_phone"/></h2>
                    </div>

                    <group col="4">
                        <field name="date"/>
                        <field name="user_id"/>
                        <field name="duration" widget="float_time"/>
                        <field name="section_id" colspan="1" widget="selection"/>
                        <field name="partner_id" on_change="onchange_partner_id(partner_id)"/>
                        <field name="email_from" invisible="1"/> <!--not needed because of the chatter, thus invisible, but must be in the view as it's returned by onchange_partner_id()-->
                        <field name="categ_id" widget="selection" domain="[('object_id.model', '=', 'crm.phonecall')]"/>
                        <field name="partner_mobile"/>
                        <field name="priority"/>
                        <field name="opportunity_id" on_change="on_change_opportunity(opportunity_id)"/>
                    </group>
                    <field name="description" placeholder="Description..."/>
                </sheet>
                <div class="oe_chatter">
                    <field name="message_follower_ids" widget="mail_followers"/>
                    <field name="message_ids" widget="mail_thread"/>
                </div>
            </form>
        ";
"";
16;
1;
"2014-07-27 16:22:20.594678";
"2014-07-27 16:22:20.594678";
1;
;
"CRM - Phone Call Form"

Thanks for your help,
Seth


On Fri, Aug 1, 2014 at 8:22 AM, Ludo - Neobis <ludo@neobis.nl> wrote:

I've edited my original answer. If that fails then I don't know what would be wrong. Assuming you did not make any typo's in the XML names. Can you check the database to verify the view itself is actually loaded?

--
Ludo - Neobis Sent by OpenERP S.A. using Odoo. Access your messages and documents in Odoo

Seth Boyd
on 8/1/14, 11:12 AM
0
Shide
On 3/21/16, 10:55 AM

You should use "replace", but leaving a blank space inside

<field name="partner_phone" position="replace">

</field>

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

3 follower(s)

Stats

Asked: 7/31/14, 12:54 PM
Seen: 6843 times
Last updated: 3/21/16, 10:55 AM