I changed some things in your code. You must return another action from Python to open the tree view:
Python code
@api.model
def getOrdersTechData(self):
getServer = 'someapi.xxx'
get_response = requests.get(url=getServer).json()
partner_id = get_response['partner_id']
name = get_response['name']
product_id = get_response['product_id']
...
po = self.createBestelAanvraag(partner_id,name,product_id,product_qty,product_uom
res = {
'view_type': 'form',
'view_mode': 'tree',
'res_model': 'purchase.order',
'type': 'ir.actions.act_window',
'target': 'current',
}
return res
@api.model
def createBestelAanvraag(self, partner_id, name, product_id, product_qty,
product_uom, price_unit, date_planned):
po_vals = {
'partner_id': partner_id,
'order_line': [
(0, 0, {
'name': name,
...
}),
],
}
return self.env['purchase.order'].create(po_vals)
XML code
<record id="action_make_testing" model="ir.actions.server">
<field name="name">My Action</field>
<field name="condition">True</field>
<field name="type">ir.actions.server</field>
<field name="model_id" ref="model_purchase_order"/>
<field name="state">code</field>
<field name="code">env['purchase.order'].getOrdersTechData()</field>
</record>
NOTE 1
If you see a purchase tree view, but your purchase order is missing, but add a parameter auto_refresh
to the value res
:
res = {
'view_type': 'form',
'view_mode': 'tree',
'res_model': 'purchase.order',
'type': 'ir.actions.act_window',
'target': 'current',
'auto_refresh': 1,
}
return res
NOTE 2
, , res
this ( Python ):
res = {
'view_type': 'form',
'view_mode': 'form',
'res_model': 'purchase.order',
'res_id': po.id,
'type': 'ir.actions.act_window',
'target': 'current',
}
return res