奥多。按字段一对多搜索
Odoo. One to many search by field
我在 odoo 9 中为员工扩展模块。每个员工都有 children。这是我的模型:
class Employee(models.Model):
_name = 'hr.employee'
_inherit = 'hr.employee'
children_ids = fields.One2many('my_module', 'employee_id', string="Children")
class Child(models.Model):
_name = 'my_module'
name = fields.Char(required=True, string='Name')
birthday = fields.Date(required=True, string='Birthday')
employee_id = fields.Many2one('hr.employee', ondelete='cascade', string="Employee")
如何配置按生日搜索?例如,我想在搜索日期中设置生日(或日期间隔),系统必须显示所有 children with birthday from search.
的所有员工
这里是我的搜索视图(以 child 的名字工作):
<record id="view_urspectr_employee_filter" model="ir.ui.view">
<field name="name">Employees</field>
<field name="model">hr.employee</field>
<field name="inherit_id" ref="hr.view_employee_filter" />
<field name="arch" type="xml">
<search position="inside">
<field name="children_ids"/>
</search>
</field>
</record>
我在模块account(../addons/account/views/account_view.xml):
中发现了类似的情况
<record id="view_account_move_filter" model="ir.ui.view">
<field name="name">account.move.select</field>
<field name="model">account.move</field>
<field name="arch" type="xml">
<search string="Search Move">
<field name="name" filter_domain="['|', ('name','ilike',self), ('ref','ilike',self)]" string="Move"/>
<field name="date"/>
按日期搜索效果很好。但在这种情况下 date 字段使用没有关系 One2Many.
你能帮忙解决一下吗?我找不到通过 One2Many 搜索的示例。
提前谢谢你。
这里你尝试在'hr.employee'table中添加'birthday'的相关字段相对于'children_ids',但是问题仍然可能是它可能不会只搜索“2015”,因为 'birthday' 字段的数据类型是 'Date',而不仅仅是简单的字符串。不过你可以试一试。
此处解决方案:
<record id="view_urspectr_employee_filter" model="ir.ui.view">
<field name="name">Employees</field>
<field name="model">hr.employee</field>
<field name="inherit_id" ref="hr.view_employee_filter"/>
<field name="arch" type="xml">
<search position="inside">
<field name="children_ids" filter_domain="[('children_ids.birthday', '=', self)]" widget="date"/>
</search>
</field>
</record>
我在 odoo 9 中为员工扩展模块。每个员工都有 children。这是我的模型:
class Employee(models.Model):
_name = 'hr.employee'
_inherit = 'hr.employee'
children_ids = fields.One2many('my_module', 'employee_id', string="Children")
class Child(models.Model):
_name = 'my_module'
name = fields.Char(required=True, string='Name')
birthday = fields.Date(required=True, string='Birthday')
employee_id = fields.Many2one('hr.employee', ondelete='cascade', string="Employee")
如何配置按生日搜索?例如,我想在搜索日期中设置生日(或日期间隔),系统必须显示所有 children with birthday from search.
的所有员工这里是我的搜索视图(以 child 的名字工作):
<record id="view_urspectr_employee_filter" model="ir.ui.view">
<field name="name">Employees</field>
<field name="model">hr.employee</field>
<field name="inherit_id" ref="hr.view_employee_filter" />
<field name="arch" type="xml">
<search position="inside">
<field name="children_ids"/>
</search>
</field>
</record>
我在模块account(../addons/account/views/account_view.xml):
中发现了类似的情况<record id="view_account_move_filter" model="ir.ui.view">
<field name="name">account.move.select</field>
<field name="model">account.move</field>
<field name="arch" type="xml">
<search string="Search Move">
<field name="name" filter_domain="['|', ('name','ilike',self), ('ref','ilike',self)]" string="Move"/>
<field name="date"/>
按日期搜索效果很好。但在这种情况下 date 字段使用没有关系 One2Many.
你能帮忙解决一下吗?我找不到通过 One2Many 搜索的示例。 提前谢谢你。
这里你尝试在'hr.employee'table中添加'birthday'的相关字段相对于'children_ids',但是问题仍然可能是它可能不会只搜索“2015”,因为 'birthday' 字段的数据类型是 'Date',而不仅仅是简单的字符串。不过你可以试一试。
此处解决方案:
<record id="view_urspectr_employee_filter" model="ir.ui.view">
<field name="name">Employees</field>
<field name="model">hr.employee</field>
<field name="inherit_id" ref="hr.view_employee_filter"/>
<field name="arch" type="xml">
<search position="inside">
<field name="children_ids" filter_domain="[('children_ids.birthday', '=', self)]" widget="date"/>
</search>
</field>
</record>