This question has been flagged
2 Replies
10437 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"/>

Avatar
Discard
Best Answer

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>

Avatar
Discard
Author

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?

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

Best Answer

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">

Avatar
Discard