Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
2 Trả lời
7060 Lượt xem

Hi

i have created a new model for managing our shipments, we have a filed with tracking link and also i have created a button (tracking) i want add an action to this button when i clicking to that open the URL also i have created a server action linked to button but i don't know how to write the python code for that any one can help?    

Ảnh đại diện
Huỷ bỏ
Tác giả

Thank you Waleed it is working :)

Câu trả lời hay nhất

Hi, 

Here you are the python code for action:

def action_open_url(self):
return {
'name': _("Tracking"),
'type': 'ir.actions.act_url',
'url': self.url, # Replace this with tracking link
'target': 'new', # you can change target to current, self, new.. etc
}

Add button in XML:


<button name="action_open_url" string="Print" type="object"/>


You can do it from Odoo studio using server action as below:


You can create your server action and select the model sale order and set "action to do" to execute python code and past the below code after change the tracking URL field:


if record.x_studio_url:
action = {
'name': "Tracking",
'type': 'ir.actions.act_url',
'url': record.x_studio_url, # Replace this with tracking link
'target': 'new', # you can change target to current, self, new.. etc


Then save the action, once saved you can get the id of the action from browser URL web#id=xxx or you click on debug action and select view Metadata and get the id of the action. You need this id to add it to the button.

Then, you will go to sale order and open any sale order form view and then open studio, in the left side of studio click on "View" tab and click on More button, the form view xml will be shown.

Add your button inside the header tag as below:


<button name="PUT THE ACTION ID HERE" string="Tracking URL" type="action" attrs="{'invisible': [('x_studio_url', '=', False)]}"/>


Set the name attribute to the server action ID which you got before, Don't forgot to change the x_studio_url to your tracking field.




Ảnh đại diện
Huỷ bỏ
Tác giả

Hi
i Have put the code in the server action but nothing

Tác giả

Waleed

my new model has created by Odoo studio. i was wondering if you might be able to tell me where exactly shout the python cone in?

Tác giả

Thank you Waleed it is working :)

Tác giả Câu trả lời hay nhất

Waleed

my new model has created by Odoo studio. i was wondering if you might be able to tell me where exactly shout the python cone in?

Ảnh đại diện
Huỷ bỏ

There is a limitation in Odoo studio so what you can do is to add your tracking link to the form view and change his widget to url

So we Can't link it a button?

 

From: Waleed Mohsen <notifications@mail.odoo.com>
Sent: Thursday, June 16, 2022 6:22 PM
To: sales@gyeongcc.com
Subject: Re: Open a URL

 

There is a limitation in Odoo studio so what you can do is to add your tracking link to the form view and change his widget to url

Sent by Odoo S.A. using Odoo.

Tác giả

Waleed
is it possible to to link the tracking url filed to a button by server action?

I have updated my answer, I have tested the solution and its working using server actions and button

Bài viết liên quan Trả lời Lượt xem Hoạt động
2
thg 3 24
4690
1
thg 2 25
1299
1
thg 12 24
2686
0
thg 11 23
1308
1
thg 11 22
3809