表单内树视图中的值未出现 Odoo 11

Value in tree view inside form not appearing Odoo 11

我刚开始使用 odoo 11。我在 FOLDER 表单中使用树,用于显示 one2many 字段的数据。单击 SYNC 按钮时将创建树视图中的数据。该按钮将触发外部 api get 方法,然后根据 JSON 值创建适当的数据。当我单击按钮时,它触发了该方法并成功进入了数据库,但是当我查看树视图时,没有任何价值。请帮忙,我卡住了。

PYTHON

class GetFolder(models.Model):
    _name = 'get_folders'
     name_folder = fields.Text(string='Name')
     email_blacklist = fields.Integer(string='Email Blacklist',store=True)
     email_subscribers = fields.Integer(string='Email Subscribers',store=True)
     unique_subscribers = fields.Integer(string='Unique Subscribers', store=True)
     email_count = fields.Integer(string='Email', store=True)
     foldersId = fields.Integer(string='FolderId', store=True)
     list_folder_ids = fields.One2many(comodel_name='get_lists', string='Folder', 
     inverse_name='folder_lists', help="")

     @api.multi
     def get_lists_request(self):
     res = self.env['get_lists'].search([('foldersId','=',self.foldersId)])
     for record in res:
        record.ensure_one()
        list_url = ""
        querystring = {"limit":"50","offset":"0","sort":"desc"}
        headers = {
            "Accept": "application/json",
            "api-key": ""
        }

        list_response = requests.request("GET", list_url, headers=headers, params=querystring)
        print(list_response.text)
        list_loads = simplejson.loads(list_response.text)
        _logger.warning(list_loads)
        for list_load in list_loads.get("lists"):
            names = list_load['name']
            ids = list_load['id']
            blacklist = list_load['totalBlacklisted']
            subscribe = list_load['totalSubscribers']
            self.env['get_lists'].sudo().create({
                    'id': self.id,
                    'name': names,
                    'email_subscribers': subscribe,
                    'email_blacklist': blacklist,
                    'listId' : ids,
                    'foldersId' : self.foldersId,
                    })

class GetList(models.Model):
    _name = "get_lists"

    name = fields.Char(string="Name")
    email_subscribers = fields.Integer(string="Total Subscribers", store=True)
    email_blacklist = fields.Integer(string="Total Blacklist", store=True)
    folder_lists = fields.Many2one(comodel_name='get_folders', string='Lists')
    foldersId = fields.Integer(string="Folder Id", related="folder_lists.foldersId", store=True)
    listId = fields.Integer(string="List Id", store=True)
    

XML

   <notebook>
     <page string="Lists">
        <tr style="margin-bottom:100px;">
           <td><button type="object" name="get_lists_request" string="Synch" class="oe_inline oe_button btn-success"/></td>
        </tr>
        <field name="list_folder_ids"/>
     </page>
   </notebook>

编辑后的版本

record = self.env['get_folders'].search([('id','=',self.id)])
for recx in record:
    self.env['get_lists'].create({
                        'id': self.id,
                        'name': names,
                        'email_subscribers': subscribe,
                        'email_blacklist': blacklist,
                        'listId' : ids,
                        'foldersId': recx.id,
                        })

是的,成功了。回复晚了,请原谅。经过多次尝试和修复。我真的看了你的代码并找到了错误。其实很简单。我忘了输入 many2one 值。你真的让我很开心。谢谢。

您需要在创建 get_lists 对象数据时传递 primary_key

代码:

self.env['get_lists'].sudo().create({
                'id': self.id,
                'name': names,
                'email_subscribers': subscribe,
                'email_blacklist': blacklist,
                'listId' : ids,
                'foldersId' : self.foldersId,
                'folder_lists': self and self.id // set the ref
        })