Skip to Content
Menu
This question has been flagged
7 Replies
31214 Views

Actually i don't know how to create a field in odoo so anyone please solve this problem.

Avatar
Discard
Best Answer

(For version 8 and above)

For create method you need values i.e. the values with which you want to create a record.

@api.model is used for create method

suppose we have an object called students and fields like name and standard and we want to create a record with values like name='ABC' standrd='10'

then our method will be


@api.model

def create(self,vals):

     vals = {'name': 'ABC', 'standard':10}

     res = super(students, self).create(vals)

     return res


here res will hold the browse record of created record.

Avatar
Discard
Best Answer

 You can create record using create method.


@api.model
def create(self, values):
        new_id = super(res_partner, self).create(vals)

        print values




Avatar
Discard
Best Answer

What version are you using?

Avatar
Discard
Author

I'm using odoo8

Best Answer

Could you be a bit more specific about what you need?

Avatar
Discard
Best Answer

Hi,


You can Use create method to create a record: This is the syntax of create method:

self.pool.get['object.name'].create( cr, uid, vals, context )

vals contains dictionaries of field and its value: eg.

vals = {'name': 'Chandni', 'city': 'xyz'}

This is how you can use in PY file.

Which version you are using and where u want to use create method !

Hope this will help you.

Thanks,

Chandni.

Avatar
Discard
Best Answer

Hi...
to create field you can use http://odoo-new-api-guide-line.readthedocs.io/en/latest/fields.html as recommendation

for example if you want to create Boolean object in odoo 10 , build a folder to contain python file, and xml


in python (file.py):


from odoo import api, fields, models, _


class YourClassName(models.Model):

     _inherit= 'res.partner' #or any of your model that you want to add

     iam_your_rival_field = fields.Boolean(string='Is Your Rival Company')    


     #below here is the example function 

     @api.onchange('suplier','customer')

     @api.multi

     def are_this_rival(self):

         if not self.suplier and not self.customer:

             self.iam_your_rival_field= True

             

Then put your field in python field into XML, plus don't foreget to put __init__.py and __manifest__.py  more detail you browse on you example base module on add on...
hope this will help...

Avatar
Discard