Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
7 Trả lời
31703 Lượt xem

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

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

(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.

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

 You can create record using create method.


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

        print values




Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

What version are you using?

Ảnh đại diện
Huỷ bỏ
Tác giả

I'm using odoo8

Câu trả lời hay nhất

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

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

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.

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

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...

Ảnh đại diện
Huỷ bỏ