Skip to Content
Menu
This question has been flagged
4 Replies
6479 Views

I am looking for the technique how to add specific functionality/action to a tree view.


in a tree view I have added a button

<tree>
    <button name="fn1" type="object" string="F1" />


then I have added a method for this button in my model


def fn1(self):

All fine to this point


Problem 1 (from view to a method)

I assume that when I click on a button on the record I would somehow get the record id in which button is clicked on. But...


Normally models method def would have REC as parameter and would consist of a marked record set, but in this case no record set has been passed to a method. How do I know on which record button I have clicked on? Is there some modifier in the view definition to instruct button to send record id to an action method?


Problem 2 (from a method to a resulting page)

There is technique to navigate to a specific form using this kind of button, by making method return data in this fashion:

return {
    'view_type': 'form',
    'view_mode': 'form',
    'res_model': 'my.cloud.files',
    'views': [(False, 'form')],
    'type': 'ir.actions.act_window',
    'target': 'new',
    'context': {},
}

this renders a popup form (in described case it is not even a record from which click is originated but it looks like 'create' form), apart from this:

I do not want to use any of existing ODOO forms, what I want to navigate to a dynamic url I am going to build within this model method.

In more detail what I want is to construct URL from the record I have clicked on, and navigate browser to that URL i have built. To build URL I will be using using a field from my model. For example I have field in the model which is called ID and it has value 123 so I would build a URL like http://site/path/123. This is trivial to make in python but later instruction to ODOO to go to that 'dynamic' url is something I cannot find how to do. 

how should 'return' look like to go to my url ?


Kindly advise.

Avatar
Discard
Author

Đức Hậu Trần

Thank you for your answer. Need to try these hints.

One small clarification, please. Following code looks to me to be a part of a Model definition. Is this correct understanding?

fb_link = fields.Html ( string= "FB link", compute="get_fb_link" )

(have not enough karma to comment on your post)

Best Answer

Hi,

1. you can use html dynamic field to define your url and show it in your form.

for example:


#Python code:

def get_fb_link( self):

    for item in self:

        item.fb_link = "http://site/path/" + item.id

fb_link = fields.Html ( string= "FB link", compute="get_fb_link" )


# in xml file, you show fb link in your form.


2. You can use "ir.actions.act_url" model to return your URL.

#https://www.odoo.com/documentation/13.0/reference/actions.html#url-actions-ir-actions-act-url

def fn1(self):

return {
    "type": "ir.actions.act_url",
    "url": "http://site/path/" + self.id,
    "target": "self",
}

Avatar
Discard