Python代码:
@api.model
def test_method(self):
a= 10
b = 20
c = a+b
return c
Run Code Online (Sandbox Code Playgroud)
jQuery的:
var Model = require('web.Model');
$(document).ready(function() {
var test_model = new Model("MyClass");
test_model.call("test_method").then(function(c) {
console.log("res ult:" + JSON.stringify(result));
});
});
Run Code Online (Sandbox Code Playgroud)
错误:
缺少取决于
上面的代码将在odoo 10中工作,但在odoo 11中不工作。我想知道如何从JS调用python函数。
有谁知道如何为Odoo对象编写模拟测试?
我有以下类和方法:
my_module:
from odoo import models
class MyModel(models.Model):
_name = 'my.model'
def action_copy(self):
IrTranslation = self.env['ir.translation']
for rec in self:
if rec.translate:
IrTranslation.force_translation(rec)
Run Code Online (Sandbox Code Playgroud)
my_module_2:
from odoo import models
class IrTranslation(models.Model):
_inherit = 'ir.translation'
def force_translation(self, rec):
# do stuff
Run Code Online (Sandbox Code Playgroud)
当我调用它时,我想测试是否IrTranslation.force_translation在action_copy方法中被调用了多少次。
但是此方法不是直接导入的,而是通过引用的env。
如果说force_translation可以像这样导入:
from my_module_2.IrTranslation import force_translation
def action_copy(self):
# do stuff.
force_translation()
Run Code Online (Sandbox Code Playgroud)
然后,我可以尝试执行以下操作:
from unittest import mock
from my_module import action_copy
def test_some_1(self):
with mock.patch('my_module.my_module_2.IrTranslation') as mocked_translation:
action_copy()
mocked_translation.force_translation.assert_called_once() …Run Code Online (Sandbox Code Playgroud) 我正在尝试在CRM模块的机会部分对客户进行分组。
我想在上分组客户/机会industry。
我已经使用过类似的代码res.partner,但我无法解决这一问题!
models.py
x_industry_id = fields.Many2one(string="Industry", comodel_name="res.partner")
Run Code Online (Sandbox Code Playgroud)
views.xml
<record id="view_crm_case_opportunities_filter_inherit" model="ir.ui.view">
<field name="name">crm.lead.search.opportunity</field>
<field name="model">crm.lead</field>
<field name="inherit_id" ref="crm.view_crm_case_opportunities_filter"/>
<field name="arch" type="xml">
<xpath expr="//search" position="inside">
<filter name="x_industry_id" string="Industry" context="{'group_by':'x_industry_id'}" domain="[('industry_id','!=', False)]"/>
</xpath>
</field>
</record>
Run Code Online (Sandbox Code Playgroud)
对于使用相同方法的过滤器和其他组,我也遇到相同的问题。
它们只是看起来不正常!
如何将群组和过滤器应用于不同的模型
我想向此表单添加其他字段,可以从Odoo中的数据库管理器访问
数据发送到此控制器:
@http.route('/web/database/duplicate', type='http', auth="none", methods=['POST'], csrf=False)
def duplicate(self, master_pwd, name, new_name):
try:
if not re.match(DBNAME_PATTERN, new_name):
raise Exception(_('Invalid database name. Only alphanumerical characters, underscore, hyphen and dot are allowed.'))
dispatch_rpc('db', 'duplicate_database', [master_pwd, name, new_name])
return http.local_redirect('/web/database/manager')
except Exception as e:
error = "Database duplication error: %s" % (str(e) or repr(e))
return self._render_template(error=error)
Run Code Online (Sandbox Code Playgroud)
但是表单是纯HTML,因此我无法继承和修改任何模板:
@http.route('/web/database/duplicate', type='http', auth="none", methods=['POST'], csrf=False)
def duplicate(self, master_pwd, name, new_name):
try:
if not re.match(DBNAME_PATTERN, new_name):
raise Exception(_('Invalid database name. Only alphanumerical characters, underscore, hyphen and dot …Run Code Online (Sandbox Code Playgroud) Is it possible to run and debug Odoo on Visual Studio Code? If yes please share me the configuration.
Visual Studio Code是Microsoft为Windows,Linux和macOS开发的源代码编辑器。它包括对调试,嵌入式Git控制,语法突出显示,智能代码完成,代码段和代码重构的支持。它是免费和开源的,尽管官方下载已获得专有许可。
我正在将模块从 odoo v10 升级到 odoo v11。发现将get_action替换为report_action。所以我使用了如下代码
self.env.ref('report_action_name').report_action(self, data=data, config=False)
但它给了我错误 AttributeError: 'ir.ui.view' object has no attribute 'report_action' 提前致谢
我有一个为特定模型创建新记录的控制器。
该模型包含一个fields.Binary.
控制器如下所示:
@http.route('/mymodel/create', type='json', method='POST', auth='user')
def create_record(self, **kwargs):
"""
@params:
'field1': string
'field2': int
'binaryField': binary
"""
values = {'my_model_field_1': kwargs.get('field1'),
'my_model_field_2': kwargs.get('field2'),
'my_model_binary_field': kwargs.get('binaryField')}
request.env['my_model'].create(values)
Run Code Online (Sandbox Code Playgroud)
我的问题是我应该如何从连接到服务器的远程应用程序发送文件?
我可能必须将其作为字符串发送,因为它是以 json 格式发送的。我必须如何修改我的控制器才能正确接收它?
我将不胜感激,提供一个将文件转换为可通过 Json 发送的字符串的代码示例。我还必须从任何语言转换它,因为我正在构建一个 API,二进制字段将识别的标准是什么?
是否可以根据另一个字段的值动态更改按钮的动作?示例代码:
<xpath expr="//button[@class='oe_stat_button o_res_partner_tip_opp']" position="attributes">
<attribute name="name">%(action1)d</attribute>
<attribute name="name">%(action2)d</attribute>
</xpath>
Run Code Online (Sandbox Code Playgroud)
该按钮的动作可以是action1或action2,具体取决于布尔值/ select /任何字段的值。如何做到这一点?
我正在使用 odoo 11,并且我已经安装了开放的 HRMS 核心,该核心安装了特定的主题。之后我安装了另一个名为加班(bt_hr_overtime_automatic)的模块来满足我的需求,但问题是在应用程序的菜单中新模块没有图标,我想添加一个(PS:该模块有一张图片在文件夹 /static/description/ 中命名为“icon.png”)。关于如何做到这一点有什么想法吗?
我如何检查演示数据是否从 python 代码加载到数据库中。我知道其他检查方法,但我需要通过代码检查。