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.

1

How to completely replace res.partner.form view?

By
David Dean
on 10/18/13, 12:23 PM 6,414 views

I would like to replace the default res.partner.form view with a completely new view from a simple module I've created.

I want to replace instead of inherit because I don't just want to change the fields, I also want to change the HTML and other markup around those fields. Inheriting the form and adjusting individual fields won't give me the control I'm looking for.

I've managed to create a module with a new view, load the module into OpenERP and confirmed the view is registered but my changes are not visible. When I enable debug mode and look at "Manage Views" the "View Type" is "undefined" and res.partner is still using the default view.

Can anyone point me in the direction of where I'm going wrong? I've spent hours reading the documentation and Googling but still not managed to get this working.

andromeda_customer_form.py

from osv import osv, fields
from tools.translate import _

class andromeda_customers(osv.osv):

  _inherit = 'res.partner'

  _columns = {
    'andromeda_customer_type': fields.selection([('individual','Individual'),('business','Business'),('charity','Charity / Non-Profit'),('government','Government')],'Customer Type'),
    'andromeda_business_type': fields.selection([('sole_trader','Sole Trader'),('limited','Limited Company / Limited Liability Partnership'),('partnership','Partnership'),('other','Other')],'Business Type'),
    'andromeda_customer_title': fields.selection([('mr','Mr'),('mrs','Mrs'),('miss','Miss'),('ms','Ms'),('dr','Dr'),('prof','Prof'),('rev','Rev'),('sir','Sir')],'Title'),
    'andromeda_customer_firstname': fields.char('First name', size=16),
    'andromeda_customer_lastname': fields.char('Last name', size=16),
    'andromeda_customer_phone': fields.integer('Contact number', size=16),
    'andromeda_customer_email': fields.char('E-mail address', size=16),
  }

andromeda_customers()

andromeda_customer_form.xml

<?xml version="1.0" encoding="utf-8"?>
<openerp>
  <data>
    <record model="ir.ui.view" id="andromeda_customer_form">
      <field name="name">res.partner.form</field>
      <field name="model">res.partner</field>
      <field name="priority" eval="1"/>
      <field name="arch" type="xml">
          <field name="andromeda_customer_type" />
          <field name="andromeda_business_type" />
          <field name="andromeda_customer_title" />
          <field name="andromeda_customer_firstname" />
          <field name="andromeda_customer_lastname" />
          <field name="andromeda_customer_phone" />
          <field name="andromeda_customer_email" />
      </field>
    </record>
  </data>
</openerp>

Screenshot: I don't have enough karma to post links, so replace ** with the http prefix to view the image.

**dl.dropboxusercontent.com/u/41195444/openerp.png

1
Jasad
On 12/18/13, 1:43 AM

Hi David Dean,

There are two solutions:

  1. Give the same id of partner form to your form.

ie,

<record model="ir.ui.view" id="base.view_partner_form">
      <field name="name">res.partner.form</field>
      <field name="model">res.partner</field>
      <field name="priority" eval="1"/>
      <field name="arch" type="xml">
          <field name="andromeda_customer_type" />
          <field name="andromeda_business_type" />
          <field name="andromeda_customer_title" />
          <field name="andromeda_customer_firstname" />
          <field name="andromeda_customer_lastname" />
          <field name="andromeda_customer_phone" />
          <field name="andromeda_customer_email" />
      </field>
    </record>

So it will replace the view with same id.

  1. Change the view_id in partner form menu.

ie,

<record id="base.action_partner_form_view2" model="ir.actions.act_window.view">
            <field eval="2" name="sequence"/>
            <field name="view_mode">form</field>
            <field name="view_id" ref="andromeda_customer_form"/>
            <field name="act_window_id" ref="action_partner_form"/>
        </record>

So here, the action inheriting, and it takes your form view.

0
Paty L L
On 8/30/14, 7:27 PM

Hello David.

Did you manage to replace completely the res_partner_form_view? Can it be done? Im having issues with this topic, and don't see a formal answer.

Greetings.

Nestor

0

AJ Schrafel Paper Corp

--AJ Schrafel Paper Corp--
2050
| 4 5 8
Bronx, United States
--AJ Schrafel Paper Corp--

Exploring OpenERP for business

AJ Schrafel Paper Corp
On 10/18/13, 12:41 PM

You just tossed the fields into the XML.

You need to wrap the type of view it is around you fields.

<field name="arch" type="xml">
    <form string="You need to include this around your fields to define it as a form" version="7.0">
        <your fields>
    </form>
</field>

Hi - thanks for your reply! Wrapping the fields inside "<form string="Partners">" has fixed the problem where the "View Type" was "undefined". It's now correctly listed as Form. But I still have the problem where view "res.partner.form" is taking precedence over my replacement view (as-per the screenshot). How can I force my new view to be used by default? Thanks again, I appreciate your help.

David Dean
on 10/18/13, 12:55 PM

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

1 follower(s)

Stats

Asked: 10/18/13, 12:23 PM
Seen: 6414 times
Last updated: 3/16/15, 8:10 AM