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.
Thank you Waleed it is working :)