我试过这个代码
raise odoo.osv.osv.except_osv('title', 'description')
Run Code Online (Sandbox Code Playgroud)
但是标题被忽略了。
我在我的视图中创建了一个按钮,它触发了模块内的一个方法。但是,单击该按钮后,临时编辑的字段将被保存,并且在单击“放弃”按钮时不会恢复。
这是我的观点的代码:
<form>
<sheet>
<group>
<field name="name" />
</group>
<button name="my_button" string="My Button" type="object" class="oe_edit_only" />
</sheet>
</form>
Run Code Online (Sandbox Code Playgroud)
单击my_button该字段后,该字段name将保存在数据库中,该按钮Discard不再起作用。
单击我的自定义按钮时,如何防止 Odoo 保存临时数据?
(我正在使用 Odoo10,但我想旧版本的 Odoo 也是如此)
这是我编写并从hr.holidays继承的程序 ,如果所选日期在当前日期之前,则应提供错误消息。代码-
from datetime import date
if self.date_from <= date.today():
print 'You cannot select the previous date'
Run Code Online (Sandbox Code Playgroud)
但它给出了错误 -
TypeError: can't compare datetime.date to bool
Run Code Online (Sandbox Code Playgroud)
谢谢
我将“location_id”字段添加到 res.user 以将用户连接到某个位置
类 ResUser(models.Model): _inherit='res.users'
current_location_id=fields.Many2one('physical.location',string="Current Loction")
allowed_location_ids=fields.Many2many('physical.location',string="Allowed Location")
Run Code Online (Sandbox Code Playgroud)
我只想过滤 current_location_id = user_current_location_id 的访问
<filter string="My visits" name="filter_my_visits"
domain="[('current_location_id','=',current_location_id)]"/>
Run Code Online (Sandbox Code Playgroud)
这给出了这个错误信息
Uncaught Error: Failed to evaluate search criterions:
{"code":400,"message":"Evaluation Error","data":{"type":"local_exception","debug":"Local evaluation failure\nNameError: name 'current_location_id' is not defined\n\n{\"domains\":[[],\"[('current_location_id','=',current_location_id)]\"],\"contexts\":[{\"lang\":\"en_US\",\"tz\":false,\"uid\":1,\"params\":{\"action\":354,\"min\":1,\"limit\":80,\"view_type\":\"list\",\"model\":\"visit.visit\",\"menu_id\":241,\"_push_me\":false}},{}],\"group_by_seq\":[]}"}}
Run Code Online (Sandbox Code Playgroud)
视图中可以直接调用的唯一字段是 uid lang ... 等 所以我试图覆盖读取方法来更新上下文,但它似乎没有在视图中更新,仍然给出未定义的“current_location_id”
@api.multi
def read(self, fields=None, load='_classic_read'):
ctx = self.env.context.copy()
ctx.update({ 'user_current_location_id':self.env.user.current_location_id.id})
return super(Visit,self.with_context(ctx)).read(fields=fields,load=load)
Run Code Online (Sandbox Code Playgroud)
访问树视图
<record id="visit_visit_tree_view" model="ir.ui.view">
<field name="name">visit.visit.tree</field>
<field name="model">visit.visit</field>
<field name="arch" type="xml">
<tree string="Visits">
<field name="name" />
<field name="date"/>
<field name="visit_type" />
<field name="patient_id"/>
<field name="hcp_id"/> …Run Code Online (Sandbox Code Playgroud) 我已经创建了一个自定义模块,在我的树视图中,我将始终只有1行数据.但在我的树视图中,它显示了额外的空行.如何删除那些不需要的空行?

我的观点代码:
<record model="ir.ui.view" id="ctimesheet.list">
<field name="name">ctimesheet list</field>
<field name="model">time.recorder</field>
<field name="arch" type="xml">
<tree string="TIME SHEET" create="false">
<field name="total_time"/>
<field name="month_time"/>
<field name="yesterday_time"/>
<field name="week_time"/>
<field name="notsubmitted_time"/>
<field name="user_id" invisible="1"/>
</tree>
</field>
</record>
Run Code Online (Sandbox Code Playgroud) 我stock.picking使用一个新方法扩展了模型,该方法do_new_transfer_xmlrpc启用了XMLRPC的基本new_transfer.
class Picking(models.Model):
_inherit = 'stock.picking'
@api.multi
def do_new_transfer_xmlrpc(self):
print 'DEBUG'
self.do_transfer()
return ['OK', '']
Run Code Online (Sandbox Code Playgroud)
我尝试使用以下方法调用该方法:
api.execute_kw(db, uid, pwd, 'stock.picking', 'do_new_transfer_xmlrpc', [[int(picking_id)], {}])
Run Code Online (Sandbox Code Playgroud)
但我得到:
Fault: <Fault 1: 'Traceback (most recent call last):\n File "/usr/lib/python2.7/dist-packages/odoo/service/wsgi_server.py", line 56, in xmlrpc_return\n result = odoo.http.dispatch_rpc(service, method, params)\n File "/usr/lib/python2.7/dist-packages/odoo/http.py", line 118, in dispatch_rpc\n result = dispatch(method, params)\n File "/usr/lib/python2.7/dist-packages/odoo/service/model.py", line 38, in dispatch\n res = fn(db, uid, *params)\n File "/usr/lib/python2.7/dist-packages/odoo/service/model.py", line 157, in execute_kw\n return execute(db, uid, obj, method, *args, …Run Code Online (Sandbox Code Playgroud) Odoo 中的 Product Master 需要两个不同的表是什么?product.product 和 product.template 有何不同?
我需要的
如果用户单击我的按钮,则根据当前记录的字段将他带到不同模型的不同视图。
我做了什么
我已经声明了一个类型对象按钮来调用 Python 方法。在里面,我检查了字段。如果它的值为A,我将他重定向到模型X,如果它的值为 B ,我将他重定向到模型Y。
编码
@api.multi
def my_button_method(self):
self.ensure_one()
if self.my_field == 'A':
action_id = self.env.ref(
'my_module.my_ir_actions_act_window_A')
return action_id.__dict__
elif self.my_field == 'B':
action_id = self.env.ref(
'my_module.my_ir_actions_act_window_B')
else:
action_id = False
if action_id:
return action_id.__dict__
Run Code Online (Sandbox Code Playgroud)
如果我在定义之后写这个action_id:
_logger.info(action_id.name)
_logger.info(action_id.type)
_logger.info(action_id.res_model)
_logger.info(action_id.view_type)
_logger.info(action_id.view_mode)
_logger.info(action_id.search_view_id)
_logger.info(action_id.help)
Run Code Online (Sandbox Code Playgroud)
我得到了正确的价值观。因此,在谷歌搜索之后,我看到它__dict__为您提供了一个字典,其键是对象的属性,其值是这些属性的值。
但是代码给出了一个错误,因为action_id.__dict__它没有返回一个包含动作及其值的预期属性的字典,而是以下内容:
{
'_prefetch': defaultdict(
<type 'set'>,
{
'ir.actions.act_window': set([449])
}
),
'env': <odoo.api.Environment object at 0x7f0aa7ed7cd0>,
'_ids': (449,) …Run Code Online (Sandbox Code Playgroud) 我需要创建一个两列索引。我已经声明:
field_A= fields.Float(string='A', index=True)
field_B= fields.Float(string='B', index=True)
Run Code Online (Sandbox Code Playgroud)
但这会创建两个独立的索引。我想获得一个复合索引。知道我怎么能做到这一点吗?