有一个带有时间表模块(自制)的odoo系统。我制作了两组搜索视图过滤器:年和月:
<!--Timesheets-ALL Tab search view-->
<record id="view_tabel_search3" model="ir.ui.view">
<field name="name">tabel.tabel.search3</field>
<field name="model">tabel.tabel</field>
<field name="type">search</field>
<field name="arch" type="xml">
<search string="Checker">
<group expand="0" string="Years">
<filter
string="Last year"
name="filter5"
domain="[('time_end_t', '>=' ,(context_today()-relativedelta(years=1)).strftime('%Y-01-01')), ('time_end_t', '<' , (context_today()).strftime(
help = "Shows timesheets for last year"/>
<separator/>
<filter
string="Current year"
name="filter4"
domain="[('time_end_t', '>=' ,(context_today()).strftime('%Y-01-01')), ('time_end_t', '<' , (context_today()+relativedelta(years=1)).strftime(
help = "Shows timesheets for current year"/>
<separator/>
<filter
string="Next year"
name="filter6"
domain="[('time_end_t', '>=', (context_today()+relativedelta(years=1)).strftime('%Y-01-01')),('time_end_t','<=', (context_today()+relativedelt
help = "Shows timesheets for next year"/>
</group>
<group expand="0" string="Months">
<filter
string="January"
name="filter7"
domain="[('time_end_t', '>=' ,(context_today()).strftime('%Y-01-01')), ('time_end_t', '<' , (context_today()).strftime('%Y-02-01'))]"
help = "Shows timesheets for january"/>
<separator/>
<filter
string="February"
name="filter8"
domain="[('time_end_t', '>=' ,(context_today()).strftime('%Y-02-01')), ('time_end_t', '<' , (context_today()).strftime('%Y-03-01'))]"
help = "Shows timesheets for february"/>
<separator/>
...
<filter
string="November"
name="filter17"
domain="[('time_end_t', '>=' ,(context_today()).strftime('%Y-11-01')), ('time_end_t', '<' , (context_today()).strftime('%Y-12-01'))]"
help = "Shows timesheets for november"/>
<separator/>
<filter
string="December"
name="filter18"
domain="[('time_end_t', '>=' ,(context_today()).strftime('%Y-12-01')), ('time_end_t', '<' , (context_today()+relativedelta(years=1)).strftime(
help = "Shows timesheets for december"/>
</group>
<field name="time_start_t" select="True"/>
<field name="id_ank" select="True"/>
</search>
</field>
</record>
time_end_t 和 time_start_t 是我们的时间表开始和结束的日期。 如您所见, months 本身将显示当年的正确时间表。以及当前年度和任何月的组合。但去年和明年显然因为(context_today())而无法工作。
我认为使用 time_end_t 的年份而不是(context_today())的年份(这是当前最合乎逻辑的方式)只要)。但我有一个错误(在翻译中),如
Unable to process the search criteria
...
name 'time_end_t' is not defined
当我写这样的东西时,例如:
<field name="time_end_t" />
<filter
string="January"
name="filter7"
domain="[('time_end_t', '>=' , time_end_t )]"
help = "Shows timesheets for january (not actually)"/>
但它正好在上面定义.. 任何建议都将受到高度赞赏!
upd:工作代码的示例(对于Odedra):
<page string="Timesheet's data">
<table style="width:100%;">
<tr>
<field name="state" widget="statusbar" string="document's status"/>
</tr>
<tr><td>
<group>
<field name="time_start_t" string="Timesheet's start date" />
<field name="time_end_t" string="Timesheet's end date" />
</group></td><td>
<group>
<field name="id_division" string="Division" domain="[('enddate','>=',time_start_t),('startdate','<=',time_end_t) ]"/>
<field name="id_ank" string="Tableman" />
<field name="dayall"/>
</group></td></tr>
</table>
</page>
答案 0 :(得分:4)
一切都好。当我们在域上使用任何字段时,我们必须注册该字段。意味着我们需要在搜索视图的第一行定义该字段。
尝试使用此代码:
<!--Timesheets-ALL Tab search view-->
<record id="view_tabel_search3" model="ir.ui.view">
<field name="name">tabel.tabel.search3</field>
<field name="model">tabel.tabel</field>
<field name="type">search</field>
<field name="arch" type="xml">
<search string="Checker">
<field name="time_start_t" select="True"/>
<field name="id_ank" select="True"/>
<group expand="0" string="Years">
<filter
string="Last year"
name="filter5"
domain="[('time_end_t', '>=' ,(context_today()-relativedelta(years=1)).strftime('%Y-01-01')), ('time_end_t', '<' , (context_today()).strftime(
help = "Shows timesheets for last year"/>
<separator/>
<filter
string="Current year"
name="filter4"
domain="[('time_end_t', '>=' ,(context_today()).strftime('%Y-01-01')), ('time_end_t', '<' , (context_today()+relativedelta(years=1)).strftime(
help = "Shows timesheets for current year"/>
<separator/>
<filter
string="Next year"
name="filter6"
domain="[('time_end_t', '>=', (context_today()+relativedelta(years=1)).strftime('%Y-01-01')),('time_end_t','<=', (context_today()+relativedelt
help = "Shows timesheets for next year"/>
</group>
<group expand="0" string="Months">
<filter
string="January"
name="filter7"
domain="[('time_end_t', '>=' ,(context_today()).strftime('%Y-01-01')), ('time_end_t', '<' , (context_today()).strftime('%Y-02-01'))]"
help = "Shows timesheets for january"/>
<separator/>
<filter
string="February"
name="filter8"
domain="[('time_end_t', '>=' ,(context_today()).strftime('%Y-02-01')), ('time_end_t', '<' , (context_today()).strftime('%Y-03-01'))]"
help = "Shows timesheets for february"/>
<separator/>
...
<filter
string="November"
name="filter17"
domain="[('time_end_t', '>=' ,(context_today()).strftime('%Y-11-01')), ('time_end_t', '<' , (context_today()).strftime('%Y-12-01'))]"
help = "Shows timesheets for november"/>
<separator/>
<filter
string="December"
name="filter18"
domain="[('time_end_t', '>=' ,(context_today()).strftime('%Y-12-01')), ('time_end_t', '<' , (context_today()+relativedelta(years=1)).strftime(
help = "Shows timesheets for december"/>
</group>
</search>
</field>
</record>