Odoo Help


Add an object in a One2many relation

on 12/19/14, 7:12 AM 1,453 views

Hello, I have Odoo 8.

In the sale.order model I define a Many2one relation

class sale_order(models.Model):
    _inherit = 'sale.order'

    pricelist_version_id = fields.Many2one('product.pricelist.version', required=False)

In product.pricelist.version I have the One2many relation:

class product_pricelist_version(models.Model):
    _inherit = 'product.pricelist.version'

    sales = fields.One2many('sale.order', 'pricelist_version_id')

I want to append a sale.order in the "sales" attribute of product.pricelist.version. I do this:


But I get the error "AttributeError: 'sale.order' object has no attribute 'append'", what is my mistake? Thanks!

Juan Carlos
On 12/19/14, 11:34 AM


class MiClase(models.Model):

_name = 'modulo.nombre'

producto_box = fields.One2many('modulo.nombredos', 'name') 


class MiClaseDos(models.Model):

_name = 'modulo.nombredos'

name = fields.Char(string="Nombre") #Intenta utilizar este como ID y no lo muestres en el XML

producto_id = fields.Many2one('product.product', "Producto") 

#Sigue agregando los campos que necesites y muestralos como field en el XML


<!-- Debe ir en un Form -->

<group string="Compras">
                                        <field name="producto_box" nolabel="1">
                                            <tree editable="bottom">
                                                <field name="producto_id"/>

Espero te sirva, ojala alguien me lo hubiera explicado de esa manera.

On 12/19/14, 12:11 PM

But I need to aggregate it from code, not from UI. I do the inverse path: I save the id in the Many2one relation field... and if I need consult the One2many relation values.


On 2/19/15, 3:01 PM

There is a special command format as documented in the ORM for many2many and one2many fields.

See: https://www.odoo.com/documentation/8.0/reference/orm.html#openerp.models.Model.write

Also, I don't think the one2many is strictly necessary to produce the link between the two, unless you want to update both at the same time. 

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 platform 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.


Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

1 follower(s)


Asked: 12/19/14, 7:12 AM
Seen: 1453 times
Last updated: 3/16/15, 8:10 AM