问题
There is an odoo system with a timesheet module (self-made) in it. I've made 2 groups of search view filters: years and months:
<!--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 and time_start_t are dates when our timesheets start and end. As you can see, months itself will show correct timesheets for current year. As well as combination of Current year and any month. But last year and next year obviously won't work because of (context_today()) thing.
The most logic way in my opinion to use time_end_t's year instead of (context_today())'s year (which is current only). But I've got an error (in translation) like
Unable to process the search criteria
...
name 'time_end_t' is not defined
when I wrote something like this for example:
<field name="time_end_t" />
<filter
string="January"
name="filter7"
domain="[('time_end_t', '>=' , time_end_t )]"
help = "Shows timesheets for january (not actually)"/>
But it was defined right above.. Any advice will be highly appreciated!
upd: an example of working code (for 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>
回答1:
Everything is OK. When we are using any field on domain than we must register that field. Means we need to define that field at the first line of search view.
Try with this code:
<!--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>
来源:https://stackoverflow.com/questions/33012722/search-view-domain-error