Odoo Help


How to insert records from Model (use self.env.create())

on 2/26/16, 11:16 AM 2,108 views

class Setting(models.Model):
    _name = 'magento.setting'
name = fields.Char(string="Title", required=True)


def action_test_connection(self): 
         stores = self.env['test.store'].search([]) #work
         store1 = self.env['test.store'].browse([1]) #work
         store = self.env['magento.store'].search([('id_store', '=', 2)]) #work
         id_created = self.env['test.store'].create({'id_store': 100}) #work but don't save

class Store(models.Model):

    _name = 'test.store'

    id_store = fields.Integer()



<button string="Test Connection" type="object" name="action_test_connection"

class="oe_stat_button" icon="fa-bolt" attrs=""/>


hi, I can not create a record in the database

when I do click on the button Create a new record the model Store

performing debugging, I noticed that id_created effectively at each iteration is created with an id in succession

if you check in or view in the database is not written anything

How do I insert new records in the database table Store ?

On 7/1/16, 2:05 AM

Try to this code


def action_test_connection(self):

self.env['test.store'].create({'id_store': 100'})

On 2/27/16, 7:32 AM

I Solved using -> self.env.cr.commit()

    def action_test_connection(self):                  
        stores = self.env['test.store'].search([])                  
        store1 = self.env['test.store'].browse([1])                  
        store = self.env['test.store'].search([('id_store', '=', 2)])          
        id_created = self.env['test.store'].create({'id_store': 100})        

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This platform is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.


Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

1 follower(s)


Asked: 2/26/16, 11:16 AM
Seen: 2108 times
Last updated: 7/1/16, 2:05 AM