Skip to Content
เมนู
คุณต้องลงทะเบียนเพื่อโต้ตอบกับคอมมูนิตี้
คำถามนี้ถูกตั้งค่าสถานะ
2 ตอบกลับ
35036 มุมมอง

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

@api.multi

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

models.py

 

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

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

test.xml

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 ?



อวตาร
ละทิ้ง
ผู้เขียน คำตอบที่ดีที่สุด

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

 @api.multi        
    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})        
        self.env.cr.commit()

อวตาร
ละทิ้ง
คำตอบที่ดีที่สุด

Try to this code

@api.multi

def action_test_connection(self):

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

อวตาร
ละทิ้ง
Related Posts ตอบกลับ มุมมอง กิจกรรม
0
ก.ย. 16
3746
Problem on Installing Odoo 9.0 แก้ไขแล้ว
1
พ.ค. 15
4117
1
ธ.ค. 22
7145
1
ม.ค. 20
5523
1
มิ.ย. 17
4062