Odoo Help

0

Add an object in a One2many relation

By
José
on 12/19/14, 7:12 AM 1,985 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:

version_pricelist.sales.append(obj_sale_order)

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

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

my.py

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

my.xml 

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

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

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

0
José
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.

thanks!

0
John
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. 

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.

Register

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)

Stats

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