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

I'm writing a function that for searching record. 

while I change the text of name fields I hope odoo will give back the record and post it.

I have refered to odoo origin code, but it did not work.

 

    @api.multi
    @api.onchange('name')
    def _search_name(self):
        if self._context.get('params')['action'] == 111:
            return {
                'res_id': self.env['yc.purchase'].search([('name', '=', self.name)]).id,
                'view_type': 'form',
                'view_mode': 'form',
                'res_model': 'yc.purchase',
                'view_id': False,
                'type': 'ir.actions.act_window',
            }

 I hope the url will from 

"localhost:8069/web?debug#id=&view_type=form&model=yc.purchase&menu_id=273&action=111"

become

"localhost:8069/web?debug#id=XXX&view_type=form&model=yc.purchase&menu_id=273&action=111".

XXX is the id of record that I'd like to display.

Avatar
Discard
Author Best Answer

hi guys, there is no-one answer me though, I use a stupid way to solve it.

The process is type down the name which you wanna to search. While clicking button, db immediately create a new record contain nothing except name field. And after entering function, I delete it. So that it would not raise error.

my view.xml

        <record model="ir.ui.view" id="process_data_entry_form">
            <field name="name">pde.form</field>
<field name="model">yc.purchase</field>
<field name="arch" type="xml">
<form string="ProcessDataEntry form">
<sheet>
<group col="8">
</group>
<div>
<button string="search name" type="object" name="yc_purchase_search_name"/>
</div>

my mudule.py

@api.multi
    # @api.onchange("name")
def yc_purchase_search_name(self,):
# if url action = 111 execute function
if self._context.get('params')['action'] == 111:
# delete the empty record just create by odoo
to_delete_id = self.env["yc.purchase"].search([('name', '=', self.name)],order='id desc',limit=1).id
sql = "delete from yc_purchase where id=%d" % to_delete_id
self._cr.execute(sql)
id = self.env['yc.purchase'].search([('name', '=', self.name)]).id
return {
'res_model': 'yc.purchase',
'type': 'ir.actions.act_window',
'res_id': id,
'view_type': 'form',
'view_mode': 'form',
'view_id': self.env.ref('yc_root.process_data_entry_form').id,
'target': 'inline',
}

the result as pic down below. 

https://i.stack.imgur.com/vwNqy.gif 

(I can't post link or pic)

I think this method is really dangerus.

any greater idea?

Avatar
Discard
Related Posts Replies Views Activity
2
Jul 24
939
1
Jun 24
3560
1
Oct 23
8582
1
Oct 23
97
1
Aug 23
2192