python-Odoo.按领域一对多搜索
作者:互联网
我在odoo 9中为员工扩展了模块.每个员工都有孩子.这是我的模型:
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")
如何在生日前配置搜索?例如,我要设置生日的搜索日期(或日期间隔),并且系统必须向我显示所有具有生日的孩子的员工.
这是我的搜索视图(按孩子的名字显示):
<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>
我在模块帐户(../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"/>
按日期搜索效果很好.但是在这种情况下,使用的日期字段没有关联One2Many.
您可以提供解决方案吗?我找不到One2Many进行搜索的示例.
先感谢您.
解决方法:
这里解决:
<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,openerp,python 来源: https://codeday.me/bug/20191119/2036192.html