コンテンツへスキップ
メニュー
この質問にフラグが付けられました
3 返信
11129 ビュー

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!

アバター
破棄
最善の回答

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.

アバター
破棄
著作者 最善の回答

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!

アバター
破棄
最善の回答

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. 

アバター
破棄
関連投稿 返信 ビュー 活動
2
12月 22
14768
1
11月 21
4890
0
1月 21
2260
8
5月 20
7772
0
12月 23
2909