You can do this with a button and an action. First, you need to add a button in your tree view:
<button type="object" name="go_to_model_B" string="To Model B" icon="fa-search"/>
Here the name prop is a method in your model A (the icon prop is optional but I think it looks better). The method goes something like this:
# Method in Model A
def go_to_model_B(self):
name_form = _('FORM B')
return {
'name': NAME_FORM,
'type': 'ir.actions.act_window',
'view_type': 'form',
'view_mode': 'form',
'res_model': 'MODEL.B',
'res_id': self.consultation_id.id, # Reference to the other model
'target': 'new',
'view_id': self.env.ref(
'FORM_VIEW_MODEL_B').id,
'context': {} # Optional
}
Maybe you want to open the form in a new tab, here is another option:
import werkzeug.utils
def go_to_model_B(self):
url_base = "{}/web?&#id={}&view_type=form&model={}&action={}'"
action = "MODULE.ACTION_FORM_MODEL_B" # Name of the action defined in some XML
model_name = "MODEL.B"
target_record_id = self.consultation_id.id
url = url_base.format(domain, target_record_id, model_name, action)
return werkzeug.utils.redirect(url)
Another way to do this is using ir.actions.act_url:
def go_to_model_B(self):
return {
'name': "TO MODEL B"
'type': 'ir.actions.act_url',
'url': url, # The url is the same as above
'target': 'new'
}