I am beginner in Odoo and python, and I want to create a simple module, which should insert some categories for a person (student, employee,...), and then insert persons with field category. My question is, how to create p_c_view.xml. I tried to adjust some xmls examples that I found, but had no success. Here is my p_c.py file. Thanks
class p_c_person(osv.osv):
_name = "p_c.person"
_description = "Person"
_columns = {
'name': fields.char('Persone', size=128, required=True),
'categories': fields.one2many('p_c.category', 'category_id', 'Categories'
}
p_c_person()
class p_c_category(osv.osv):
_name = "p_c.category"
_description = "Category"
_columns = {
'name': fields.char('Category', size=128, required=True),
'property_id': fields.many2one('p_c.person', 'Person Name', select=True),
}
p_c_category()
Many2one
Store a relation against a co-model:
Specific options:
Example:
'property_id': fields.many2one('p_c.person', 'Person Name', select=True),
One2many
Store a relation against many rows of co-model:
Specific options:
Example:
'categories': fields.one2many('p_c.category', 'property_id', 'Categories'),
Refer Odoo documentation
One2many field only created for relational many2one field of that model, it gives you freedom to travelling bi-directional. Odoo engine manage integrity while you create record in reference model in which you have define many2one field then you will see the effect in one2many field as well.
one2many field takes responding many2one field with that object.
try with this code
class p_c_person(osv.osv):
_name = "p_c.person"
_description = "Person"
_columns = {
'name': fields.char('Persone', size=128, required=True),
'categories': fields.one2many('p_c.category', 'property_id', 'Categories'
}
p_c_person()
class p_c_category(osv.osv):
_name = "p_c.category"
_description = "Category"
_columns = {
'name': fields.char('Category', size=128, required=True),
'property_id': fields.many2one('p_c.person', 'Person Name', select=True),
}
p_c_category()
For more details you may visit odoo documentation.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With