3

I'm trying to add the field 'mobil_brigada' to the existing view view_operaciones_brigadas_form, which is in a module named operaciones.

My Python code:

class operaciones_mobil(osv.osv):
   _name = 'operaciones.mobil'
   _inherit = 'operaciones.brigada'
   _columns = {
      'mobil_brigada': fields.many2one('add.mobil', 'Numero de Mobil', help="Numero de celular asignado a la brigada")
   }

My XML code:

<openerp>
<data>
    <!-- begin -->
     <record id="view_operaciones_mobil_form" model="ir.ui.view">
        <field name="name">operaciones.mobil.form</field>
        <field name="model">operaciones.mobil</field>
        <field name="inherit_id" ref="operaciones.view_operaciones_brigadas_form" />
         <field name="priority">100</field>
        <field name="type">form</field>
        <field name="arch" type="xml">
           <field name="supervisor" position="after">
              <field name="mobil_brigada"/>
           </field>
        </field>
    </record>
    <!--/ end -->    
</data>

And this is the original view I want to modify:

<record id="view_operaciones_brigadas_form" model="ir.ui.view">
                <field name="name">operaciones.brigada.form</field>
                <field name="model">operaciones.brigada</field>
                <field name="arch" type="xml">
                    <form string="Employee">
                        <header>
                            <field name="state" widget="statusbar" />
                        </header>
                        <sheet>
                            <div class="oe_title">
                                <label for="ficha" class="oe_edit_only"/>
                                <h1>
                                    <field name="ficha" />
                                </h1>
                                <label for="tipo" class="oe_edit_only"/>
                                <h1>
                                    <field name="tipo"/>
                                </h1>
                                <label for="proyecto" class="oe_edit_only"/>
                                <h1>
                                    <field name="proyecto"/>
                                </h1>
                            </div>
                            <group>
                                <group colspan="8">
                                    <field name="tecnico1"/>
                                    <field name="tecnico2"/>
                                </group>
                                <group colspan="4">
                                    <field name="supervisor"/>
                                    <!-- it supposed to be here -->
                                </group>
                            </group>
                        </sheet>
                    </form>
                </field>
    </record>

But nothing is happening, I'm not getting error in console, I'm administrator and I've added into __openerp__.py the XML file... What am I doing wrong?

forvas
  • 9,801
  • 7
  • 62
  • 158
  • Are your indentation issues in your code a symptom of copy paste, or are they in fact structured the way you pasted it? If so, that is one problem you should fix first and see what errors you get afterwards. – idjaw Oct 07 '15 at 13:28
  • its not identation issues .. xD you make me review my code, but thank you. – Jorge Tejeda Oct 07 '15 at 15:21

3 Answers3

2

If you only want to modify the existing form, you must remove the attribute _name from the Python model. In your case:

class operaciones_mobil(osv.osv):
   _inherit = 'operaciones.brigada'
   _columns = {
      'mobil_brigada': fields.many2one('add.mobil', 'Numero de Mobil', help='Numero de celular asignado a la brigada')
   }
forvas
  • 9,801
  • 7
  • 62
  • 158
  • Forvas, i did and i get this error, Error de contexto: Vista `operaciones.mobil.form` [view_id: 1116, xml_id: inventario_mobil.view_operaciones_mobil_form, model: operaciones.mobil, parent_id: 1042]" while parsing /home/run/openerp8/openerp/addons/inventario_mobil/ext_operaciones.xml:4, near – Jorge Tejeda Oct 07 '15 at 15:23
  • Ok, now you have just removed the line `_name` from your Python code, you cannot use `operaciones.mobil` model anymore. So change your XML code, in the record with ID *view_operaciones_mobil_form* you must replace model `operaciones.mobil` by `operaciones.brigada`. – forvas Oct 07 '15 at 15:45
  • I'm glad you did it @Jorge. Don't forget to set the answer as correct to close the question, if you consider it has helped you ;) – forvas Oct 08 '15 at 07:23
1

You are creating two tables with that kind of inheritance (using _name and _inherit attributes). If you only want to add new features to the existent table you should remove the _name attribute. If you want to keep both tables (operaciones.mobil and operaciones.brigada) try to create another whole form for the model operaciones.mobil since you can't mix forms with different models.

ChesuCR
  • 9,352
  • 5
  • 51
  • 114
0

In your code you write _name = 'operaciones.mobil' it means you creade new model or table so you can not inherit view like you write

You need to create new view including old view and your new filed, so your final code may be

<record id="view_operaciones_mobil_form" model="ir.ui.view">
        <field name="name">operaciones.mobil.form</field>
        <field name="model">operaciones.mobil</field>
        <field name="inherit_id" ref="operaciones.view_operaciones_brigadas_form" />
         <field name="priority">100</field>
        <field name="type">form</field>
        <field name="arch" type="xml">
              <form string="Employee">
                        <header>
                            <field name="state" widget="statusbar" />
                        </header>
                        <sheet>
                            <div class="oe_title">
                                <label for="ficha" class="oe_edit_only"/>
                                <h1>
                                    <field name="ficha" />
                                </h1>
                                <label for="tipo" class="oe_edit_only"/>
                                <h1>
                                    <field name="tipo"/>
                                </h1>
                                <label for="proyecto" class="oe_edit_only"/>
                                <h1>
                                    <field name="proyecto"/>
                                </h1>
                            </div>
                            <group>
                                <group colspan="8">
                                    <field name="tecnico1"/>
                                    <field name="tecnico2"/>
                                </group>
                                <group colspan="4">
                                    <field name="supervisor"/>
                                    <!-- Your New Field  -->
                                    <field name="mobil_brigada"/>
                                </group>
                            </group>
                        </sheet>
                    </form>
           </field>
        </field>
    </record>
Sagar Pise
  • 837
  • 10
  • 20