Skip to Content
Menu
This question has been flagged
1 Reply
2920 Views

I try build a module global_search now i stuck at how to store data in TransientModel  from a query in a function to render treeview

this is my py code but self.write not work


# -*- coding: utf-8 -*-

from odoo import models, fields, api


class CreateViewSql(models.TransientModel):
    _name = "create.view.sql"

    email = fields.Char(string='Email')
    name = fields.Char(string='Name')
    phone = fields.Integer(string='Phone')
    # type_of = fields.Char(string='Type')

    @api.model
    def get_data(selfsearch):
        text_input = search.get("Input")
        sql = "select name,email,phone from res_partner where phone = '%s' or email = '%s'"
        self.env.cr.execute(sql)
        result = self.env.cr.fetchall() or []
        vals = {}
        vals['name'] = result[0][0]
        vals['email'] = result[0][1]
        vals['phone'] = result[0][2]
        self.write(vals)
        return result


now i need store result 3 fields(name, email, phone) to TransientModel

Avatar
Discard
Author Best Answer

done!
just change self.write(vals) to self.create(vals)

Avatar
Discard
Related Posts Replies Views Activity
1
Jul 24
3500
2
Jan 24
10135
1
Apr 24
924
7
Jan 24
45459
0
Mar 23
1038