Odoo 10 - 带动作的自定义按钮(POST JSON 客户数据帮助!!)
Odoo 10 - Custom Button with Action (POST JSON customer data help !!)
Odoo 10 - 带动作的自定义按钮(发布 JSON 客户数据帮助!!)
您好,我已经能够使用 xml
中的以下代码在 account.invoice 中创建一个按钮
<record id="invoice_form_shippinglabel" model="ir.ui.view">
<field name="name">account.invoice.form.shippinglabel</field>
<field name="model">account.invoice</field>
<field name="inherit_id" ref="account.invoice_form"/>
<field name="arch" type="xml">
<header>
<button name="label" string="Print Shipping Label" class="oe_highlight"/>
</header>
</field>
</record>
现在我想在用户按下按钮后添加一个功能
所以在我的 'models.py' 中,我尝试将此代码
def label(self):
data = {'ids':[12, 3, 4, 5, 6]}
req = urllib2.Request('https://requestb.in/1bz11jv1')
req.add_header('Content-Type', 'application/json')
response = urllib2.urlopen(req, json.dumps(data))
所以基本上,我想发送一些示例数据到 https://requestb.in/1bz11jv1
但是当我重新启动 odoo 时它不起作用它在 odoo.log
中给我这个错误
File "/odoo/odoo-server/addons/labelprint/models/models.py", line 14
def label(self):
IndentationError: unexpected indent
我不太清楚为什么会导致这个错误我已经用谷歌搜索了缩进,但它根本没有帮助
此外,我还有一个问题,关于我是否可以 post json 数据
我如何获取 customer.address、customer.phone、customer.name 等信息,因为我在发送 json 数据时需要这些信息
非常感谢
这是因为你的缩进。 Python 使用缩进来分隔逻辑。
这是正确缩进的示例。
# -*- coding: utf-8 -*-
from odoo import models, fields, api
class ModelName(models.Model):
_name = 'addon_name.model_name'
field1 = fields.Char()
field2 = fields.Char()
field3 = fields.Char()
@api.multi
def test(self):
print("HELLO")
return
我认为您的按钮 xml 定义也有一些问题。您可能想要指定一个 'type' 属性并为其分配一个值 'object'.
Odoo 10 - 带动作的自定义按钮(发布 JSON 客户数据帮助!!)
您好,我已经能够使用 xml
中的以下代码在 account.invoice 中创建一个按钮<record id="invoice_form_shippinglabel" model="ir.ui.view">
<field name="name">account.invoice.form.shippinglabel</field>
<field name="model">account.invoice</field>
<field name="inherit_id" ref="account.invoice_form"/>
<field name="arch" type="xml">
<header>
<button name="label" string="Print Shipping Label" class="oe_highlight"/>
</header>
</field>
</record>
现在我想在用户按下按钮后添加一个功能
所以在我的 'models.py' 中,我尝试将此代码
def label(self):
data = {'ids':[12, 3, 4, 5, 6]}
req = urllib2.Request('https://requestb.in/1bz11jv1')
req.add_header('Content-Type', 'application/json')
response = urllib2.urlopen(req, json.dumps(data))
所以基本上,我想发送一些示例数据到 https://requestb.in/1bz11jv1
但是当我重新启动 odoo 时它不起作用它在 odoo.log
中给我这个错误File "/odoo/odoo-server/addons/labelprint/models/models.py", line 14 def label(self): IndentationError: unexpected indent
我不太清楚为什么会导致这个错误我已经用谷歌搜索了缩进,但它根本没有帮助
此外,我还有一个问题,关于我是否可以 post json 数据
我如何获取 customer.address、customer.phone、customer.name 等信息,因为我在发送 json 数据时需要这些信息
非常感谢
这是因为你的缩进。 Python 使用缩进来分隔逻辑。
这是正确缩进的示例。
# -*- coding: utf-8 -*-
from odoo import models, fields, api
class ModelName(models.Model):
_name = 'addon_name.model_name'
field1 = fields.Char()
field2 = fields.Char()
field3 = fields.Char()
@api.multi
def test(self):
print("HELLO")
return
我认为您的按钮 xml 定义也有一些问题。您可能想要指定一个 'type' 属性并为其分配一个值 'object'.