Skip to Content
เมนู
คุณต้องลงทะเบียนเพื่อโต้ตอบกับคอมมูนิตี้
คำถามนี้ถูกตั้งค่าสถานะ
3 ตอบกลับ
11135 มุมมอง

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. 

อวตาร
ละทิ้ง
Related Posts ตอบกลับ มุมมอง กิจกรรม
Selecting items for one2many relation แก้ไขแล้ว
2
ธ.ค. 22
14773
1
พ.ย. 21
4895
0
ม.ค. 21
2265
8
พ.ค. 20
7776
0
ธ.ค. 23
2914