我从这样的外部来源提取数据:
from odoo import models,fields,api
import datetime
import requests
import logging
_logger = logging.getLogger(__name__)
class purchase_order(models.Model):
_inherit = "purchase.order"
@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']
...
self.createBestelAanvraag(partner_id,name,product_id,product_qty,product_uom,price_unit,date_planned)
@api.multi
def createBestelAanvraag(self,partner_id,name,product_id,product_qty,product_uom,price_unit,date_planned):
_logger.debug("name:")
_logger.debug(name)
self.PurchaseOrder = self.env['purchase.order']
po_vals = {
'partner_id': partner_id,
'order_line': [
(0, 0, {
'name': name,
...
}),
],
}
self.po = self.PurchaseOrder.create(po_vals)
我从主屏幕上的menuitem开始这样做:
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<data>
<record id="action_make_testing" model="ir.actions.server">
<field name="name">My Action</field>
<field name="model_id" ref="model_purchase_order"/>
<field name="code">env['purchase.order'].getOrdersTechData()
</field>
</record>
<menuitem name="Fetch Data" action="action_make_testing"
id="sale_order_custom_document" sequence="20"/>
</data>
</odoo>
但是在创建订单后,我看到一个空白视图,我必须从GUI购买。相反,我希望立即查看包含新订单的所有订单的购买清单视图。
答案 0 :(得分:2)
您可以退回购买行为。
试试这个:
action = self.env.ref('purchase.purchase_rfq').read()[0]
action.update({'domain': [('id', '=', self.po.id)], 'res_id': self.po.id})
return action
这将打开购买视图并显示采购订单。
答案 1 :(得分:1)
我修改了代码中的一些内容。您必须从Python返回另一个操作才能打开树视图:
Python代码
df4 <- data.frame(MIN = c(1,4,8, 20, 30, 22), MAX = c(3, 6, 10, 25, 40, 24), VALUE = c(3, 56, 8, 10, 12, 23))
df2A <- data.frame(KEY = c(3, 6, 22, 30, 50))
df4
MIN MAX VALUE
1 1 3 3
2 4 6 56
3 8 10 8
4 20 25 10
5 30 40 12
6 22 24 23
> df2A
KEY
1 3
2 6
3 22
4 30
5 50
> lookup(df2A, df4)
rowid KEY VALUE
1 1 3 3
2 2 6 56
3 3 22 10
4 3 22 23
5 4 30 12
6 5 50 NA
XML代码
@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)
注1
如果您看到购买树视图,但您的采购订单不存在 但是,将
<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>
参数添加到auto_refresh
值:
res
注2
如果不是采购订单的树状图,而是想看到 您刚刚创建的采购订单,请更改此
res = { 'view_type': 'form', 'view_mode': 'tree', 'res_model': 'purchase.order', 'type': 'ir.actions.act_window', 'target': 'current', 'auto_refresh': 1, } return res
变量 方式(在我写的上面的Python代码中):
res