تخطي للذهاب إلى المحتوى
القائمة
لقد تم الإبلاغ عن هذا السؤال
3 الردود
11145 أدوات العرض

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
ديسمبر 22
14784
1
نوفمبر 21
4904
0
يناير 21
2267
8
مايو 20
7782
0
ديسمبر 23
2921