Odoo 10:更改字段

时间:2017-10-06 13:00:02

标签: openerp odoo-9 odoo-10

这是使用Odoo 10和默认的bootstrap-datetimepicker。

我的视图中有一个字段,其中包含“事件开始”日期时间。我希望日期选择器以5分钟的间隔(minuteStepping: 5)显示,并显示时间选择器和日期选择器(sideBySide: true)。

我已经确认这可以通过手动编辑addons/web/static/src/js/widgets/date_picker.js来实现。

但是,我更愿意将我想要更改的两个选项作为参数添加到视图XML中<field ..>标记下的<form>定义中。源Widget在其options方法中接受init参数,它扩展为最终选项对象,但我无法将配置选项插入此对象。

我尝试将其作为<field ... options="{...}".. t-field-options='..'给出,但我猜测后者将无效,因为我在视图中不在qweb上下文中,并且第一个不是小部件不读。

有没有办法在不创建新小部件的情况下做到这一点? (并且希望没有子类化或扩展现有的小部件,而是将其保留为纯视图配置选项)?

1 个答案:

答案 0 :(得分:2)

You can see a great example in this module. https://github.com/OCA/web/tree/10.0/web_m2x_options

In the file. static/src/js/form.js.

The module has overridden the fields Many2one to add different options can be set in the XML declaration of field.

Example : <field name="partner_id" options="{'search_more':true}" />

In this example. The search more button is visible in all cases.

You can use the logic of this module as a base of your widget extension.

Installation:

In a First time, you must download the Github repository.

https://github.com/jo541/web

Select the branch 10.0. In the repository, there are a named module "web_widget_datepicker_options". This module gives you the possibility to specify any options as you want for a specific field.

After download and install the module on Odoo. You needing to reload the cache of your browser to be sure.

Modification:

Now you can modify your form view. For an example, I will use the view form sale.order.

In the form view sale.order, you have a field "date_order". If you would like to have the time step 5 by 5.

<field name="date_order" options="{'datepicker':{'minuteStepping': 5}}" attrs="{'invisible': [('state', 'in', ['sale', 'done', 'cancel'])]}"/>

All the options in the dict of the key datepicker will be adding to the option of the bootstrap datepicker.