Help

3

one2many field in openerp

Avatar
mid123

how to give one2many field to same model...for an example I have to create one 2 many in product.product it refers to same product.product it shows an integriyt error how to rectify this problem ???

1 Comment
Avatar
Discard
Avatar
Francesco OpenCode
-

Post the code, please

8 Answers
5

First you have to create many2one field of product.product and then you can create one2many field.

For example:

`partent_id`: fields.many2one('product.product', 'Parent Product', ondelete='cascade'),
`product_ids`: fields.one2many('product.product', 'parent_id', 'Products'),
3 Comments
Avatar
Discard
Avatar
mid123
-

Thanks for your reply

Avatar
Shivam Mahajan
-

but it still gives the integrity error

Avatar
Shivam Mahajan
-

Integrity Error The operation cannot be completed, probably due to the following: - deletion: you may be trying to delete a record while other records still reference it - creation/update: a mandatory field is not correctly set [object with reference: name - name]

1
Avatar
mywebsitedeal
Best Answer

Hi,

I also  have created that one2many field  on same model . it works but their are no records are being displayed  in one2many field .

How to display value in one2many .

1 Comment
Avatar
Discard

you got solution to this?

0
Avatar
Rey Perez
Best Answer

if you ask something like this:
model "product.product"
fields in the same model: product_parent_id, product_children_ids

when you try running the program this show some integrity error with the fields ids that should be into list product_children_ids,

you should solve with something like this, creating domain for this filed into the xml and some additional field into model like "type_product" if haven't anyone like this field to refer:

TYPE_MODE = [('product','product'),('subproduct','subproduct')]

model ("product.product")
type_product = fields.Selection(TYPE_MODE , 'Product Type', default='product', store=True)

xml (form_view for  "product.product")
<field name="product_children_ids" domain="[('type_product','=','subproduct')]">
                                <tree>
                                    <field name="code"/>
                                    <field name="descripcion"/>
                                    <field name="other_product_field_name"/>
                                </tree>
</field>

if this solve work for you, make me know.

Avatar
Discard