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

Why is my one2many field not showing in form view?

By
Anna
on 9/7/14, 11:58 PM 1,183 views

Hi, i am creating a module which has a model with a one2many relation. There was no error installing, but when i hit the create button to go to form view, i only get the name button for input, show's nothing to take input for one2many field.

I am not quite sure of how the one2many field works in xml, so if anyone can help me continue  i would really appreciate it

Here is my .py definition:

class account_invoice(osv.osv):
    _name = 'account.invoice'
    _inherit = 'account.invoice'
    _columns = {
        'route_id' : fields.many2one('best.route', 'Ruta', readonly=False, required=True, ondelete='cascade',change_default=True, select=True,
            track_visibility='always'),
        'has_route' : fields.boolean('Tiene Ruta Asignada', readonly=True)
    }
    _defaults = {
        'has_route' : False
    }
account_invoice()

class fleet_vehicle(osv.osv):
    _name = 'fleet.vehicle'
    _inherit = 'fleet.vehicle'
    _columns = {
        'route_id' : fields.many2one('best.route', 'Ruta', readonly=False, required=True, ondelete='cascade',change_default=True, select=True,
            track_visibility='always')
    }
fleet_vehicle()

class best_route(osv.osv):
    _name = 'best.route'
    _columns = {
        'name': fields.char('Nombre', required=True, size=100),
        'invoices' : fields.one2many('account.invoice', 'route_id', 'Facturas', readonly=False, required=True, select=True),
        'fleets' : fields.one2many('fleet.vehicle', 'route_id', 'Flotas', readonly=False, required=True, select=True)
    }
best_route()

Here is my xml code to show the view:

        <record id="view_best_rutas_tree" model="ir.ui.view">
                    <field name="name">best.route</field>
                    <field name="model">best.route</field>
                    <field name="priority">1</field>
                    <field name="arch" type="xml">
                        <tree string="Mejores Rutas">
                            <field name="id" string="Id"/>
                            <field name="name" string="Nombre"/>
                            <field name="invoices" string="Facturas para Enviar" widget="one2many" domain="[('has_route','=',False)]" colspan="4" nolabel="1">
                                <tree editable='bottom'>
                                    <field name="name"/>                          
                                </tree>

                                <form>
                                    <field name="id"/>
                                    <field name="name"/>
                                </form>
                            </field>
                        </tree>
                    </field>
        </record>

        <record model="ir.actions.act_window" id="action_tree_rutas">

                    <field name="name">Mejores Rutas</field>

                    <field name="res_model">best.route</field>
                    
                    <field name="view_id" ref="view_best_rutas_tree"/>

                    <field name="view_type">form</field>

                    <field name="view_mode">tree,form</field>

        </record>

        <menuitem id="main_menu_ruta" name="Rutas"/>
            <menuitem id="Rutas" parent="main_menu_ruta" name="Rutas"/>
            <menuitem id="Destinos" parent="Rutas" action="action_tree_destination" name="Destinos" sequence="1"/>
            <menuitem id="Mejores Rutas" parent="Rutas" action="action_tree_rutas" name="Mejores Rutas" sequence="2"/>

1

Prakash

--Prakash--
3173
| 5 4 7
Bikaner, India
--Prakash--

OpenERP Devloper at SunARC Technology

Prakash
On 9/8/14, 2:53 AM

Try the below code in xml

   <record id="view_best_rutas_form" model="ir.ui.view">
        <field name="name">best.route</field>
        <field name="model">best.route</field>
        <field name="priority">1</field>
        <field name="arch" type="xml">
            <form string="Mejores Rutas">
                <field name="id" string="Id"/>
                <field name="name" string="Nombre"/>
                <field name="invoices" string="Facturas para Enviar" widget="one2many"  colspan="4" nolabel="1">
                    <tree editable='bottom'>
                        <field name="route_id"/>      
                        <field name="has_route"/>

                       <field name="state" invisible="1"/>            
                    </tree>
                    <form>
                        <field name="route_id"/>  
                        <field name="has_route"/>  
                    </form>
                </field>
            </form>
        </field>            
   </record>

ok, added this as form view, but with fields id and name for invoices,not route_id and has route, cuz that was giving me the best.route in the one2many field. And i want account.invoices. Now i can see the field in form view, but it's giving me a runtime error: Error: QWeb2 - template['ListView.row']: Runtime Error: Error: Campo desconocido state en el dominio [["state","not in",["draft"]]]. I'm thinking maybe i need to add context or something, but i am not sure.Do you know why it's giving me that error?

Anna
on 9/8/14, 6:00 PM

To fix runtime error add state field in tree view with invisible tag i updated my answer.

Prakash
on 9/9/14, 3:15 AM
0

deep

--deep--
1617
| 5 4 7
Bengaluru, India
--deep--

Techno-Functional Associate with 6+ years of experience in Odoo (formerly known as OpenERP).

deep
On 9/8/14, 3:15 AM

Firstly: Your Tree view for the object "best.route" is not set to editable...

                      <tree string="Mejores Rutas" editable="top">

Secondly: You haven't specified mode for your o2m field..

                         <field name="invoices" string="Facturas para Enviar" widget="one2many" mode="tree,form" domain="  [('has_route','=',False)]" colspan="4" nolabel="1">

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: 9/7/14, 11:58 PM
Seen: 1183 times
Last updated: 3/16/15, 8:10 AM