搜索视图域错误 [英] Search view domain error

查看:60
本文介绍了搜索视图域错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有一个包含时间表模块(自制)的odoo系统.我已经做了2组搜索视图过滤器::

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', '&gt;=' ,(context_today()-relativedelta(years=1)).strftime('%Y-01-01')), ('time_end_t', '&lt;' , (context_today()).strftime(
                help = "Shows timesheets for last year"/>
                <separator/>
                <filter
                string="Current year"
                name="filter4"
                domain="[('time_end_t', '&gt;=' ,(context_today()).strftime('%Y-01-01')), ('time_end_t', '&lt;' , (context_today()+relativedelta(years=1)).strftime(
                help = "Shows timesheets for current year"/>
                <separator/>
                <filter
                string="Next year"
                name="filter6"
                domain="[('time_end_t', '&gt;=', (context_today()+relativedelta(years=1)).strftime('%Y-01-01')),('time_end_t','&lt;=', (context_today()+relativedelt
                help = "Shows timesheets for next year"/>
                </group>
                <group expand="0" string="Months">
                <filter
                string="January"
                name="filter7"
                domain="[('time_end_t', '&gt;=' ,(context_today()).strftime('%Y-01-01')), ('time_end_t', '&lt;' , (context_today()).strftime('%Y-02-01'))]"
                help = "Shows timesheets for january"/>
                <separator/>
                <filter
                string="February"
                name="filter8"
                domain="[('time_end_t', '&gt;=' ,(context_today()).strftime('%Y-02-01')), ('time_end_t', '&lt;' , (context_today()).strftime('%Y-03-01'))]"
                help = "Shows timesheets for february"/>
                <separator/>
                ...
                <filter
                string="November"
                name="filter17"
                domain="[('time_end_t', '&gt;=' ,(context_today()).strftime('%Y-11-01')), ('time_end_t', '&lt;' , (context_today()).strftime('%Y-12-01'))]"
                help = "Shows timesheets for november"/>
                <separator/>
                <filter
                string="December"
                name="filter18"
                domain="[('time_end_t', '&gt;=' ,(context_today()).strftime('%Y-12-01')), ('time_end_t', '&lt;' , (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 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.

使用 time_end_t 的年份而不是(context_today())的年份(仅当前)是最合乎逻辑的方法.但是我遇到了

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', '&gt;=' , time_end_t   )]"
  help = "Shows timesheets for january (not actually)"/>

但是它是在上面定义的. 任何建议将不胜感激!

But it was defined right above.. Any advice will be highly appreciated!

upd:工作代码示例(适用于Odedra):

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','&gt;=',time_start_t),('startdate','&lt;=',time_end_t)  ]"/>
        <field name="id_ank" string="Tableman" />
        <field name="dayall"/>
    </group></td></tr>
    </table>
</page>

推荐答案

一切正常.当我们在域上使用任何字段时,我们必须注册该字段.意味着我们需要在搜索视图的第一行定义该字段.

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.

尝试使用此代码:

<!--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', '&gt;=' ,(context_today()-relativedelta(years=1)).strftime('%Y-01-01')), ('time_end_t', '&lt;' , (context_today()).strftime(
            help = "Shows timesheets for last year"/>
            <separator/>
            <filter
            string="Current year"
            name="filter4"
            domain="[('time_end_t', '&gt;=' ,(context_today()).strftime('%Y-01-01')), ('time_end_t', '&lt;' , (context_today()+relativedelta(years=1)).strftime(
            help = "Shows timesheets for current year"/>
            <separator/>
            <filter
            string="Next year"
            name="filter6"
            domain="[('time_end_t', '&gt;=', (context_today()+relativedelta(years=1)).strftime('%Y-01-01')),('time_end_t','&lt;=', (context_today()+relativedelt
            help = "Shows timesheets for next year"/>
            </group>
            <group expand="0" string="Months">
            <filter
            string="January"
            name="filter7"
            domain="[('time_end_t', '&gt;=' ,(context_today()).strftime('%Y-01-01')), ('time_end_t', '&lt;' , (context_today()).strftime('%Y-02-01'))]"
            help = "Shows timesheets for january"/>
            <separator/>
            <filter
            string="February"
            name="filter8"
            domain="[('time_end_t', '&gt;=' ,(context_today()).strftime('%Y-02-01')), ('time_end_t', '&lt;' , (context_today()).strftime('%Y-03-01'))]"
            help = "Shows timesheets for february"/>
            <separator/>
            ...
            <filter
            string="November"
            name="filter17"
            domain="[('time_end_t', '&gt;=' ,(context_today()).strftime('%Y-11-01')), ('time_end_t', '&lt;' , (context_today()).strftime('%Y-12-01'))]"
            help = "Shows timesheets for november"/>
            <separator/>
            <filter
            string="December"
            name="filter18"
            domain="[('time_end_t', '&gt;=' ,(context_today()).strftime('%Y-12-01')), ('time_end_t', '&lt;' , (context_today()+relativedelta(years=1)).strftime(
            help = "Shows timesheets for december"/>
            </group>
        </search>
        </field>
</record>

这篇关于搜索视图域错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆